Honor [Subscribe(With = ...)] in source-generated subscriptions#9702
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds source generator support for the [Subscribe(With = nameof(...))] attribute on subscription resolvers, ensuring (1) the referenced stream-producing sibling method is excluded from being exposed as its own GraphQL field, and (2) the generated configuration sets SubscribeWith/SourceType so the runtime invokes the correct event stream.
Changes:
WellKnownAttributes: addedSubscribeAttributeconstant.ObjectTypeInspector: pre-scans members for[Subscribe(With = ...)], builds a name set/lookup, skips referenced sibling methods, and propagatessubscribeWithinto the resolver model.Resolvermodel +TypeFileBuilderBase: addedSubscribeWithand emitconfiguration.SubscribeWith/configuration.SourceTypewhen present.- Tests/snapshots: new generator and integration tests covering the subscribe-with behavior, ignored-method suppression, and live subscription delivery.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Core/src/Types.Analyzers/WellKnownAttributes.cs | Adds the SubscribeAttribute constant. |
| src/HotChocolate/Core/src/Types.Analyzers/Models/Resolver.cs | Adds SubscribeWith property and constructor parameter, threaded through WithSchemaTypeName. |
| src/HotChocolate/Core/src/Types.Analyzers/Inspectors/ObjectTypeInspector.cs | Collects [Subscribe(With=...)] references, suppresses the referenced sibling methods as fields, and forwards the value to CreateResolver. |
| src/HotChocolate/Core/src/Types.Analyzers/FileBuilders/TypeFileBuilderBase.cs | Emits configuration.SubscribeWith and configuration.SourceType when the resolver has a subscribe-with target. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/OperationTests.cs | Adds two generator tests for Subscribe-with and [GraphQLIgnore] interaction. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/OperationTests.Subscription_With_Subscribe_With_Excludes_Stream_Method.md | New snapshot showing generated subscription wiring. |
| src/HotChocolate/Core/test/Types.Analyzers.Tests/snapshots/OperationTests.Subscription_Ignored_Method_Does_Not_Suppress_Public_Resolver.md | New snapshot verifying ignored stub doesn't suppress sibling field. |
| src/HotChocolate/Core/test/Types.Analyzers.Integration.Tests/Subscription.cs | New integration subscription type exercising both private and public subscribe sources. |
| src/HotChocolate/Core/test/Types.Analyzers.Integration.Tests/IntegrationTests.cs | Adds runtime subscription test and field-exposure test. |
| src/HotChocolate/Core/test/Types.Analyzers.Integration.Tests/snapshots/IntegrationTests.Schema_Snapshot.snap | Updates schema snapshot to include the new Subscription type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.