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

Only root fields of subscriptions should set StreamResolver; only object output types should set Resolver #3574

Merged
merged 10 commits into from Apr 6, 2023

Conversation

sungam3r
Copy link
Member

@sungam3r sungam3r commented Apr 4, 2023

fixes #2994
also fixes #1176

@Shane32 I suggest to consider this as a "fix" for #1176. I do not believe that we will split FieldType for inputs and outputs or redesign API in some other way. At least I'm sure that it will be opened for years without any progress. Schema validation allows to find all invalid usages during initialization, i.e. early thought in runtime, not at compile time, so I think this is a good compromise and we do not need to break the whole design.

@github-actions github-actions bot added the test Pull request that adds new or changes existing tests label Apr 4, 2023
@sungam3r
Copy link
Member Author

sungam3r commented Apr 4, 2023

@Shane32 I need your help with grammar in messages.

@sungam3r sungam3r added the enhancement New feature or request label Apr 4, 2023
@@ -63,6 +63,9 @@
throw new InvalidOperationException($"The field '{field.Name}' of an Object type '{type.Name}' must be an output type.");

ValidateFieldArgumentsUniqueness(field, type);

if (field.StreamResolver != null && type != schema.Subscription)

Check warning

Code scanning / CodeQL

Reference equality test on System.Object Warning

Reference equality for System.Object comparisons (
this
argument has type IObjectGraphType).
@sungam3r sungam3r changed the title Only root fields of subscriptions should set StreamResolver; only output types should set Resolver Only root fields of subscriptions should set StreamResolver; only object output types should set Resolver Apr 6, 2023
@sungam3r sungam3r requested a review from Shane32 April 6, 2023 16:33
@sungam3r sungam3r self-assigned this Apr 6, 2023
@Shane32
Copy link
Member

Shane32 commented Apr 6, 2023

Do we have schema validation tests to ensure that StreamResolver IS set for the Schema.Subscription graph type?

@Shane32
Copy link
Member

Shane32 commented Apr 6, 2023

I really like this PR. But, is it a breaking PR? It would seem so; notice the changes necessary to our own StarWars sample.

@sungam3r
Copy link
Member Author

sungam3r commented Apr 6, 2023

But, is it a breaking PR? It would seem so; notice the changes necessary to our own StarWars sample.

I removed some resolvers to make it work. Does not it mean that changes are indeed breaking?

@Shane32
Copy link
Member

Shane32 commented Apr 6, 2023

For v8, I would also like to require that Resolver is null when StreamResolver is not null. This would certainly be a breaking change, but it should clarify behavior, as implementing a field resolver on top of a stream resolver is not intuitive and introduces unnecessary complexity. Moreover, if a mapping was needed from the IObservable type to the resolved type, a simple .Select (via System.Reactive extensions) allows for nearly identical behavior.

@sungam3r
Copy link
Member Author

sungam3r commented Apr 6, 2023

Do we have schema validation tests to ensure that StreamResolver IS set for the Schema.Subscription graph type?

No. I can add it in new PR, don't want to mix one more check.

@Shane32
Copy link
Member

Shane32 commented Apr 6, 2023

But, is it a breaking PR? It would seem so; notice the changes necessary to our own StarWars sample.

I removed some resolvers to make it work. Does not it mean that changes are indeed breaking?

Well, technically, I would say it is indeed breaking, as setting certain resolvers now throws an exception whereas before they were simply ignored. That's not always a bad thing though. So:

I'm not worried about the fact that stream resolvers must not be set for non-root-subscription graph types. This should not occur in user code; it would be a 'bug' if it were so.

It seems to me that having resolvers for interface types MAY be common practice. I do not know. It is clear that they should not be used/necessary with a properly configured schema. I have demonstrated in the past how they could be usefully used, although it does break GraphQL spec. It is also possible or perhaps likely that dynamically-built schemas would set these resolvers for interfaces, assuming they would be ignored, just as AutoRegisteringInterfaceGraphType did. This is the part that bothers me about introducing this PR to 7.4.

So, we have a few options:

  1. Delay this PR to v8
  2. Disable the interface type checks until v8
  3. Add global flag to disable interface checks (and remove flag for v8)
  4. Merge whole PR for v7.4

I'm really not sure what I would choose. Probably option 2, but options 3 and 4 also has merit. Your thoughts?

@Shane32
Copy link
Member

Shane32 commented Apr 6, 2023

Do we have schema validation tests to ensure that StreamResolver IS set for the Schema.Subscription graph type?

No. I can add it in new PR, don't want to mix one more check.

Sounds good. If this were not the case, the schema would be improperly configured, so this is not a breaking change.

@sungam3r
Copy link
Member Author

sungam3r commented Apr 6, 2023

I prefer option 4 - merge as is and wait for feedback. If anyone will be affected, then push changes for option 3 in v7.5+

Co-authored-by: Shane Krueger <shane@acdmail.com>
@codecov-commenter
Copy link

Codecov Report

Merging #3574 (cd76943) into master (6b914db) will increase coverage by 0.06%.
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    #3574      +/-   ##
==========================================
+ Coverage   83.82%   83.89%   +0.06%     
==========================================
  Files         381      381              
  Lines       16875    16884       +9     
  Branches     2704     2710       +6     
==========================================
+ Hits        14146    14164      +18     
+ Misses       2084     2073      -11     
- Partials      645      647       +2     
Impacted Files Coverage Δ
src/GraphQL/Types/Fields/FieldType.cs 100.00% <ø> (ø)
src/GraphQL/Types/Collections/SchemaTypes.cs 85.43% <100.00%> (ø)
...hQL/Types/Composite/AutoRegisteringOutputHelper.cs 98.44% <100.00%> (-0.03%) ⬇️
src/GraphQL/Types/Composite/ComplexGraphType.cs 51.90% <100.00%> (+0.18%) ⬆️
...phQL/Utilities/Visitors/SchemaValidationVisitor.cs 72.22% <100.00%> (+1.63%) ⬆️

... and 2 files with indirect coverage changes

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

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
3 participants