Explanation

GraphQL basics

How GraphQL works and why the Loco API uses it.

GraphQL lets you ask for exactly the data you need, in one request, from one endpoint.

Queries read, mutations write

  • Queries fetch data. See all queries.
  • Mutations change data. See all mutations.

You choose the shape

The response mirrors your query. If you only select id, you only get id:

graphql
query { me { id } }

Types

Every field has a type. A trailing ! means the value is never null, and [T] means a list of T. Click any type in the reference to see its fields.

Variables

Pass dynamic values as variables rather than string-building queries:

graphql
query Restaurant($id: ID!) {
  restaurant(id: $id) { id }
}
json
{ "id": "…" }