Schema parsing fails when a union has a leading pipe
mattcosta7 opened this issue · 1 comments
Describe the bug
Prettier version 3.2.0 started formatting unions in schemas with a leading bar when they are defined across lines
When consuming/validating a schema using this gem, however, we get an error when using that formatting standard.
Which notes that this syntax has been support for years (since graphql 0.10.3) - prettier/prettier#15870 (comment) https://github.com/graphql/graphql-js/releases/tag/v0.10.3
see: https://prettier.io/blog/2024/01/12/3.2.0#graphql
this gem's parser fails on schemas like this with
it "is parsed for union definitions when the union has a leading bar" do
document = subject.parse <<-GRAPHQL
"Thing description"
union Thing =
| Int
| String
GRAPHQL
thing_defn = document.definitions[0]
assert_equal "Thing", thing_defn.name
assert_equal "Thing description", thing_defn.description
end
Error:
GraphQL::Language::Parser::string description#test_0004_is parsed for union definitions:
GraphQL::ParseError: Expected NAME, actual: PIPE ("|") at [3, 11]
lib/graphql/language/parser.rb:799:in `raise_parse_error'
lib/graphql/language/parser.rb:788:in `expect_token'
lib/graphql/language/parser.rb:627:in `parse_name'
lib/graphql/language/parser.rb:640:in `parse_type_name'
lib/graphql/language/parser.rb:401:in `parse_union_members'
lib/graphql/language/parser.rb:335:in `definition'
lib/graphql/language/parser.rb:103:in `document'
lib/graphql/language/parser.rb:45:in `block in parse'
lib/graphql/tracing/trace.rb:24:in `parse'
lib/graphql/language/parser.rb:44:in `parse'
lib/graphql/language/parser.rb:16:in `parse'
lib/graphql.rb:38:in `parse'
spec/graphql/language/parser_spec.rb:253:in `block (3 levels) in <top (required)>'
Versions
graphql
version: all as far as I can tell
GraphQL schema
Include relevant types and fields (in Ruby is best, in GraphQL IDL is ok). Any custom extensions, etc?
GraphQL schema
union Thing =
| Int
| String
Additional context
Add any other context about the problem here.
With these details, we can efficiently hunt down the bug!
Hey, thanks for the detailed report! I never noticed that a leading pipe was valid syntax, but sure enough: https://github.com/graphql/graphql-spec/blame/f8f2fac7478df812af885f7f8470cdb5a6c1659b/spec/Section%203%20--%20Type%20System.md#L1410-L1411
I agree, the parser should handle this without a hitch 👍