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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

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 ])

Copy link

codecov bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.04%. Comparing base (8004643) to head (fad06a2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7681      +/-   ##
==========================================
+ Coverage   74.00%   74.04%   +0.03%     
==========================================
  Files        2918     2920       +2     
  Lines      151252   151494     +242     
  Branches    17576    17619      +43     
==========================================
+ Hits       111936   112167     +231     
- Misses      33464    33472       +8     
- Partials     5852     5855       +3     
Flag Coverage Δ
unittests 74.04% <ø> (+0.03%) ⬆️

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants