简体   繁体   English

GraphQL:InputObject 上的参数具有无效值 ([\"a\"])。 预期类型“[Bars.]?”。 如何在 Ruby 中将枚举传递给 GraphQL 查询?

[英]GraphQL: Argument on InputObject has an invalid value ([\"a\"]). Expected type '[Bars!]!'. How to pass enum to GraphQL query in Ruby?

I have this in my code:我的代码中有这个:

# spec
let(:query) do
  graphql_query_for(:foos,
                    {
                      foo_bars:      [:a],
                    },

And

module Types
  module Arguments
    class FoosInput < Types::BaseInputObject
      argument :foo_bars, [Types::Enums::BarsType], required: true

And

module Types
  module Enums
    class BarsType < Types::Enums::BaseEnum
      description 'List of different types of bars'
      convert_enum Foo.bars
    end
  end
end

And

class Foo < ApplicationRecord
  enum bar: {
    a:       'a',
    b:       'b',
    c:       'c',
    d:       'd',
  }
end

How do I get the spec to pass, how do I properly send in the enum as an argument to the GraphQL query?如何让规范通过,如何正确地将枚举作为参数发送给 GraphQL 查询?

I tried doing foo_bars: [Foo.bars['a']] , but similar error.我尝试做foo_bars: [Foo.bars['a']] ,但出现类似的错误。

I would like foo_bars to take an array of the enum Foo.bars .我希望foo_bars获取枚举Foo.bars的数组。

Figured it out, pass the enum key as all caps symbol, so in this case :A .想通了,将枚举键作为全部大写符号传递,所以在这种情况下是:A

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM