Version 1.0 is released.
We have a spectrum chat for general questions.
This project integrates GraphQL Java into Spring/Spring Boot, by enabling query execution via HTTP.
While the GraphQL Specification itself doesn't specify any transport protocol there is a quasi standard how to do it described here and this project follows this quasi standard.
Goals / Design:
- Just HTTP JSON: the current focus is on HTTP execution via JSON.
- Minimal Dependencies: the only dependencies are GraphQL Java and Spring projects (including Jackson for JSON handling).
- No additional abstraction layer on top of GraphQL Java: GraphQL Java is meant to be used directly.
As outlined in https://graphql.org/learn/serving-over-http this project supports:
- GET request with
query
,operationName
andvariables
parameters. The variable parameters are json encoded - POST request with body
application/json
and keysquery
(string),operationName
(string) andvariables
(map).
Both produce application/json
.
We support both spring web types: the fully non-blocking webflux
and the traditional servlet based webmvc
.
Please see here in the spring documentation itself about the differences.
There are four different artifacts: (all with group id com.graphql-java
)
graphql-java-spring-webflux
graphql-java-spring-boot-starter-webflux
graphql-java-spring-webmvc
graphql-java-spring-boot-starter-webmvc
The Spring Boot Starter artifact provides a HTTP endpoint on ${graphql.url}
with the default value "/graphql"
just by being on the classpath.
The only requirement is to have a Bean of type graphql.GraphQL
available.
Add the following dependency to your build.gradle
(make sure mavenCentral()
is among your repos)
for webflux:
dependencies {
implementation "com.graphql-java:graphql-java-spring-boot-starter-webflux:1.0"
}
for webmvc:
dependencies {
implementation "com.graphql-java:graphql-java-spring-boot-starter-webmvc:1.0"
}
or to your pom.xml
for webflux
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-spring-boot-starter-webflux</artifactId>
<version>1.0</version>
</dependency>
for webmvc:
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-spring-boot-starter-webmvc</artifactId>
<version>1.0</version>
</dependency>
The following properties are currently available:
Property | Description | Default Value |
---|---|---|
graphql.url | the endpoint url | graphql |
The following Beans can be overridden by providing a different implementation.
Interface | Description |
---|---|
GraphQLInvocation | Executes one request. The default impl just calls the provided GraphQL bean. |
ExecutionResultHandler | Takes a ExecutionResult and sends the result back to the client. The default impl returns ExecutionResult.toSpecification() as json. |