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

Fix NRE when printing directive without locations #300

Merged
merged 1 commit into from
Apr 18, 2023
Merged

Conversation

sungam3r
Copy link
Member

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

Codecov Report

Merging #300 (c6a4c8d) into master (b05f365) will increase coverage by 0.00%.
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     #300   +/-   ##
=======================================
  Coverage   99.82%   99.82%           
=======================================
  Files          85       85           
  Lines        4540     4547    +7     
  Branches      459      461    +2     
=======================================
+ Hits         4532     4539    +7     
  Misses          6        6           
  Partials        2        2           
Impacted Files Coverage Δ
src/GraphQLParser/Visitors/SDLPrinter.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.

Copy link
Member

@Shane32 Shane32 left a comment

Choose a reason for hiding this comment

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

The real problem is that we have = null!; as the property initializer, which we should not if we are exposing the class publicly.

@sungam3r
Copy link
Member Author

I can argue. = null! is done by following the GraphQL grammar - the AST node for locations is not optional. For optional nodes we do have ? in their property type.

@sungam3r
Copy link
Member Author

I mean any property in AST node may be uninialized now if constructed manually. Parser throws exception if locations not set into parsed text.

@sungam3r sungam3r merged commit ee3179c into master Apr 18, 2023
@sungam3r sungam3r deleted the locations branch April 18, 2023 04:56
@Shane32
Copy link
Member

Shane32 commented Apr 18, 2023

Right but what I mean is that we should have a constructor which requires a value and remove the default constructor, in order for the NRT attributes to be accurate always. Then “= null!” is not required. Or, make the default constructors internal.

Certainly the NRT attributes are correct as-is to match the AST parsing.

@sungam3r
Copy link
Member Author

It will force us to switch the order of nodes creation from "parent, then child" to "child, then parent" and
may give unforseen consequences.

@Shane32
Copy link
Member

Shane32 commented Apr 18, 2023

Internally we can still do it the other way. But the public constructor would have proper NRT attributes. We can also allow for users to pass in null! if they like to the constructor, but they are then knowingly breaking NRT semantics.

@sungam3r
Copy link
Member Author

Understood.

@sungam3r sungam3r mentioned this pull request Apr 18, 2023
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.

3 participants