简体   繁体   English

您如何编写可在红宝石中测试的graphql突变?

[英]How do you write your graphql mutations testable in ruby?

When you create a mutation, you usually follow this guide and create one with GraphQL::Relay::Mutation.define 创建突变时,通常遵循本指南并使用GraphQL::Relay::Mutation.define创建一个
http://graphql-ruby.org/relay/mutations.html http://graphql-ruby.org/relay/mutations.html

I found this website, and this explains another approach to create a mutation by using GraphQL::Function 我找到了这个网站,这解释了使用GraphQL::Function创建变异的另一种方法
https://www.howtographql.com/graphql-ruby/3-mutations/ https://www.howtographql.com/graphql-ruby/3-mutations/
http://graphql-ruby.org/fields/function.html 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 . GraphQL::Function看起来很容易测试,但是与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 我认为在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
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GraphQL Ruby:如何编写具有多个参数的 DRY 突变? - GraphQL Ruby: How to write DRY mutations with multiple parameters? 如何将 url 中的图像写入 Ruby 中的文件系统? - How do you write an image at a url to your filesystem in Ruby? 您更喜欢在Ruby On Rails中组织测试数据吗? - How do you prefer to organize your test data in Ruby On Rails? 您如何打开最近的ruby rails项目? - how do you open up your recent ruby rails project? 如何处理rails中graphql突变的错误 - how to handle errors in graphql mutations in rails 如何使用 Rails 和 GraphQL 处理复杂的突变 - How to handle complex mutations with Rails and GraphQL 你如何在Ruby on Rails中编写一个内联的条件三元运算符? - How do you write a conditional ternary operator inline in Ruby on Rails? 如果您的ruby on rails脚本中有多个错误,那么它如何知道显示哪个错误? - If you have more than 1 error in your ruby on rails script, how does it know which one do display? graphql-红宝石。 使用(不是中继)突变DRY。 有没有GraphQL :: Function? - graphql-ruby. Use (not Relay) mutations DRY. With or without GraphQL::Function? 在Ruby on Rails 3.1中,你在哪里放置自己的类? - In Ruby on Rails 3.1, where do you put your own classes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM