This is simple example of GraphQL API implemented in Java with Spring Boot, and relaying on it's magic :)
There is example of implementation of Query and Subscription.
For GraphQL dependency added
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
<version>8.0</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>5.0.0</version>
</dependency>
To connect GraphQL and Spring Boot added this dependency
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>5.0.2</version>
</dependency>
In order to get GraqhiQL, UI for testing local version of GraphQL API added this dependency
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<version>5.0.2</version>
</dependency>
For GraphiQL hit http://localhost:8080/graphiql, when you start application
Query implementation is almost exactly the same like all other my examples of Query. Only difference is annotation @Component at top. For full code just open Query.java
Query example in GraphiQL
query {
allData {
message
}
}
Mutation implementation is almost exactly the same like all other my examples of Mutation. Only difference is annotation @Component at top. For full code just open Mutation.java
Mutation example in GraphiQL
mutation {
add(message:"Hello") {
message
}
}
after mutation you can run query again and check if all worked as intended.
Subscription implementation is done using RXJava and by implementing GraphQLSubscriptionResolver
For full code example check Subscription.java
Subscription can be tested from GraphiQL.
Subscription example in GraphiQL
subscription {
data {
message
}
}