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

@semanticNonNull support #7681

Merged
merged 13 commits into from
Nov 17, 2024
Merged

Conversation

tobias-tengler
Copy link
Collaborator

@tobias-tengler tobias-tengler commented Nov 4, 2024

Adds a new EnableSemanticNonNull option that, when set to true, rewrites all non-null fields to nullable fields and annotates them with the @semanticNonNull directive. A ResultFormatter is added to the rewritten fields that throws an error if a null value is returned at a position that is marked as semantically non-null.

builder.Services
  .AddGraphQLServer()
  .ModifyOptions(o =>
  {
    o.EnableSemanticNonNull = true;
  });

The @semanticNonNull directive has a levels argument that allows to specify the semantic non-nullability in the context of lists. 0 is the outer most list and n the named type.

Non-Null Semantic Non-Null
field: String! field: String @semanticNonNull
field: [String!] field: [String] @semanticNonNull(levels: [ 1 ])
field: [[String!]]! field: [[String]] @semanticNonNull(levels: [ 0, 2 ])

@tobias-tengler tobias-tengler force-pushed the tte/hotchocolate-semantic-non-null branch from 79ec25d to 1f766a2 Compare November 4, 2024 20:36
Copy link

codecov bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.03%. Comparing base (8004643) to head (4abe440).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7681      +/-   ##
==========================================
+ Coverage   74.00%   74.03%   +0.02%     
==========================================
  Files        2918     2920       +2     
  Lines      151252   151490     +238     
  Branches    17576    17618      +42     
==========================================
+ Hits       111936   112152     +216     
- Misses      33464    33485      +21     
- Partials     5852     5853       +1     
Flag Coverage Δ
unittests 74.03% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tobias-tengler tobias-tengler force-pushed the tte/hotchocolate-semantic-non-null branch from 6a2d95e to 7344282 Compare November 13, 2024 20:52
@tobias-tengler tobias-tengler force-pushed the tte/hotchocolate-semantic-non-null branch from 7344282 to 83e7547 Compare November 13, 2024 20:52
@tobias-tengler tobias-tengler changed the title [WIP] @semanticNonNull support @semanticNonNull support Nov 14, 2024
@tobias-tengler tobias-tengler marked this pull request as ready for review November 14, 2024 21:32
@tobias-tengler tobias-tengler force-pushed the tte/hotchocolate-semantic-non-null branch from c86300f to aca4e59 Compare November 14, 2024 21:33
@tobias-tengler tobias-tengler added the 👓 ready-for-review The PR is ready for review. label Nov 14, 2024
Comment on lines +938 to +944
public string[] PureScalarListItemThrowingError(IResolverContext context)
{
// TODO: How can you create a terminating error for a single item?
context.ReportError(ErrorBuilder.New().SetMessage("Another error").SetPath(context.Path.Append(1)).Build());
return ["a", null!, "c"];
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Does someone have an idea?

@tobias-tengler tobias-tengler force-pushed the tte/hotchocolate-semantic-non-null branch from aca4e59 to 20a18cb Compare November 14, 2024 21:49
@michaelstaib michaelstaib merged commit 2c085bc into main Nov 17, 2024
2 checks passed
@michaelstaib michaelstaib deleted the tte/hotchocolate-semantic-non-null branch November 17, 2024 21:40
michaelstaib pushed a commit that referenced this pull request Nov 19, 2024
@tobias-tengler tobias-tengler added the 🍒 cherry-pick Consider cherry-picking these changes into the previous major version. label Nov 27, 2024
tobias-tengler added a commit that referenced this pull request Nov 28, 2024
michaelstaib pushed a commit that referenced this pull request Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 cherry-pick Consider cherry-picking these changes into the previous major version. 🌶️ hot chocolate 👓 ready-for-review The PR is ready for review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants