`GraphQL::Query#variables` raises `GraphQL::Schema::Enum::MissingValuesError` when the enum isn't visible
eapache-opslevel opened this issue · 4 comments
eapache-opslevel commented
Describe the bug
We have an enum with limited visibility. When that enum is used in an input variable (nested in an input object, though that may be irrelevant), and the enum isn't visible, and our ruby code calls result.query.variables
, it crashes with the noted MissingValuesError
because none of the values of the enum pass the warden.
The query itself returns the correct error to the user, but result.query.variables
shouldn't crash here I don't think.
Versions
graphql
version: 2.2.14
rails
(or other framework): 7.1.3.4
GraphQL schema
(with some stuff elided of course)
module Types
class TypeEnum < Types::BaseEnum
TYPES = [
:contains,
:equals,
]
TYPES.each do |type|
value(type)
end
end
end
module Types
class FilterInput < Types::BaseInputObject
argument :type,
Types::TypeEnum,
required: false,
default_value: "equals",
visibility: :public
end
end
GraphQL query
query servicesIndex($filter: [FilterInput!]) {
account {
services(filter: $filter) {
nodes {
id
}
}
}
}
variables:
{
"filter": {
"type": "equals",
}
}
The query seems to return the right error message when executed normally:
(byebug) result.to_h
{"errors"=>[{"message"=>"Field 'services' doesn't accept argument 'filter'", "locations"=>[{"line"=>3, "column"=>14}], "path"=>["query servicesIndex", "account", "services", "filter"], "extensions"=>{"code"=>"argumentNotAccepted", "name"=>"services", "typeName"=>"Field", "argumentName"=>"filter"}}, {"message"=>"Variable $filter is declared by servicesIndex but not used", "locations"=>[{"line"=>1, "column"=>1}], "path"=>["query servicesIndex"], "extensions"=>{"code"=>"variableNotUsed", "variableName"=>"filter"}}]}
Actual behavior
Click to view exception backtrace
GraphQL::Schema::Enum::MissingValuesError: Enum types require at least one value, but TypeEnum didn't provide any for this query. Make sure at least one value is defined and visible for this query. (GraphQL::Schema::Enum::MissingValuesError)
from graphql (2.2.14) lib/graphql/schema/warden.rb:216:in `block in enum_values'
from graphql (2.2.14) lib/graphql/schema/warden.rb:380:in `block in read_through'
from graphql (2.2.14) lib/graphql/schema/warden.rb:220:in `enum_values'
from graphql (2.2.14) lib/graphql/schema/enum.rb:133:in `validate_non_null_input'
from graphql (2.2.14) lib/graphql/schema/member/validates_input.rb:15:in `validate_input'
from graphql (2.2.14) lib/graphql/schema/input_object.rb:181:in `block (2 levels) in validate_non_null_input'
from actionpack (7.1.3.4) lib/action_controller/metal/strong_parameters.rb:400:in `block in each_pair'
from actionpack (7.1.3.4) lib/action_controller/metal/strong_parameters.rb:399:in `each_pair'
from actionpack (7.1.3.4) lib/action_controller/metal/strong_parameters.rb:399:in `each_pair'
from graphql (2.2.14) lib/graphql/schema/input_object.rb:173:in `block in validate_non_null_input'
from graphql (2.2.14) lib/graphql/schema/input_object.rb:172:in `each'
from graphql (2.2.14) lib/graphql/schema/input_object.rb:172:in `validate_non_null_input'
from graphql (2.2.14) lib/graphql/schema/member/validates_input.rb:15:in `validate_input'
from graphql (2.2.14) lib/graphql/schema/non_null.rb:40:in `validate_input'
from graphql (2.2.14) lib/graphql/schema/list.rb:51:in `block in validate_non_null_input'
from graphql (2.2.14) lib/graphql/schema/list.rb:50:in `each'
from graphql (2.2.14) lib/graphql/schema/list.rb:50:in `each_with_index'
from graphql (2.2.14) lib/graphql/schema/list.rb:50:in `validate_non_null_input'
from graphql (2.2.14) lib/graphql/schema/member/validates_input.rb:15:in `validate_input'
from graphql (2.2.14) lib/graphql/query/variables.rb:38:in `block in initialize'
from graphql (2.2.14) lib/graphql/query/variables.rb:19:in `each'
from graphql (2.2.14) lib/graphql/query/variables.rb:19:in `each_with_object'
from graphql (2.2.14) lib/graphql/query/variables.rb:19:in `initialize'
from graphql (2.2.14) lib/graphql/query.rb:257:in `new'
from graphql (2.2.14) lib/graphql/query.rb:257:in `block in variables'
from graphql (2.2.14) lib/graphql/query.rb:460:in `with_prepared_ast'
from graphql (2.2.14) lib/graphql/query.rb:256:in `variables'