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?
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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.