lib/wcc/contentful/graphql/builder.rb in wcc-contentful-0.1.0 vs lib/wcc/contentful/graphql/builder.rb in wcc-contentful-0.2.0
- old
+ new
@@ -44,11 +44,11 @@
argument :id, types.ID
description "Find a #{schema_type.name} by ID"
resolve ->(_obj, args, _ctx) {
if args['id'].nil?
- store.find_by(content_type: content_type).first
+ store.find_by(content_type: content_type)
else
store.find(args['id'])
end
}
end
@@ -56,11 +56,16 @@
field "all#{schema_type.name}".to_sym do
type schema_type.to_list_type
argument :filter, Types::FilterType
resolve ->(_obj, args, ctx) {
- relation = store.find_by(content_type: content_type)
- relation = relation.apply(args[:filter], ctx) if args[:filter]
+ relation = store.find_all(content_type: content_type)
+ # TODO: improve this POC
+ if args[:filter]
+ filter = {}
+ filter[args[:filter]['field']] = { eq: args[:filter][:eq] }
+ relation = relation.apply(filter, ctx)
+ end
relation.result
}
end
end
end