Skip to content

feat: add SubscriptionOnCreate hook#1538

Open
dkorittki wants to merge 7 commits into
masterfrom
dominik/new_subscriptionOnTrigger_hook
Open

feat: add SubscriptionOnCreate hook#1538
dkorittki wants to merge 7 commits into
masterfrom
dominik/new_subscriptionOnTrigger_hook

Conversation

@dkorittki

@dkorittki dkorittki commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Adds a new hook SubscriptionOnCreate. That hook is part of the new interface HookablePubsubDatasource.
This interface extends HookableSubscriptionDataSource and is meant to be implemented by Cosmo Streams (pubsub) datasources only. It means that in comparison with the SubscriptionOnStart hook, SubscriptionOnCreate is only called for Cosmo Streams datasources, not for normal subscription datasources.

The hook is meant to modify subscription event data. The corresponding router pull request highlights the usecase wundergraph/cosmo#2972.

The changes here are meant to be backwards compatible. No breaking API changes are introduced. The routers pubsub datasource still implement HookableSubscriptionDataSource and that works the same as before. In order to make use of the new hook it needs to implement HookablePubsubDatasource.

@coderabbitai summary

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.

Open Source AI Manifesto

This project follows the principles of the Open Source AI Manifesto. Please ensure your contribution aligns with its principles.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A new HookablePubsubDatasource interface extending HookableSubscriptionDataSource is added with a SubscriptionOnCreate method. Both ResolveGraphQLSubscription and AsyncResolveGraphQLSubscription now type-assert this interface and invoke SubscriptionOnCreate to transform subscription input before prepareTrigger; errors produce an immediate error response. Tests add a fake pubsub stream type and subtests for all hook behaviors.

Changes

HookablePubsubDatasource SubscriptionOnCreate Hook

Layer / File(s) Summary
HookablePubsubDatasource interface and resolve integration
v2/pkg/engine/resolve/datasource.go, v2/pkg/engine/resolve/resolve.go
Defines the HookablePubsubDatasource interface extending HookableSubscriptionDataSource with SubscriptionOnCreate(ctx, input) (newInput, err). Both ResolveGraphQLSubscription and AsyncResolveGraphQLSubscription type-assert the datasource, call the hook to rewrite input before prepareTrigger, and write a flush-complete error response on failure.
Fake pubsub stream and SubscriptionOnCreate subtests
v2/pkg/engine/resolve/resolve_test.go
Adds _fakePubsubStream embedding _fakeStream with an optional subscriptionOnCreateFn and a createFakePubsubStream constructor. New subtests cover hook invocation, input rewriting in async and sync paths, error propagation, shared-trigger merging, and failure isolation between co-subscribed streams.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • wundergraph/graphql-go-tools#1531: Modifies the same subscription trigger preparation pipeline in v2/pkg/engine/resolve, extends datasource interfaces, and propagates the identical "failed to prepare subscription trigger" error response pattern in resolve.go.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the new SubscriptionOnCreate hook, its purpose for Cosmo Streams datasources, backwards compatibility, and references related context.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title 'feat: add SubscriptionOnCreate hook' directly and clearly summarizes the main change—introducing a new hook interface for pubsub datasources.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dominik/new_subscriptionOnTrigger_hook

Comment @coderabbitai help to get the list of available commands and usage tips.

@dkorittki dkorittki marked this pull request as ready for review June 16, 2026 11:28
@dkorittki dkorittki requested a review from a team as a code owner June 16, 2026 11:28
@dkorittki

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@v2/pkg/engine/resolve/resolve_test.go`:
- Around line 6882-6884: Replace all instances of Context struct literal
construction with the NewContext() constructor function throughout the test
file. In v2/pkg/engine/resolve/resolve_test.go at lines 6882-6884 (anchor),
6915-6917, 6943-6945, 7055-7056, 7114-7115, and 7159-7160 (siblings), change
each occurrence of &Context{ctx: context.Background()} (or similar literal
construction) to NewContext(context.Background()) instead. After calling
NewContext(context.Background()), set only the required fields on the returned
Context object to ensure internal initialization invariants are preserved and
avoid brittle nil-field behavior as the resolver evolves.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2fe6af90-67f7-4a7a-9c35-9dcf41d7812c

📥 Commits

Reviewing files that changed from the base of the PR and between 6a5eb1a and 8f84e67.

📒 Files selected for processing (3)
  • v2/pkg/engine/resolve/datasource.go
  • v2/pkg/engine/resolve/resolve.go
  • v2/pkg/engine/resolve/resolve_test.go

Comment thread v2/pkg/engine/resolve/resolve_test.go Outdated
@alepane21 alepane21 changed the title feat: add SubscriptionBeforeTrigger hook feat: add SubscriptionOnCreate hook Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants