Introduction

GraphQL was implemented by facebook in 2015 and has gained traction as the next step in API's to allow clients to get only the data they need.

Tools

Pluralsight gives a good course on building a GraphQL server with Spring Boot.

GraphiQL is a great GUI built for editing and testing GraphQL queries and mutations.

Queries

An example of getting a user through curl/browser/ajax:

curl http://localhost:8080/graphql?query={user(contactId: 393839) {username}}

Multiline easier to read queries can be done better through a GUI tool like GraphiQL:

{
  user(contactId: 390239) {
    username
    person {
      displayName
      email
      address {
        country
      }
    }
  }
}

And here is the response to that query:

{
  "user": {
    "jonny",
    "person": {
      "displayName": "Jonn-E",
      "email": "jonn.e@coyote.ca",
      "address": {
        "country": "Canada"
      }
    }
  }
}

Mutations

Mutations change the information stored in API and here is an example for updating some user information.

mutation {
  updateContactName(
    contactId: 390239,
    name: {
      firstName: "Jon"
      middleName: "E"
      lastName: "Coyote"
    }
  ) {
    displayName
  }
}

Other useful links to gather information from