A walk in GraphQL

Spring boot setup

The Spring Boot GraphQL Starter combined with the GraphQL Java Tools library offer a fantastic way to get a GraphQL server running in a very short time, we need only write the code necessary for our resolvers and services.

Requirements

AdoptOpenJDK 8 (LTS) Installation

Installers are currently available for Windows®, Linux®, and macOS® JDK and JRE packages. Installation steps are covered in the following sections:

Project Dependencies

Spring Boot will automatically pick these up and set up the appropriate handlers to work automatically. By default, this will expose the GraphQL Service on the /graphql endpoint of our application and will accept POST requests containing the GraphQL Payload. This endpoint can be customised in our application.properties file if necessary.

Keep in mind

Run Application

Using Maven Wrapper

The Maven Wrapper is an excellent choice for projects that need a specific version of Maven (or for users that don’t want to install Maven at all).

  1. Open a terminal
  2. go to the java exercise directory
  3. run ./mvnw spring-boot:run(linux) or mvnw.cmd spring-boot:run(windows) to start the GraphQL server.

Using the IDE (IntelliJ IDEA)

  1. Open IntelliJ IDEA
  2. Select “Open or Import” option
  3. go to the exercise directory and choose the “java” folder
  4. run DemoGraphQlApplication

Testing GraphQL queries

To display a GUI for editing and testing GraphQL queries and mutations against the server you can open your browser and type http://localhost:8080/playground

Inspect the Database

H2 database has an embedded GUI console for browsing the contents of a database and running SQL queries. After starting the application, you can navigate to: http://localhost:8080/h2-console/login.jsp and enter the following information:

Learning Resources