Essentially, the Graphql-java-servlet software module implements a Java Servlet that publishes the GRAPHQL service as a Web service accessible via HTTP. Currently, the Graphql-java-servlet software module supports only the GRAPHQL query and mutation operation types and does not support subscription operation types.
The latest version of the Graphql-java-servlet software module is the 2017.12 release of 4.7.0.
1. Graphql-java-servlet relies on the following modules
javax.servlet:javax.servlet-api:3.0.1 com.graphql-java:graphql-java:6.0 com.fasterxml.jackson.core:jackson-* : 2.8.4
2. Use Graphql-java-servlet in the MAVEN project as long as it is referenced in Pom.xml
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId> graphql-java-servlet</artifactid>
<version>4.7.0</version>
</dependency>
3. The Graphql-java-servlet software module is only a servlet, which provides only a single Web request path
Although it is only a servlet, it supports HTTP GET/POST requests at the same time, and depending on the request parameters, there are several ways to request them. 1 internal structure query GET request
http://localhost:8080/graphql/Schema.json
2) graphql query GET request
Http://localhost:8080/graphql/?query={...} 3) graphql query POST request
http://localhost:8080/graphql/
{' query ': ' {Hello} '}
4) graphql query (multipart/form-data) Post request
http://localhost:8080/graphql/
{' graphql ': {' query ': ' {Hello} '}}
5) graphql query (multipart/form-data) Post request
http://localhost:8080/graphql/
{' query ': {' {hello} '}}
Note: For each request (possibly query or mutation), you can take the parameter "OperationName", "variables", where "OperationName" is the object of action, and "variables" is the set of properties of the action object.
The HTTP content-type for the default request is Application/json;charset=utf-8.
4. Using Graphql-java-servlet modules in spring Web applications
1 through the Graphql-spring-boot module, the indirect use of the Graphql-java-servlet module, please refer to Graphql-spring-boot, combined with GRAPHQL Spring Boot starters Class Library Overview.
2) by defining the spring bean as follows
@Bean
Servletregistrationbean Graphqlservletregistrationbean (graphqlschema schema, Executionstrategy Executionstrategy, list<graphqloperationlistener> operationlisteners) {return
new Servletregistrationbean (New Simplegraphqlservlet (schema, Executionstrategy, operationlisteners), "/graphql");
The default Web request path is/GRAPHQL.
Reference Links:
Https://github.com/graphql-java/graphql-java-servlet