Coder Social home page Coder Social logo

tutorials's Introduction

GraphQL Java

Discuss and ask questions in our Discussions: https://github.com/graphql-java/graphql-java/discussions

This is a GraphQL Java implementation.

Latest build in Maven central: https://repo1.maven.org/maven2/com/graphql-java/graphql-java/

Build Latest Release Latest Snapshot MIT licensed

Documentation

The GraphQL Java book, from the maintainers: GraphQL with Java and Spring

See our tutorial for beginners: Getting started with GraphQL Java and Spring Boot

For further details, please see the documentation: https://www.graphql-java.com/documentation/getting-started

If you're looking to learn more, we (the maintainers) have written a book! GraphQL with Java and Spring includes everything you need to know to build a production ready GraphQL service. The book is available on Leanpub and Amazon.

Please take a look at our list of releases if you want to learn more about new releases and the changelog.

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By contributing to this project (commenting or opening PR/Issues etc) you are agreeing to follow this conduct, so please take the time to read it.

License

Copyright (c) 2015, Andreas Marek and Contributors

Supported by

YourKit

YourKit supports this project by providing the YourKit Java Profiler.

tutorials's People

Contributors

andimarek avatar dondonz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tutorials's Issues

Thanks..

Thanks for sharing the sample code here.. If you could correct the below method by adding the prefix TypeRuntimeWiring, it will help starters like me.

private RuntimeWiring buildWiring() {
return RuntimeWiring.newRuntimeWiring()
.type(TypeRuntimeWiring.newTypeWiring("Query")
.dataFetcher("bookById", graphQLDataFetchers.getBookByIdDataFetcher()))
.type(TypeRuntimeWiring.newTypeWiring("Book")
.dataFetcher("author", graphQLDataFetchers.getAuthorDataFetcher()))
.build();
}

Cannot integreate with graphql-java verion 15.0

There is an issue in GraphQLInbocationDaata class, in Graphql version 15.0, the Assert.assertNotNull method was been changed.
the second parameter type was changed to Supplier msg, not String any more.
fixed code:
public GraphQLInvocationData(String query, String operationName, Map<String, Object> variables) {
this.query = Assert.assertNotNull(query, () -> "query must be provided");
this.operationName = operationName;
this.variables = variables != null ? variables : Collections.emptyMap();
}

请教些问题

  1. 事实上在实际项目中,GraphQL只是一个中间层,SQL还是要后端去写的,但是要写得很通用,才能支持前端各种查询吗?
  2. ORM层都要写到对象里去查询数据吗?

DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'query' is not present]

I have just downloaded the sample from https://www.graphql-java.com/tutorials/getting-started-with-spring-boot/#graphql-in-3-minutes, gradle represh and I got

2019-08-13 14:24:04.278 INFO 14648 --- [ main] c.g.t.b.BookDetailsApplication : Starting BookDetailsApplication on DESKTOP-AKCNE7F with PID 14648 (C:_d\samples\graphql\tutorials\book-details\bin\main started by resource in C:_d\samples\graphql\tutorials\book-details)
2019-08-13 14:24:04.284 INFO 14648 --- [ main] c.g.t.b.BookDetailsApplication : No active profile set, falling back to default profiles: default
2019-08-13 14:24:06.818 INFO 14648 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-08-13 14:24:06.864 INFO 14648 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-13 14:24:06.864 INFO 14648 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.14]
2019-08-13 14:24:06.882 INFO 14648 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk-11.0.2\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jdk-11.0.2/bin/server;C:/Program Files/Java/jdk-11.0.2/bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Java\jdk-11.0.2\bin;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;C:_d\tools\apache-maven-3.6.0\bin;C:_d\WSs\kafka\zookeeper-3.4.14\bin;C:\Users\resource\AppData\Local\Programs\Python\Python37-32\Scripts;C:\Users\resource\AppData\Local\Programs\Python\Python37-32;C:\Users\resource\AppData\Local\Microsoft\WindowsApps;C:\minishift;C:_d\tools\nc111nt_safe;C:_d\tools\apache-cassandra-3.11.4-bin\apache-cassandra-3.11.4\bin;C:\Program Files\nodejs;C:\Users\resource\AppData\Local\Microsoft\WindowsApps;C:\Users\resource\AppData\Local\Programs\Microsoft VS Code\bin;C:_d\tools\apache-cassandra-3.11.4-bin\apache-cassandra-3.11.4\bin;C:\Python27;C:\Users\resource\AppData\Roaming\npm;C:\Users\resource\AppData\Local\atom\bin;C:\Program Files\heroku\bin;C:_d\tools\eclipse;;.]
2019-08-13 14:24:07.053 INFO 14648 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-13 14:24:07.054 INFO 14648 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2653 ms
2019-08-13 14:24:07.718 INFO 14648 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-08-13 14:24:07.996 INFO 14648 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-08-13 14:24:08.001 INFO 14648 --- [ main] c.g.t.b.BookDetailsApplication : Started BookDetailsApplication in 4.335 seconds (JVM running for 5.063)
2019-08-13 14:24:19.724 INFO 14648 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-08-13 14:24:19.725 INFO 14648 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-08-13 14:24:19.736 INFO 14648 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 10 ms
2019-08-13 14:24:19.772 WARN 14648 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'query' is not present]

