Add entity-scoped GraphQL subscription support#3548
Conversation
Agent-Logs-Url: https://github.com/Azure/data-api-builder/sessions/be163e20-1dae-4692-a489-fb69ebe6e927 Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/data-api-builder/sessions/be163e20-1dae-4692-a489-fb69ebe6e927 Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/data-api-builder/sessions/be163e20-1dae-4692-a489-fb69ebe6e927 Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/data-api-builder/sessions/be163e20-1dae-4692-a489-fb69ebe6e927 Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds entity-scoped GraphQL subscription support to DAB (schema generation + in-process Hot Chocolate WebSocket subscriptions) and publishes DAB-originated write events from GraphQL/REST paths, with config/CLI/schema updates and unit tests.
Changes:
- Introduces per-entity GraphQL subscription configuration (
graphql.subscription.enabled/graphql.subscription.events) across config object model, CLI, and JSON schema validation. - Generates GraphQL
Subscriptionfields and event payload types conditionally (based on configured events + role write permissions). - Publishes
created/updated/deletedevents from mutation paths and tracks active subscriptions via metrics/telemetry.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Service/Startup.cs | Registers subscription publisher, enables Hot Chocolate in-memory subscriptions, and enables WebSockets middleware. |
| src/Service/Azure.DataApiBuilder.Service.csproj | Adds HotChocolate in-memory subscriptions package reference. |
| src/Service.Tests/UnitTests/SerializationDeserializationTests.cs | Adds config merge/deserialization coverage for entity subscription options. |
| src/Service.Tests/UnitTests/GraphQLSubscriptionEventTests.cs | Adds unit tests for extracting per-record publish payloads from mutation results. |
| src/Service.Tests/GraphQLBuilder/SubscriptionBuilderTests.cs | Adds tests for subscription SDL generation and permission-based field omission. |
| src/Service.GraphQLBuilder/Subscriptions/SubscriptionBuilder.cs | Implements subscription SDL generation (event interface, event types, subscription fields). |
| src/Directory.Packages.props | Central package version for HotChocolate.Subscriptions.InMemory. |
| src/Core/Telemetry/TelemetryMetricsHelper.cs | Adds an active GraphQL subscriptions UpDownCounter metric. |
| src/Core/Services/ResolverTypeInterceptor.cs | Wires subscription resolvers and adds special pure-resolver handling for event payload types. |
| src/Core/Services/GraphQLSubscriptionEventPublisher.cs | Adds event publish/subscribe abstraction using Hot Chocolate topics + telemetry/logging. |
| src/Core/Services/GraphQLSchemaCreator.cs | Adds subscription document generation and injects publisher/logger into ExecutionHelper. |
| src/Core/Services/ExecutionHelper.cs | Adds subscription subscribe resolver, event payload resolvers, and subscription metric tracking. |
| src/Core/Resolvers/SqlMutationEngine.cs | Publishes subscription events after successful mutations (GraphQL + REST paths). |
| src/Core/Resolvers/Factories/MutationEngineFactory.cs | Injects subscription publisher into mutation engines. |
| src/Core/Configurations/RuntimeConfigValidator.cs | Warns when subscriptions are enabled but no events are configured. |
| src/Core/Azure.DataApiBuilder.Core.csproj | Adds HotChocolate in-memory subscriptions package reference. |
| src/Config/ObjectModel/GraphQLSubscriptionEvent.cs | Adds enum for supported subscription event kinds. |
| src/Config/ObjectModel/EntityGraphQLSubscriptionOptions.cs | Adds per-entity subscription options model. |
| src/Config/ObjectModel/EntityGraphQLOptions.cs | Extends entity GraphQL options to include subscription settings. |
| src/Config/Converters/EntityGraphQLOptionsConverterFactory.cs | Adds (de)serialization support for graphql.subscription in entity config. |
| src/Cli/ConfigGenerator.cs | Adds CLI update support for entity subscription options. |
| src/Cli/Commands/EntityOptions.cs | Adds CLI flags for graphql.subscription.enabled and graphql.subscription.events. |
| schemas/dab.draft.schema.json | Adds JSON schema validation for entity GraphQL subscription configuration. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/Azure/data-api-builder/sessions/ca962dbd-4262-4080-8156-fa0941606d49 Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
The review thread feedback has been applied across ca6621d, c4df06b, and c309f8f, covering subscription/WebSocket gating, active metric ordering, key-only delete payloads, CLI validation, and explicit |
…ql-subscription-support # Conflicts: # src/Core/Services/GraphQLSchemaCreator.cs # src/Directory.Packages.props Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/data-api-builder/sessions/834d9860-e4c6-40a1-ade7-036da2ec3aa8 Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Merged latest |
|
@copilot apply changes based on the comments in this thread and then re-check the spec #3547 and ensure it is followed completely. |
Agent-Logs-Url: https://github.com/Azure/data-api-builder/sessions/8e0156c0-e054-43a8-9618-7fb46c5fcbf1 Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Applied the review-thread changes in 08fcdf7. Subscription event metadata fields now use the normal leaf resolver for scalar conversion, late-config/hot-reload scenarios use the real in-memory publisher and WebSocket middleware, and the active subscription metric name is aligned with existing metrics. I also re-checked #3547 after the changes and the implementation remains faithful to the spec. |
|
@copilot Merge the latest changes from main into this branch. |
…ql-subscription-support Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/data-api-builder/sessions/f26556e6-8663-437f-98c7-e84ee2ef9b76 Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Merged latest main in fc42130 and then completed a pedantic #3547 spec follow-up in 20bf2fe. The follow-up tightens WebSocket gating, telemetry, stored-procedure/Cosmos eligibility, schema defaults, and SQL publish semantics; build and targeted tests passed. |
Why make this change?
created,updated, anddeletedevents over the existing GraphQL endpoint. Subscriptions should stay invisible unless an entity configures subscription events, use process-local Hot Chocolate WebSockets, and publish only DAB-originated writes.What is this change?
Entity configuration + CLI
entities.<name>.graphql.subscription.enabledandentities.<name>.graphql.subscription.events.dab update <entity> --graphql.subscription.eventsand--graphql.subscription.enabled, with validation errors for invalid values.GraphQL schema
SubscriptionEventand entity event types only when entity events are configured and eligible.actorCreated,actorUpdated,actorDeleted.SubscriptionEventinterface as the explicit resolver marker for generated event payloads.mainHot Chocolate 16 stable updates.Runtime publishing
Telemetry
active_graphql_subscriptions.eventIdin payloads and publish telemetry.How was this tested?
Final CodeQL validation was attempted after the latest spec-follow-up changes, but the validation tool hit its time limit before completing.
Sample Request(s)