Get a story
Read a story by its slug with the story query, or by its GraphQL ID with the node query.
There are two ways to read a story. The first uses its slug, the number in its address. The second uses its GraphQL ID, which is what mutations and most other objects give you. GraphQL IDs and nodes explains the difference.
By slug
Use the story query with the slug. This example reads the story with the slug 123. It returns the title of the latest version and the name of the owner:
query {
story(slug: 123) {
id
slug
version {
title
}
user {
name
}
}
}
The response:
{
"data": {
"story": {
"id": "U3Rvcnk6MTIz",
"slug": 123,
"version": {
"title": "Hello world!"
},
"user": {
"name": "John Doe"
}
}
}
}
By ID
Use the node query with the ID. Because node can return any type, wrap the fields in ... on Story:
query {
node(id: "U3Rvcnk6MTIz") {
... on Story {
id
version {
title
}
user {
name
}
}
}
}
The only difference in the response is the name of the key, node instead of story:
{
"data": {
"node": {
"id": "U3Rvcnk6MTIz",
"version": {
"title": "Hello world!"
},
"user": {
"name": "John Doe"
}
}
}
}
To get the same shape as the first query, give the field an alias:
query {
story: node(id: "U3Rvcnk6MTIz") {
... on Story {
id
}
}
}
Choose the version
version returns the latest published version, in the preferred language of the user whose token you use. Pass lang to read another language, or uuid to read one specific version:
query {
story(slug: 123) {
version(lang: "fr") {
title
published
publishedAt
}
}
}