Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Understanding GraphQL for Beginners–Part Two - Try it yourself #2
query {
findFood(term: "China") {
id
name
nutrition {
calories
}
}
}
{
"data": {
"findFood": [
{
"id": "2",
"name": "Beef Chow Mein",
"nutrition": {
"calories": "459"
}
}
]
}
}
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