Skip to content

Commit

Permalink
fix: check root operation type definition end at new operation defini…
Browse files Browse the repository at this point in the history
…tion (new query)
  • Loading branch information
vohoanglong0107 committed Apr 29, 2024
1 parent 6ff1c1e commit 42c0b7f
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 5 deletions.
5 changes: 4 additions & 1 deletion crates/biome_graphql_parser/src/parser/definitions/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,8 @@ fn is_at_root_operation_type_definition(p: &mut GraphqlParser<'_>) -> bool {
#[inline]
fn is_at_root_operation_type_definition_end(p: &mut GraphqlParser<'_>) -> bool {
// stop at closing brace or at the start of a new definition
p.at(T!['}']) || (!p.at_ts(OPERATION_TYPE) && is_at_definition(p))
p.at(T!['}'])
|| (!p.at_ts(OPERATION_TYPE) && is_at_definition(p))
// start of a new operation definition
|| (p.at_ts(OPERATION_TYPE) && !p.lookahead_at(T![:]))
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ schema {
"sth schema {
quer:
}
schema {
query: MyQueryRootType
schema {
query: MyQueryRootType
query MyQueryRootType {
field: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ schema {
quer:
}
schema {
query: MyQueryRootType
schema {
query: MyQueryRootType
query MyQueryRootType {
field: String
}
```
## AST
Expand Down Expand Up @@ -119,17 +129,87 @@ GraphqlRoot {
R_CURLY@197..199 "}" [Newline("\n")] [],
],
},
GraphqlSchemaDefinition {
description: missing (optional),
schema_token: SCHEMA_KW@199..208 "schema" [Newline("\n"), Newline("\n")] [Whitespace(" ")],
directives: GraphqlDirectiveList [],
l_curly_token: L_CURLY@208..209 "{" [] [],
root_operation_type: GraphqlRootOperationTypeDefinitionList [
GraphqlRootOperationTypeDefinition {
operation_type: GraphqlOperationType {
value_token: QUERY_KW@209..217 "query" [Newline("\n"), Whitespace(" ")] [],
},
colon_token: COLON@217..219 ":" [] [Whitespace(" ")],
named_type: GraphqlNamedType {
name: GraphqlName {
value_token: GRAPHQL_NAME@219..234 "MyQueryRootType" [] [],
},
},
},
],
r_curly_token: missing (required),
},
GraphqlSchemaDefinition {
description: missing (optional),
schema_token: SCHEMA_KW@234..243 "schema" [Newline("\n"), Newline("\n")] [Whitespace(" ")],
directives: GraphqlDirectiveList [],
l_curly_token: L_CURLY@243..244 "{" [] [],
root_operation_type: GraphqlRootOperationTypeDefinitionList [
GraphqlRootOperationTypeDefinition {
operation_type: GraphqlOperationType {
value_token: QUERY_KW@244..252 "query" [Newline("\n"), Whitespace(" ")] [],
},
colon_token: COLON@252..254 ":" [] [Whitespace(" ")],
named_type: GraphqlNamedType {
name: GraphqlName {
value_token: GRAPHQL_NAME@254..269 "MyQueryRootType" [] [],
},
},
},
],
r_curly_token: missing (required),
},
GraphqlOperationDefinition {
ty: GraphqlOperationType {
value_token: QUERY_KW@269..277 "query" [Newline("\n"), Newline("\n")] [Whitespace(" ")],
},
name: GraphqlName {
value_token: GRAPHQL_NAME@277..293 "MyQueryRootType" [] [Whitespace(" ")],
},
variables: missing (optional),
directives: GraphqlDirectiveList [],
selection_set: GraphqlSelectionSet {
l_curly_token: L_CURLY@293..294 "{" [] [],
selections: GraphqlSelectionList [
GraphqlField {
alias: GraphqlAlias {
value: GraphqlName {
value_token: GRAPHQL_NAME@294..301 "field" [Newline("\n"), Whitespace("\t")] [],
},
colon_token: COLON@301..303 ":" [] [Whitespace(" ")],
},
name: GraphqlName {
value_token: GRAPHQL_NAME@303..309 "String" [] [],
},
arguments: missing (optional),
directives: GraphqlDirectiveList [],
selection_set: missing (optional),
},
],
r_curly_token: R_CURLY@309..311 "}" [Newline("\n")] [],
},
},
],
eof_token: EOF@199..200 "" [Newline("\n")] [],
eof_token: EOF@311..312 "" [Newline("\n")] [],
}
```
## CST
```
0: GRAPHQL_ROOT@0..200
0: GRAPHQL_ROOT@0..312
0: (empty)
1: GRAPHQL_DEFINITION_LIST@0..199
1: GRAPHQL_DEFINITION_LIST@0..311
0: GRAPHQL_BOGUS_DEFINITION@0..154
0: SCHEMA_KW@0..7 "schema" [] [Whitespace(" ")]
1: GRAPHQL_DIRECTIVE_LIST@7..7
Expand Down Expand Up @@ -180,7 +260,56 @@ GraphqlRoot {
1: GRAPHQL_NAME@189..196 "quer" [Newline("\n"), Whitespace(" ")] []
2: COLON@196..197 ":" [] []
3: R_CURLY@197..199 "}" [Newline("\n")] []
2: EOF@199..200 "" [Newline("\n")] []
3: GRAPHQL_SCHEMA_DEFINITION@199..234
0: (empty)
1: SCHEMA_KW@199..208 "schema" [Newline("\n"), Newline("\n")] [Whitespace(" ")]
2: GRAPHQL_DIRECTIVE_LIST@208..208
3: L_CURLY@208..209 "{" [] []
4: GRAPHQL_ROOT_OPERATION_TYPE_DEFINITION_LIST@209..234
0: GRAPHQL_ROOT_OPERATION_TYPE_DEFINITION@209..234
0: GRAPHQL_OPERATION_TYPE@209..217
0: QUERY_KW@209..217 "query" [Newline("\n"), Whitespace(" ")] []
1: COLON@217..219 ":" [] [Whitespace(" ")]
2: GRAPHQL_NAMED_TYPE@219..234
0: GRAPHQL_NAME@219..234
0: GRAPHQL_NAME@219..234 "MyQueryRootType" [] []
5: (empty)
4: GRAPHQL_SCHEMA_DEFINITION@234..269
0: (empty)
1: SCHEMA_KW@234..243 "schema" [Newline("\n"), Newline("\n")] [Whitespace(" ")]
2: GRAPHQL_DIRECTIVE_LIST@243..243
3: L_CURLY@243..244 "{" [] []
4: GRAPHQL_ROOT_OPERATION_TYPE_DEFINITION_LIST@244..269
0: GRAPHQL_ROOT_OPERATION_TYPE_DEFINITION@244..269
0: GRAPHQL_OPERATION_TYPE@244..252
0: QUERY_KW@244..252 "query" [Newline("\n"), Whitespace(" ")] []
1: COLON@252..254 ":" [] [Whitespace(" ")]
2: GRAPHQL_NAMED_TYPE@254..269
0: GRAPHQL_NAME@254..269
0: GRAPHQL_NAME@254..269 "MyQueryRootType" [] []
5: (empty)
5: GRAPHQL_OPERATION_DEFINITION@269..311
0: GRAPHQL_OPERATION_TYPE@269..277
0: QUERY_KW@269..277 "query" [Newline("\n"), Newline("\n")] [Whitespace(" ")]
1: GRAPHQL_NAME@277..293
0: GRAPHQL_NAME@277..293 "MyQueryRootType" [] [Whitespace(" ")]
2: (empty)
3: GRAPHQL_DIRECTIVE_LIST@293..293
4: GRAPHQL_SELECTION_SET@293..311
0: L_CURLY@293..294 "{" [] []
1: GRAPHQL_SELECTION_LIST@294..309
0: GRAPHQL_FIELD@294..309
0: GRAPHQL_ALIAS@294..303
0: GRAPHQL_NAME@294..301
0: GRAPHQL_NAME@294..301 "field" [Newline("\n"), Whitespace("\t")] []
1: COLON@301..303 ":" [] [Whitespace(" ")]
1: GRAPHQL_NAME@303..309
0: GRAPHQL_NAME@303..309 "String" [] []
2: (empty)
3: GRAPHQL_DIRECTIVE_LIST@309..309
4: (empty)
2: R_CURLY@309..311 "}" [Newline("\n")] []
2: EOF@311..312 "" [Newline("\n")] []
```
Expand Down Expand Up @@ -334,4 +463,30 @@ schema.graphql:13:1 parse ━━━━━━━━━━━━━━━━━━
14quer:
15}
schema.graphql:20:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× expected `}` but instead found `schema`
18 │ query: MyQueryRootType
19 │
> 20 │ schema {
^^^^^^
21query: MyQueryRootType
22
i Remove schema
schema.graphql:23:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× expected `}` but instead found `query`
21query: MyQueryRootType
22
> 23query MyQueryRootType {
│ ^^^^^
24 │ field: String
25 │ }
i Remove query
```

0 comments on commit 42c0b7f

Please sign in to comment.