'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?
I tried doing foo_bars: [Foo.bars['a']], but similar error.
I would like foo_bars to take an array of the enum Foo.bars.
Solution 1:[1]
Figured it out, pass the enum key as all caps symbol, so in this case :A.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alien |
