-
-
Notifications
You must be signed in to change notification settings - Fork 442
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(biome_graphql_parser): parse object extension #2928
feat(biome_graphql_parser): parse object extension #2928
Conversation
CodSpeed Performance ReportMerging #2928 will not alter performanceComparing Summary
|
PR has conflicts |
pub(crate) fn parse_object_type_extension(p: &mut GraphqlParser) -> ParsedSyntax { | ||
let m = p.start(); | ||
|
||
p.bump(T![extend]); |
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.
bump
can panic if the current token doesn't match.
It's better to use expect
or have a guard like is_at_object_type_extension
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 have placed a check on the outer parse_extension
function here, so unless this function was called outside of parse_extension
it should be fine. I think panic would even be preferred in this case, cause it will fail the test and indicate that this function was called at a unintended location. What do you think?
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.
Hmm, I'm unsure how to handle this better because I understand the cons and pros of both approaches.
I see two ways:
-
Add
is_at_object_type_extension
and use it only inparse_object_type_extension
. This brings some duplication because we already check the correct parser state beforehand. However, I tend to use this approach. -
Write documentation stating that we must check extends and type on the call sites; otherwise, it can cause a panic.
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 have added documents to check for the tokens. Since this pattern is also used in some other places, I have also documented them as well.
a8d390d
to
865a097
Compare
Summary
Parse GraphQL object type extensions (link). This is a small case, as almost all parsing logic was handled by a previous PR focusing on parsing object type definition.
The object extension syntax defined in the ungrammar was also needlessly complicated, so this PR also simplifies the syntax.
Test Plan
All tests should pass