1
votes

When you create a mutation, you usually follow this guide and create one with GraphQL::Relay::Mutation.define
http://graphql-ruby.org/relay/mutations.html

I found this website, and this explains another approach to create a mutation by using GraphQL::Function
https://www.howtographql.com/graphql-ruby/3-mutations/
http://graphql-ruby.org/fields/function.html

GraphQL::Function looks so much easier to test, but I am not sure if I will lose some functionalities compared to a mutation defined by GraphQL::Relay::Mutation.define.

Are there any differences when to use from the client side?

1
You could test the resolve of your mutation's field and test the impact of the resolved mutation. Example: YourMutationRoot.fields['updateCurrentUser'].resolve(nil, input, context) where you manually set the provided input as a hash and same for context - MrYoshiji

1 Answers

0
votes

i think this way is more easy, in mutation_type.rb

Types::MutationType = GraphQL::ObjectType.define do
  name "Mutation"

  field :yourMutation, yourType do
    argument :field, type_of_field
    resolve -> (obj, args, ctx){
      #do whatever you want
  }