【问题标题】:How do you write your graphql mutations testable in ruby?您如何编写可在 ruby​​ 中测试的 graphql 突变?
【发布时间】:2017-12-19 20:45:17
【问题描述】:

当你创建一个突变时,你通常按照这个指南使用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 定义的突变相比,我不确定我是否会失去一些功能。

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

【问题讨论】:

  • 您可以测试您的突变字段的resolve 并测试已解决突变的影响。示例:YourMutationRoot.fields['updateCurrentUser'].resolve(nil, input, context) 您手动将提供的输入设置为散列,并且与上下文相同

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


【解决方案1】:

我认为这种方式更简单,在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
  }

【讨论】:

    猜你喜欢
    • 2020-03-22
    • 2022-01-07
    • 2021-04-14
    • 2021-08-23
    • 2019-04-10
    • 1970-01-01
    • 2019-10-30
    • 2019-04-06
    • 2021-08-31
    相关资源
    最近更新 更多