你如何在ruby中编写可测试的graphql变异?

时间:2017-12-19 20:45:17

标签: ruby-on-rails graphql graphql-ruby

创建变异时,您通常会遵循本指南并使用GraphQL::Relay::Mutation.define创建一个 http://graphql-ruby.org/relay/mutations.html

我找到了这个网站,这解释了使用GraphQL::Function来创建变异的另一种方法 https://www.howtographql.com/graphql-ruby/3-mutations/
http://graphql-ruby.org/fields/function.html

GraphQL::Function看起来更容易测试,但我不确定与GraphQL::Relay::Mutation.define定义的突变相比,我是否会失去一些功能。

从客户端使用时有什么不同吗?

1 个答案:

答案 0 :(得分:0)

我认为这种方式更容易,在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
  }
相关问题