Examples ======== .. _simplequery: Simple query ############ A simple query that returns a list of dishes with names and descriptions using :ref:`dishes ` schema. Query: .. code-block:: query dishes { dishes { name description } } Response: .. code-block:: json { "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!" } ] } } .. _querywithvariables: 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: .. code-block:: query get_ingredient($id: ID!) { ingredients(id:$id) { id name } } Variables: .. code-block:: json { "id": 17 } Response: .. code-block:: json { "data": { "ingredients": [ { "id": "17", "name": "avocado" } ] } } .. _fragments: Fragments ######### Query: .. code-block:: query q1 { ingredients (id:1) {...withPrepTags} } fragment withPrepTags on Ingredient { name tags (category: "prep"){ name } } Response: .. code-block:: { "data": { "ingredients": [ { "name": "acorn squash", "tags": [ { "name": "peel_cut" } ] } ] } } .. _multiplequeries: Multiple queries ################ GraphQL accepts multiple queries in one call. Query: .. code-block:: query q1 { ing1: ingredients (id:1) {...withPrepTags} ing2: ingredients (id:2) {...withPrepTags} } fragment withPrepTags on Ingredient { name tags (category: "prep"){ name } } Response: .. code-block:: json { "data": { "ing1": [ { "name": "acorn squash", "tags": [ { "name": "peel_cut" } ] } ], "ing2": [ { "name": "agave nectar", "tags": [] } ] } } Mutation ######## Query: .. code-block:: mutation save_tag { saveTag(ingredients: {ids: [1,2,3], action: ADD}, name: "my tag", category: "my category"){ tag { id name category } } } Response: .. code-block:: json { "data": { "saveTag": { "tag": { "id": "514", "name": "my tag", "category": "my category" } } } }