Closed hughevans closed 6 years ago
Hi,
You can nest arguments by defining an InputObjectType
:
class PostSearch
include SearchObject.module(:graphql)
NestedInput = GraphQL::InputObjectType.define do
name 'PostSearchNestedInput'
argument :type, types.String
argument :value, types.String
end
option :filters, type: NestedInput, with: :apply_filters
end
If you gave me concrete example, I can help more.
Thanks @RStankov. Then you’d have to apply all the filters “manually” in one large method though wouldn’t you. This would be nicer I think:
class PostSearch
include SearchObject.module(:graphql)
option :filter do
name 'PostSearchFilters'
option(:name, type: types.String) { |scope, value| scope.where name: value }
option(:published, type: types.Boolean) { |scope, value| value ? scope.published : scope.unpublished }
end
end
Yes you have to apply the filter manually.
I really like your idea of nested filters. It would be a bit tricky to implement. But I try to see how, I can do it.
đź‘‹
Is there an easy way to nest the options (arguments) inside another input?
For example, I want the nest the options under
filter:
:I can do this by defining an
GraphQL::InputObjectType
for the option type, but that means I just end up with a single resolver function where I need to tediously apply the scope changes (negating much of the benefits of SearchObject).Cheers!