Skip to content

Commit e1829e4

Browse files
committed
fix(QueryParserSpecification) update to match ligraphqlparser
1 parent 66bb7e6 commit e1829e4

File tree

3 files changed

+38
-41
lines changed

3 files changed

+38
-41
lines changed

lib/graphql/compatibility/query_parser_specification.rb

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,6 @@ def test_it_parses_queries
3737
assert_valid_typeless_inline_fragment(query.selections[3])
3838
end
3939

40-
def test_it_parses_empty_arguments
41-
strings = [
42-
"{ field { } }",
43-
"{ field() }",
44-
]
45-
strings.each do |query_str|
46-
doc = parse(query_str)
47-
field = doc.definitions.first.selections.first
48-
assert_equal 0, field.arguments.length
49-
assert_equal 0, field.selections.length
50-
end
51-
end
52-
5340
def test_it_parses_unnamed_queries
5441
document = parse("{ name, age, height }")
5542
operation = document.definitions.first
@@ -59,14 +46,18 @@ def test_it_parses_unnamed_queries
5946
assert_equal 3, operation.selections.length
6047
end
6148

49+
def test_it_parses_the_introspection_query
50+
parse(GraphQL::Introspection::INTROSPECTION_QUERY)
51+
end
52+
6253
def test_it_parses_inputs
6354
query_string = %|
6455
{
6556
field(
6657
int: 3,
6758
float: 4.7e-24,
6859
bool: false,
69-
string: "☀︎🏆\\n escaped \\" unicode \\u00b6 /",
60+
string: "☀︎🏆\\n escaped \\" unicode \u00b6 /",
7061
enum: ENUM_NAME,
7162
array: [7, 8, 9]
7263
object: {a: [1,2,3], b: {c: "4"}}

lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_it_includes_line_and_column
1515
}
1616
")
1717

18-
assert_includes(err.message, '"{"')
18+
assert_includes(err.message, '{')
1919
assert_equal(3, err.line)
2020
assert_equal(27, err.col)
2121
end
@@ -31,7 +31,10 @@ def test_it_rejects_unexpected_ends
3131

3232
def assert_rejects_character(char)
3333
err = assert_raises_parse_error("{ field#{char} }")
34-
assert_includes(err.message, char.inspect, "The message includes the invalid character")
34+
expected_char = char.inspect.gsub('"', '').downcase
35+
msg_downcase = err.message.downcase
36+
# Case-insensitive for UTF-8 printing
37+
assert_includes(msg_downcase, expected_char, "The message includes the invalid character")
3538
end
3639

3740
def test_it_rejects_invalid_characters

spec/graphql/language/parser_spec.rb

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,35 @@
1111
}
1212
|}
1313

14-
describe ".parse" do
15-
it "parses queries" do
16-
assert document
17-
end
18-
19-
describe "visited nodes" do
20-
let(:fragment) { document.definitions.first }
21-
22-
it "creates an anonymous fragment definition" do
23-
assert fragment.is_a?(GraphQL::Language::Nodes::FragmentDefinition)
24-
assert_equal nil, fragment.name
25-
assert_equal 1, fragment.selections.length
26-
assert_equal "NestedType", fragment.type.name
27-
assert_equal 1, fragment.directives.length
28-
assert_equal [2, 7], fragment.position
29-
end
30-
end
31-
32-
it "parses the test schema" do
33-
schema = DummySchema
34-
schema_string = GraphQL::Schema::Printer.print_schema(schema)
35-
36-
document = subject.parse(schema_string)
14+
let(:fragment) { document.definitions.first }
15+
16+
it "creates an anonymous fragment definition" do
17+
assert fragment.is_a?(GraphQL::Language::Nodes::FragmentDefinition)
18+
assert_equal nil, fragment.name
19+
assert_equal 1, fragment.selections.length
20+
assert_equal "NestedType", fragment.type.name
21+
assert_equal 1, fragment.directives.length
22+
assert_equal [2, 7], fragment.position
23+
end
24+
end
3725

38-
assert_equal schema_string, document.to_query_string
39-
end
26+
it "parses empty arguments" do
27+
strings = [
28+
"{ field { inner } }",
29+
"{ field() { inner }}",
30+
]
31+
strings.each do |query_str|
32+
doc = subject.parse(query_str)
33+
field = doc.definitions.first.selections.first
34+
assert_equal 0, field.arguments.length
35+
assert_equal 1, field.selections.length
4036
end
4137
end
38+
39+
it "parses the test schema" do
40+
schema = DummySchema
41+
schema_string = GraphQL::Schema::Printer.print_schema(schema)
42+
document = subject.parse(schema_string)
43+
assert_equal schema_string, document.to_query_string
44+
end
4245
end

0 commit comments

Comments
 (0)