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

Allow to parse more AST nodes #306

Merged
merged 4 commits into from
Apr 20, 2023
Merged

Allow to parse more AST nodes #306

merged 4 commits into from
Apr 20, 2023

Conversation

sungam3r
Copy link
Member

fixes #296

@sungam3r sungam3r requested a review from Shane32 April 20, 2023 12:27
@sungam3r sungam3r self-assigned this Apr 20, 2023
@sungam3r sungam3r added the enhancement New feature or request label Apr 20, 2023
@github-actions github-actions bot added the test Pull request that adds new or changes existing tests label Apr 20, 2023
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

@@ -1418,23 +1420,23 @@ private GraphQLUnionTypeExtension ParseUnionTypeExtension(int start, List<GraphQ
return extension;
}

internal GraphQLValue ParseValueLiteral(bool isConstant)
public GraphQLValue ParseValueLiteral(bool? isConstant)
Copy link
Member

Choose a reason for hiding this comment

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

I don’t understand why these were changed to nullable booleans or what null does compared to false. Here I don’t see a difference.

Copy link
Member Author

Choose a reason for hiding this comment

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

GraphQLVariable inherits GraphQLValue and I called ParseValueLiteral with true before. In case of GraphQLVariable this method throws. null as a value of isConstant means that caller wants to parse any value - either constant or not (variable).

Copy link
Member Author

@sungam3r sungam3r Apr 20, 2023

Choose a reason for hiding this comment

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

Core difference is here:
изображение

variable will be parsed for false AND null

Copy link
Member

Choose a reason for hiding this comment

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

I still fail to understand why it's not a bool instead of bool?. It seems that null behaves identically to false. Why the change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, it works without ?, reverted.

else if (typeof(T) == typeof(GraphQLValue))
result = (T)(object)context.ParseValueLiteral(true);
result = (T)(object)context.ParseValueLiteral(null);
Copy link
Member

Choose a reason for hiding this comment

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

And here it’s now null. I’m sorta puzzled. Certainly for your use you would need the ability to have this as false, right ? And if false is null then why not false?

Copy link
Member Author

Choose a reason for hiding this comment

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

For my use case I wanted to be able to parse literals, so I wrote true here. Now I added support for parsing variables. Variable inherits GraphQLValue but parser will throw if you call ParseValueLiteral(true) on text $id.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not change calls inside parser - they all continue to pass either true or false as before. The single place where I pass null is here.

Copy link
Member

Choose a reason for hiding this comment

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

Are you adding something to the API so you can call ParseValueLiteral(true)? Or are you going to write an AST visitor to ensure that the value does not reference a variable?

Copy link
Member Author

Choose a reason for hiding this comment

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

I reverted bool? to bool and now pass false. It works. My bad.

@codecov-commenter
Copy link

Codecov Report

Merging #306 (844b2e3) into master (8483d95) will increase coverage by 0.20%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master     #306      +/-   ##
==========================================
+ Coverage   96.02%   96.23%   +0.20%     
==========================================
  Files          85       85              
  Lines        4835     4889      +54     
  Branches      448      475      +27     
==========================================
+ Hits         4643     4705      +62     
+ Misses        190      184       -6     
+ Partials        2        0       -2     
Impacted Files Coverage Δ
src/GraphQLParser/Parser.cs 100.00% <100.00%> (+53.33%) ⬆️
src/GraphQLParser/ParserContext.Parse.cs 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@sungam3r sungam3r merged commit 7b0e9da into master Apr 20, 2023
@sungam3r sungam3r deleted the parse branch April 20, 2023 15:32
@sungam3r
Copy link
Member Author

@Shane32 Are you OK to release v9 after merge?

@Shane32
Copy link
Member

Shane32 commented Apr 20, 2023

@Shane32 Are you OK to release v9 after merge?

Sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request test Pull request that adds new or changes existing tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More Parse methods
3 participants