-
-
Save ShopifyEng/1f92cee91f2932a0ef665594418764d3 to your computer and use it in GitHub Desktop.
Understanding GraphQL for Beginners–Part Two - Try it yourself #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query { | |
findFood(term: "China") { | |
id | |
name | |
nutrition { | |
calories | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"data": { | |
"findFood": [ | |
{ | |
"id": "2", | |
"name": "Beef Chow Mein", | |
"nutrition": { | |
"calories": "459" | |
} | |
} | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
field :find_food, [Types::FoodType], null: false do | |
description 'Get all food items based on place of origin.' | |
argument :term, String, required: true | |
end | |
def find_food(term:) | |
Food.where('place_of_origin = ?', term) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment