Skip to content

Commit

Permalink
Allow filtering recipes by category
Browse files Browse the repository at this point in the history
Did this with a more simple category name query param that finds
the category.
  • Loading branch information
Marco Segreto committed Sep 14, 2018
1 parent f47a37d commit 07a11c3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion api/app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,16 @@
field :recipes, types[Types::RecipeType] do
description "Retrieve all recipes"

argument :categoryName, types.String, "Name of category"

resolve -> (obj, args, ctx) {
Recipe.all
category = Category.find_by(name: args[:categoryName])
if category
Recipe.where(category: category)
else
Recipe.all.limit(1)
end
# TODO: what if the category wasn't found?
}
end
end

0 comments on commit 07a11c3

Please sign in to comment.