Skip to content

Commit

Permalink
implement parser validation for types missing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tinnou committed Mar 26, 2024
1 parent 25d006a commit a4bf64e
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 34 deletions.
6 changes: 3 additions & 3 deletions crates/apollo-compiler/tests/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn get_operations() {
#[test]
fn is_introspection_operation() {
let query_input = r#"
type Query {}
type Query { foo: String }
query TypeIntrospect {
__type(name: "User") {
name
Expand Down Expand Up @@ -184,7 +184,7 @@ fn is_introspection_deep() {
#[test]
fn is_introspection_repeated_fragment() {
let query_input_indirect = r#"
type Query {}
type Query { foo: String }
query IntrospectRepeatedIndirectFragment {
...A
Expand All @@ -204,7 +204,7 @@ fn is_introspection_repeated_fragment() {
"#;

let query_input_direct = r#"
type Query {}
type Query { foo: String }
query IntrospectRepeatedDirectFragment {
...C
Expand Down
6 changes: 6 additions & 0 deletions crates/apollo-parser/src/parser/grammar/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ pub(crate) fn field(p: &mut Parser) {
pub(crate) fn fields_definition(p: &mut Parser) {
let _g = p.start_node(SyntaxKind::FIELDS_DEFINITION);
p.bump(S!['{']);

match p.peek() {
Some(TokenKind::Name | TokenKind::StringValue) => field_definition(p),
_ => p.err("expected Field Definition"),
}

p.peek_while(|p, kind| match kind {
TokenKind::Name | TokenKind::StringValue => {
field_definition(p);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cats
# https://github.com/apollographql/apollo-rs/issues/325

interface X {}
interface X

cats
type Query {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
- DOCUMENT@0..115
- DOCUMENT@0..112
- [email protected] "cats"
- [email protected] "\n"
- [email protected] "# https://github.com/apollographql/apollo-rs/issues/325"
- [email protected] "\n\n"
- INTERFACE_TYPE_DEFINITION@62..76
- INTERFACE_TYPE_DEFINITION@62..73
- [email protected] "interface"
- [email protected] " "
- [email protected]
- [email protected] "X"
- [email protected] " "
- [email protected]
- [email protected] "{"
- [email protected] "}"
- [email protected] "\n\n"
- [email protected] "cats"
- [email protected] "\n"
- [email protected]
- [email protected] "type"
- [email protected] " "
- [email protected]
- [email protected] "Query"
- [email protected] " "
- [email protected]
- [email protected] "{"
- [email protected] "\n "
- [email protected]
- [email protected]
- [email protected] "name"
- [email protected] ":"
- [email protected] " "
- [email protected]
- [email protected]
- [email protected] "String"
- [email protected] "\n"
- [email protected] "}"
- [email protected] "\n"
- [email protected] "\n\n"
- [email protected] "cats"
- [email protected] "\n"
- [email protected]
- [email protected] "type"
- [email protected] " "
- [email protected]
- [email protected] "Query"
- [email protected] " "
- [email protected]
- [email protected] "{"
- [email protected] "\n "
- [email protected]
- [email protected]
- [email protected] "name"
- [email protected] ":"
- [email protected] " "
- [email protected]
- [email protected]
- [email protected] "String"
- [email protected] "\n"
- [email protected] "}"
- [email protected] "\n"
- ERROR@0:4 "expected definition" cats
- ERROR@78:82 "expected definition" cats
- ERROR@75:79 "expected definition" cats
recursion limit: 500, high: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type {
id: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- [email protected]
- [email protected]
- [email protected] "type"
- [email protected] " "
- [email protected]
- [email protected] "{"
- [email protected] "\n "
- [email protected]
- [email protected]
- [email protected] "id"
- [email protected] ":"
- [email protected] " "
- [email protected]
- [email protected]
- [email protected] "String"
- [email protected] "\n"
- [email protected] "}"
- ERROR@6:7 "expected a name" {
recursion limit: 500, high: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type Person { id: String
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- [email protected]
- [email protected]
- [email protected] "type"
- [email protected] " "
- [email protected]
- [email protected] "Person"
- [email protected] " "
- [email protected]
- [email protected] "{"
- [email protected] " "
- [email protected]
- [email protected]
- [email protected] "id"
- [email protected] ":"
- [email protected] " "
- [email protected]
- [email protected]
- [email protected] "String"
- ERROR@24:24 "expected R_CURLY, got EOF" EOF
recursion limit: 500, high: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type Person {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- [email protected]
- [email protected]
- [email protected] "type"
- [email protected] " "
- [email protected]
- [email protected] "Person"
- [email protected] " "
- [email protected]
- [email protected] "{"
- [email protected] "\n"
- [email protected] "}"
- ERROR@14:15 "expected Field Definition" }
recursion limit: 500, high: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface {
id: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- [email protected]
- [email protected]
- [email protected] "interface"
- [email protected] " "
- [email protected]
- [email protected] "{"
- [email protected] "\n "
- [email protected]
- [email protected]
- [email protected] "id"
- [email protected] ":"
- [email protected] " "
- [email protected]
- [email protected]
- [email protected] "String"
- [email protected] "\n"
- [email protected] "}"
- ERROR@10:11 "expected a Name" {
recursion limit: 500, high: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
interface Person {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- [email protected]
- [email protected]
- [email protected] "interface"
- [email protected] " "
- [email protected]
- [email protected] "Person"
- [email protected] " "
- [email protected]
- [email protected] "{"
- [email protected] "\n"
- [email protected] "}"
- ERROR@19:20 "expected Field Definition" }
recursion limit: 500, high: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
interface Person { id: String
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- [email protected]
- [email protected]
- [email protected] "interface"
- [email protected] " "
- [email protected]
- [email protected] "Person"
- [email protected] " "
- [email protected]
- [email protected] "{"
- [email protected] " "
- [email protected]
- [email protected]
- [email protected] "id"
- [email protected] ":"
- [email protected] " "
- [email protected]
- [email protected]
- [email protected] "String"
- ERROR@29:29 "expected R_CURLY, got EOF" EOF
recursion limit: 500, high: 0

0 comments on commit a4bf64e

Please sign in to comment.