Skip to content

Commit 44a9c84

Browse files
committed
Improve SDL directive argument coercion
1 parent 21b4409 commit 44a9c84

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/graphql/schema/directive.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,14 @@ def initialize(owner, **arguments)
142142
# However, we're using result coercion here to go from Ruby value
143143
# to GraphQL value, so it doesn't have that feature.
144144
# Keep the GraphQL-type behavior but implement it manually:
145-
coerce_value = [coerce_value]
145+
wrap_type = arg_type
146+
while wrap_type.list?
147+
if wrap_type.non_null?
148+
wrap_type = wrap_type.of_type
149+
end
150+
wrap_type = wrap_type.of_type
151+
coerce_value = [coerce_value]
152+
end
146153
end
147154
arg_type.coerce_isolated_result(coerce_value)
148155
rescue GraphQL::Schema::Enum::UnresolvedValueError

spec/graphql/schema/build_from_definition_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,4 +1921,20 @@ module MyInterface
19211921
GRAPHQL
19221922
GraphQL::Schema.from_definition(schema_sdl)
19231923
end
1924+
1925+
it "works with invalid directive argument value" do
1926+
sdl = <<~EOS
1927+
directive @requiresScopes(scopes: [[String]]) on FIELD_DEFINITION
1928+
1929+
type Query {
1930+
product: Product
1931+
}
1932+
1933+
type Product {
1934+
shippingEstimate: String @requiresScopes(scopes: "shipping")
1935+
}
1936+
EOS
1937+
1938+
assert GraphQL::Schema.from_definition(sdl).to_definition
1939+
end
19241940
end

0 commit comments

Comments
 (0)