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

Schema builder fixes; add schema validation of subscription fields #3867

Merged
merged 4 commits into from
Jan 2, 2024

Conversation

Shane32
Copy link
Member

@Shane32 Shane32 commented Jan 1, 2024

Fixes #3580

Adds schema validation to ensure that StreamResolver is set for fields of root subscription types. This is a non-breaking change because without the validation, attempting to resolve these fields would fail at runtime.

Trying to write a fix for #3580 I found two bugs in the schema-first SchemaBuilder (as far as I can tell).

  • Include does not include configurations via ForAll
  • Subscriptions don't work properly when the schema definition is listed after the subscription definition

@Shane32 Shane32 self-assigned this Jan 1, 2024
@@ -111,14 +111,19 @@ private Schema BuildSchemaFrom(GraphQLDocument document)

var directives = new List<Directive>();

// process the schema definition first
foreach (var def in document.Definitions)
{
if (def is GraphQLSchemaDefinition schemaDef)
{
_schemaDef = schemaDef;
Copy link
Member Author

@Shane32 Shane32 Jan 1, 2024

Choose a reason for hiding this comment

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

_schemaDef must be set first or subscription resolvers don't get set properly. Who knows; maybe it affects more stuff.

@@ -74,7 +74,7 @@ public void Include(Type type)
/// </summary>
public void Include(string name, Type type)
{
_typeConfigurations[name].Type = type;
For(name).Type = type;
Copy link
Member Author

Choose a reason for hiding this comment

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

ForAll only triggers when using For, but seems to clearly indicate that it should operate on all types. So I've changed Include to call For and thereby execute any configured ForAll code.

@Shane32 Shane32 changed the title Schema builder fixes Schema builder fixes; add schema validation of subscription fields Jan 1, 2024
@Shane32 Shane32 added this to the 7.8 milestone Jan 1, 2024
@Shane32 Shane32 requested a review from gao-artur January 1, 2024 02:08
@Shane32 Shane32 added enhancement New feature or request bugfix Pull request that fixes a bug labels Jan 1, 2024
@Shane32 Shane32 requested a review from gao-artur January 2, 2024 06:40
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (911afe8) 84.66% compared to head (bedfc07) 84.66%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3867      +/-   ##
==========================================
- Coverage   84.66%   84.66%   -0.01%     
==========================================
  Files         419      419              
  Lines       19333    19344      +11     
  Branches     3033     3037       +4     
==========================================
+ Hits        16369    16377       +8     
- Misses       2251     2253       +2     
- Partials      713      714       +1     

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

@Shane32 Shane32 merged commit b9a113e into master Jan 2, 2024
10 checks passed
@Shane32 Shane32 deleted the schema_builder_fixes branch January 2, 2024 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Pull request that fixes a bug enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure that StreamResolver IS set for the Schema.Subscription graph type
3 participants