Introduction to GraphQL

As explainded in the Quick Start guide, the Elium API uses GraphQL as language to query and modify data. It allows you, among other things, to query and receive exactly the information you need (not more, not less).

Node

A Relay concept that you will need to understand is the GraphQL Node. It provides a way to identify and query any GraphQL object that implements this interface. The interface only contains an id that we will refer to as GraphQL ID.

GraphQL ID

A GraphQL ID is unique among all the objects, it is auto-generated by the server. It is not to be mistaken with a slug (typically and Integer) that can be different depending the object type. The slug mainly appears in the browser's URL.

Example:

A user can have the slug 123 and a content also have a slug 123, because they are different concepts but each one will have a unique GraphQL id

Those concepts allow us to make query from node on different sort of objects, it is only required to cast the expected returned object. For example to query a content you could make the following query:

graphql
query {
node(id: "azQSdm") {
... on Story {
id
version {
title
}
user {
name
}
}
}
}

Note the ... on Story {} casting the expected return to be a Story. You can see alternatives in How to get a story

Was this page helpful?