0

What's the best way to share some arguments between different query types. I want to share some common arguments like created_at, updated_at

field :products, ProductType.connection_type, null: false do
  argument :name, [String], required: false
  # <--shared arguments args1-->
  # <--shared arguments args2-->
end
field :brands, BrandType.connection_type, null: false do
  argument :code, [String], required: false
  # <--shared arguments args1-->
end

We could use Resolver but it is not recommended unless absolutely necessary.

ingnam
  • 111
  • 1
  • 9
  • 1
    Not sure if decent way if possible, but I'd start here https://graphql-ruby.org/type_definitions/extensions first. There's a section about customizing arguments: https://graphql-ruby.org/type_definitions/extensions#customizing-arguments – Greg Jun 09 '21 at 07:20
  • Thanks @Grzegorz for the response. I did have look at customizing arguments and looks like it's the way to go. But I'm not quite sure how to implement it. Here's what I did: created `Types::SharedArguments` and added `argument_class SharedArguments` in `BaseField`. I'm not sure where/how do we put these shared arguments (`created_at`, `updated_at`) – ingnam Jun 10 '21 at 10:37
  • I'd guess `field :name, Type, argument_class(Types::SharedArgument)`, but I never tried it. – Greg Jun 10 '21 at 11:28

0 Answers0