Examples¶
Simple query¶
A simple query that returns a list of dishes with names and descriptions using dishes schema.
Query:
query dishes {
dishes {
name
description
}
}
Response:
{
"data": {
"dishes": [
{
"name": "5-Minute Oatmeal",
"description": "Oatmeal is the world's fastest breakfast. Pour boiling water on top, and wait 5 minutes - voilá porridge!"
},
{
"name": "Alberte Stengaard's Pulled Portobello",
"description": "Deliciously saucy pulled portobello mushrooms by Alberte Stengaard."
},
{
"name": "Amit Vaidya Comfort Khichdi",
"description": "The classic Indian comfort food, nutritionally balanced with a twist."
},
{
"name": "Asian Marinade",
"description": "Create a delicious marinade to give an Asian twist to your vegetables or tofu."
},
{
"name": "Avocado Banana Kiwi Smoothie",
"description": "Create a delicious green smoothie using avocado, kiwi and bananas!"
},
{
"name": "Baba Ganoush",
"description": "Baba Ganoush is a Middle Eastern spread based on roasted eggplant and tahini with various seasoning. It is fantastic for appetizers and dinners!"
}
]
}
}
Query with GraphQL variables¶
To specify your request you can add relevant variables accepted by schema. To do so, add arguments to query definition and include values in GraphQL variables.
Query:
query get_ingredient($id: ID!) {
ingredients(id:$id) {
id
name
}
}
Variables:
{
"id": 17
}
Response:
{
"data": {
"ingredients": [
{
"id": "17",
"name": "avocado"
}
]
}
}
Fragments¶
Query:
query q1 {
ingredients (id:1) {...withPrepTags}
}
fragment withPrepTags on Ingredient {
name
tags (category: "prep"){
name
}
}
Response:
{
"data": {
"ingredients": [
{
"name": "acorn squash",
"tags": [
{
"name": "peel_cut"
}
]
}
]
}
}
Multiple queries¶
GraphQL accepts multiple queries in one call.
Query:
query q1 {
ing1: ingredients (id:1) {...withPrepTags}
ing2: ingredients (id:2) {...withPrepTags}
}
fragment withPrepTags on Ingredient {
name
tags (category: "prep"){
name
}
}
Response:
{
"data": {
"ing1": [
{
"name": "acorn squash",
"tags": [
{
"name": "peel_cut"
}
]
}
],
"ing2": [
{
"name": "agave nectar",
"tags": []
}
]
}
}
Mutation¶
Query:
mutation save_tag {
saveTag(ingredients: {ids: [1,2,3], action: ADD}, name: "my tag", category: "my category"){
tag {
id
name
category
}
}
}
Response:
{
"data": {
"saveTag": {
"tag": {
"id": "514",
"name": "my tag",
"category": "my category"
}
}
}
}