Skip to content
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 schema definition #2557

Merged

Conversation

vohoanglong0107
Copy link
Contributor

Summary

Parse GraphQL schema definition. This is a small case so I parse both the happy path and error path in this PR

Test Plan

All tests should pass

@vohoanglong0107 vohoanglong0107 marked this pull request as ready for review April 22, 2024 10:33
Copy link

codspeed-hq bot commented Apr 22, 2024

CodSpeed Performance Report

Merging #2557 will not alter performance

Comparing vohoanglong0107:feat-graphql-parse-schema-definition (42c0b7f) with main (1abda0c)

Summary

✅ 88 untouched benchmarks

}

fn is_at_list_end(&self, p: &mut Self::Parser<'_>) -> bool {
is_at_root_operation_type_definition_end(p)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please help me to understand why we need here is_at_root_operation_type_definition_end?
What cases do we cover? Is it possible to check only p.at(T!['}'])?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider this case:

schema {
  query: MyQueryRootType
  mutation: MyMutationRootType

schema {
  query: Query
}

If we only check for p.at(T!['}']) the second schema definition is also included in RootOperationType, so I included another check to see if we are at the start of other definition or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this is a good idea?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's a great idea.

I'm wondering if it's possible to have a 'complex' check when we get an Absent result from the parse_element function.
Specifically, it would be beneficial to maintain p.at(T!['}']) the happy path, avoiding additional checks which are required for the failure path.

I don't have any work solution for now, we might think about it in the next MR.


#[inline]
fn parse_root_operation_type_definition(p: &mut GraphqlParser) -> ParsedSyntax {
if !(p.at_ts(OPERATION_TYPE) || p.at(T![:]) || p.lookahead_at(T![:])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can extract p.at_ts(OPERATION_TYPE) || p.at(T![:]) || p.lookahead_at(T![:]) as a is_at_root_operation_type_definition function and reuse it in the RootOperationTypeDefinitionListRecovery.

Copy link
Contributor

@denbezrukov denbezrukov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀🚀🚀

@vohoanglong0107 vohoanglong0107 force-pushed the feat-graphql-parse-schema-definition branch from 3db791d to 00dc3b2 Compare April 23, 2024 11:41
@vohoanglong0107 vohoanglong0107 force-pushed the feat-graphql-parse-schema-definition branch from 00dc3b2 to 42c0b7f Compare April 29, 2024 03:44
Copy link
Contributor

@arendjr arendjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job!

@arendjr arendjr merged commit 5fda633 into biomejs:main May 1, 2024
12 checks passed
@vohoanglong0107 vohoanglong0107 deleted the feat-graphql-parse-schema-definition branch May 1, 2024 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants