GRAPHQL's Graphql-java-servlet module detailed

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.