In case it matter I have Java 11.

java -version

java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)

this does not work 404 error

just cloning this and running it results in
{
"timestamp": "2019-08-01T17:35:11.276+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/graphql"
}

How to initialize a GraphQL Java project without using Spring Boot?

All the GraphQL samples only use Spring Boot. I want to know how to use GraphQL without using Spring.I want to make a new GraphQL Java project but I do not want to use Spring Boot for it. I want to make the exact equivalent of this sample project but only using Jersey 3 and Jakarta 5. I have added my Gradle dependenices like this:

dependencies {
    implementation group: 'org.glassfish.jersey.containers', name: 'jersey-container-servlet', version: '3.0.3'
    implementation group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '3.0.3'
    implementation group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '3.0.3'
	implementation group: 'jakarta.servlet', name: 'jakarta.servlet-api', version: '5.0.0'
    implementation group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api', version: '3.0.1'
    implementation group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '3.0.2'
    
    implementation 'com.graphql-java:graphql-java:17.3'
    implementation 'com.graphql-java:graphql-java-extended-scalars:17.0'
    implementation 'com.graphql-java:graphql-java-extended-validation:17.0'
    implementation 'com.google.guava:guava:31.0.1-jre'
    
  	implementation 'com.google.code.gson:gson:2.8.8'
}

I would like to know how to rewrite the BookDetailsApplication, GraphQLDataFetchers and GraphQLProvider classes using Jersey 3.

Question: DataFetcher and RuntimeWiring vs GraphQLQueryResolver

I just started with graphql and have a question about this tutorial.

I don't really see the purpose of the GraphQLProvider class. Especially the method buildWiring(). As far as I can see the graphql-spring-boot-starter is doing the initialization and wiring automagically.

The following code is working fine for me:

@Component
@RequiredArgsConstructor
public class Query implements GraphQLQueryResolver {

	private final AuthorRepository authorRepo;
	private final BookRepository bookRepo;

    public Author getAuthor(Long id) {
    	return authorRepo.findById(id).orElse(null);
    }

    public Book getBook(Long id) {
    	return bookRepo.findById(id).orElse(null);
    }
}

Is there any benift of defining the DataFetchers manually? Or is this tutorial just outdated?

Unexpected token < in JSON at position 0

Just have started server, execute with GraphQL Playground as suggeted and it does not works.
Error:

Unexpected token < in JSON at position 0

image

Any help?

Best,
Eduardo

http://localhost:8080/graphiql throws org.springframework.util.InvalidMimeTypeException

Hi

Using the com.graphqljava.tutorial.bookDetails project I get the application to start, but when I use the graphiql UI to query for a book (based on the query detailed in the tutorial), The UI response window has this:

{ "timestamp": "2022-08-04T09:33:37.709+00:00", "status": 500, "error": "Internal Server Error", "path": "/graphql" }

Checking the application logs I am seeing this error:

org.springframework.util.InvalidMimeTypeException: Invalid mime type "application/json, application/json": Invalid token character ',' in token "json, application/json"

So the request header Content-Type is being set to "application/json, application/json"

Workarounds:

  1. Use Postman's Graphql to POST your query directly to http://localhost:8080/graphql
  2. As I'm using Chrome, use the ModHeader extension to set the Content-Type request header to "application/json"

Hope this helps someone

the author key is wrong

in schema.graphqls this file,defined property "author",but in GraphQLDataFetchers.java this file,defined property "authorId"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.