[英]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.