Getting Started
GraphQL interface exposed to endpoint http://localhost:8080/graphql based on tutorial from www.graphql-java.com
ToDo
Activate /graphql/schema.json
- queries via endpoints /graphql and /graphiql work as desired
- http://localhost:8080/graphql/schema.json leads to 404
Versions and Dependencies
Spring Boot 2.7.3, using spring-boot-starter-graphql as single dependency for GraphQL.
History and Migration
Before Spring Boot 2.7.0 the two dependencies:
- graphql-spring-boot-starter (5.0.2), together with
- graphql-java-tools (5.2.4))
... have been used along with implementation of the two interfaces GraphQLQueryResolver and GraphQLMutationResolver. Both are not required/supported since Spring Boot 2.7.0 and replaced with Annotations.
Also see blog.devgenius.io where migration to 2.7.0 from earlier versions is described.
Example Query via GraphiQL
Navigate to http://localhost:8080/graphiql and place following query:
{
getAllBooks {
id
name
}
}
{
bookById(id: "book-1"){
id
name
pageCount
author {
firstName
lastName
}
}
}
Example Queries via GraphQL (standard /graphql endpoint)
Navigate to http://localhost:8080/graphql and send a POST Request with header:
- key = Content-Type
- value = application/json
and following body:
{
"query":"{ getAllBooks { id } }"
}
Reference Documentation
For further reference, please consider the following sections:
- Official Apache Maven documentation
- Spring Boot Maven Plugin Reference Guide
- Create an OCI image
- Spring Web
Guides
The following guides illustrate how to use some features concretely: