Build a Single-Post GraphQL Query With Variables
Admin ·
Use the Blog API sample to build a small operation for one article card. The card needs the post ID and the author's display name.
Choose post and author fields
Keep Schema on Blog API and Operation type on query. Set Operation name to ReadPost. Select post, then enter "post-7" in post id argument JSON, including the quotes.
Set Alias for post to featured. Select id and author inside the post fields, then select displayName inside author. The builder checks the resulting operation against the sample schema.
query ReadPost($post_id: ID!) {
featured: post(id: $post_id) {
id
author {
displayName
}
}
}Save the operation and its variables
Select Download operation.graphql and Download variables.json. The operation declares $post_id as ID! and returns the post under featured. The variables file supplies the value post-7 for post_id.
The alias changes the response key. The field in the selected schema is still post.
Use a local schema for a different API
Select Local schema SDL and paste or open a complete saved schema. Select Load local schema. The operation type choices reflect the roots present in that file.
When you select a composite field without a child, the preview uses __typename. Select child fields where your application needs specific values.
GraphQL schema and root operation typesGraphQL language and field selections
Common questions
How do I supply a GraphQL input object?
Enter one JSON object with the schema's input properties. The tool checks required fields and creates a matching variable.
Can I build a subscription?
Choose subscription under Operation type for a schema that defines that root. Select one root field and its arguments or child fields.