I'm trying to implement two mutations in graphql-ruby - one for creation of a resource, and one for editing. In most scenarios, they both take the exact same parameters from the client, so I want to avoid duplicating the mutations and try and have the arguments specified in a reusable class/module.
I'm using graphql-ruby 1.8 and the new class based API, and have started with this:
class Mutations::ApplicationMutation < GraphQL::Schema::Mutation
... common to every mutation ...
end
class Mutations::CreateResourceMutation < Mutations::ApplicationMutation
argument :name, String, required: true
argument :description, String
argument :create_only_field, String
end
class Mutations::UpdateResourceMutation < Mutations::ApplicationMutation
argument :name, String, required: true
argument :description, String
argument :update_only_field, String
end
In this basic example, the name
and description
attributes are the same in both mutations. I've extracted the resolver out into another class so that is reusable, but I'm not sure the best way to tackle the arguments.
I imagine an ActiveSupport::Concern would work, but it doesn't feel right or the way I think it should work for this, but I'm very new to GraphQL in general so have no idea.
Aucun commentaire:
Enregistrer un commentaire