Skip to content

Commit b0a9b49

Browse files
fix: Parser fails to parse object type def with no fields (#901)
According to the spec, a syntactically valid object type definition can have no fields (if the curlies are omitted). See the second option: https://spec.graphql.org/draft/#ObjectTypeDefinition This removes the parse expectation that the only `TokenKind::Name` which can follow a type's name is `implements`, since it can also be the beginning of a following definition or extension. Credit to @swcollard for spotting this bug during LSP QA!
1 parent e27ac26 commit b0a9b49

7 files changed

+125
-2
lines changed

crates/apollo-parser/src/parser/grammar/object.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ pub(crate) fn object_type_definition(p: &mut Parser) {
3535
if let Some(TokenKind::Name) = p.peek() {
3636
if p.peek_data().unwrap() == "implements" {
3737
implements_interfaces(p);
38-
} else {
39-
p.err("unexpected Name");
4038
}
4139
}
4240

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"A type with no fields"
2+
type AnObjectTypeWithoutFields
3+
4+
extend type AnObjectTypeWithoutFields {
5+
id: ID!
6+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
3+
4+
5+
- [email protected] "\"A type with no fields\""
6+
7+
8+
9+
10+
- [email protected] "AnObjectTypeWithoutFields"
11+
12+
13+
- [email protected] "extend"
14+
15+
16+
17+
18+
- [email protected] "AnObjectTypeWithoutFields"
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
recursion limit: 500, high: 0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"An interface with no fields"
2+
interface AnInterfaceWithoutFields
3+
4+
extend interface AnInterfaceWithoutFields {
5+
id: ID!
6+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
3+
4+
5+
- [email protected] "\"An interface with no fields\""
6+
7+
- [email protected] "interface"
8+
9+
10+
- [email protected] "AnInterfaceWithoutFields"
11+
12+
13+
- [email protected] "extend"
14+
15+
- [email protected] "interface"
16+
17+
18+
- [email protected] "AnInterfaceWithoutFields"
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
recursion limit: 500, high: 0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"An input with no input values"
2+
input AnInputWithoutInputValues
3+
4+
extend input AnInputWithoutInputValues {
5+
limit: Int!
6+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
3+
4+
5+
- [email protected] "\"An input with no input values\""
6+
7+
8+
9+
10+
- [email protected] "AnInputWithoutInputValues"
11+
12+
13+
- [email protected] "extend"
14+
15+
16+
17+
18+
- [email protected] "AnInputWithoutInputValues"
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
recursion limit: 500, high: 0

0 commit comments

Comments
 (0)