-
-
Notifications
You must be signed in to change notification settings - Fork 540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(graphql_parser): parse enum extension #3044
Merged
ematipico
merged 2 commits into
biomejs:main
from
vohoanglong0107:feat-graphql-enum-extension
Jun 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 29 additions & 23 deletions
52
crates/biome_graphql_factory/src/generated/node_factory.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
44 changes: 2 additions & 42 deletions
44
crates/biome_graphql_factory/src/generated/syntax_factory.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/enum_extension.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
extend enum Direction | ||
|
||
extend enum Direction | ||
NORTH | ||
} | ||
|
118 changes: 118 additions & 0 deletions
118
...biome_graphql_parser/tests/graphql_test_suite/err/definitions/enum_extension.graphql.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
--- | ||
source: crates/biome_graphql_parser/tests/spec_test.rs | ||
expression: snapshot | ||
--- | ||
## Input | ||
```graphql | ||
extend enum Direction | ||
|
||
extend enum Direction | ||
NORTH | ||
} | ||
|
||
|
||
``` | ||
|
||
## AST | ||
|
||
``` | ||
GraphqlRoot { | ||
bom_token: missing (optional), | ||
definitions: GraphqlDefinitionList [ | ||
GraphqlEnumTypeExtension { | ||
extend_token: EXTEND_KW@0..7 "extend" [] [Whitespace(" ")], | ||
enum_token: ENUM_KW@7..12 "enum" [] [Whitespace(" ")], | ||
name: GraphqlName { | ||
value_token: GRAPHQL_NAME@12..21 "Direction" [] [], | ||
}, | ||
directives: GraphqlDirectiveList [], | ||
enum_values: missing (optional), | ||
}, | ||
GraphqlEnumTypeExtension { | ||
extend_token: EXTEND_KW@21..30 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")], | ||
enum_token: ENUM_KW@30..35 "enum" [] [Whitespace(" ")], | ||
name: GraphqlName { | ||
value_token: GRAPHQL_NAME@35..44 "Direction" [] [], | ||
}, | ||
directives: GraphqlDirectiveList [], | ||
enum_values: GraphqlEnumValuesDefinition { | ||
l_curly_token: missing (required), | ||
values: GraphqlEnumValueList [ | ||
GraphqlEnumValueDefinition { | ||
description: missing (optional), | ||
value: GraphqlEnumValue { | ||
graphql_name: GraphqlName { | ||
value_token: GRAPHQL_NAME@44..52 "NORTH" [Newline("\n"), Whitespace(" ")] [], | ||
}, | ||
}, | ||
directives: GraphqlDirectiveList [], | ||
}, | ||
], | ||
r_curly_token: R_CURLY@52..54 "}" [Newline("\n")] [], | ||
}, | ||
}, | ||
], | ||
eof_token: EOF@54..56 "" [Newline("\n"), Newline("\n")] [], | ||
} | ||
``` | ||
|
||
## CST | ||
|
||
``` | ||
0: GRAPHQL_ROOT@0..56 | ||
0: (empty) | ||
1: GRAPHQL_DEFINITION_LIST@0..54 | ||
0: GRAPHQL_ENUM_TYPE_EXTENSION@0..21 | ||
0: EXTEND_KW@0..7 "extend" [] [Whitespace(" ")] | ||
1: ENUM_KW@7..12 "enum" [] [Whitespace(" ")] | ||
2: GRAPHQL_NAME@12..21 | ||
0: GRAPHQL_NAME@12..21 "Direction" [] [] | ||
3: GRAPHQL_DIRECTIVE_LIST@21..21 | ||
4: (empty) | ||
1: GRAPHQL_ENUM_TYPE_EXTENSION@21..54 | ||
0: EXTEND_KW@21..30 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")] | ||
1: ENUM_KW@30..35 "enum" [] [Whitespace(" ")] | ||
2: GRAPHQL_NAME@35..44 | ||
0: GRAPHQL_NAME@35..44 "Direction" [] [] | ||
3: GRAPHQL_DIRECTIVE_LIST@44..44 | ||
4: GRAPHQL_ENUM_VALUES_DEFINITION@44..54 | ||
0: (empty) | ||
1: GRAPHQL_ENUM_VALUE_LIST@44..52 | ||
0: GRAPHQL_ENUM_VALUE_DEFINITION@44..52 | ||
0: (empty) | ||
1: GRAPHQL_ENUM_VALUE@44..52 | ||
0: GRAPHQL_NAME@44..52 | ||
0: GRAPHQL_NAME@44..52 "NORTH" [Newline("\n"), Whitespace(" ")] [] | ||
2: GRAPHQL_DIRECTIVE_LIST@52..52 | ||
2: R_CURLY@52..54 "}" [Newline("\n")] [] | ||
2: EOF@54..56 "" [Newline("\n"), Newline("\n")] [] | ||
|
||
``` | ||
|
||
## Diagnostics | ||
|
||
``` | ||
enum_extension.graphql:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
|
||
× Expected at least one directive or a set of enum values | ||
|
||
1 │ extend enum Direction | ||
2 │ | ||
> 3 │ extend enum Direction | ||
│ ^^^^^^ | ||
4 │ NORTH | ||
5 │ } | ||
|
||
enum_extension.graphql:4:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
|
||
× expected `{` but instead found `NORTH` | ||
|
||
3 │ extend enum Direction | ||
> 4 │ NORTH | ||
│ ^^^^^ | ||
5 │ } | ||
6 │ | ||
|
||
i Remove NORTH | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/enum_extension.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
extend enum Direction @deprecated | ||
|
||
extend enum Direction { | ||
NORTH | ||
} | ||
|
||
extend enum Direction @deprecated { | ||
NORTH | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is truly necessary, as this parsing rule should only be called in one place (here), and we must have already checked for the presence of both tokens before advancing. Correct me if you think otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it’s not a blocker, but it’s good practice for the parser functions to validate their preconditions instead of assuming to be called correctly. It wouldn’t change anything functionally now, but it makes the contract more explicit and brings some extra robustness in the face of future changes to the parser.