/SimpleGraphQL4Books

Udacity Exercise (Java Web Developer)

Primary LanguageJava

Getting Started

GraphQL interface exposed to endpoint http://localhost:8080/graphql based on tutorial from www.graphql-java.com

ToDo

Activate /graphql/schema.json

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:

Guides

The following guides illustrate how to use some features concretely: