Graphql-ruby mutations
From wikinotes
Mutations are graphql fields that trigger side effects.
- mutations return a hash, that contains all of the fields defined on it.
- mutations may optionally accept arguments
Basics
Set the root-mutation object on the schema
class MyGraph < GraphQL::Schema mutation(MyMutationRoot) endAdd your mutations as fields on the mutation-root
class MyMutationRoot < GraphQL::Schema::RelayClassicMutation field :mymutation, mutation: MyMutation # TODO: needs arg?? endDefine your mutation
class MyMutation < GraphQL::Schema::RelayClassicMutation argument :username, String, required: true field :message, String, null: true # returns string, allows null field :errors, [String], null, false # returns list of strings, disallows null def resolve(username) # do thing that produces side effect { message: "Hello #{username}", errors: [] } end end