-
-
Notifications
You must be signed in to change notification settings - Fork 5
feat: GraphQL Subscriptions with WebSocket, SSE, and Auto Mode #57
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
Merged
Conversation
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
- Add WebSocket handlers for GraphQL Yoga and Apollo Server
- Implement graphql-ws protocol for real-time subscriptions
- Add SubscriptionsConfig type and endpoint configuration
- Auto-enable experimental websocket flag when subscriptions enabled
- Add playground examples with PubSub chat implementation
Usage:
```typescript
// nitro.config.ts
graphql: {
framework: 'graphql-yoga',
subscriptions: {
enabled: true,
},
}
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
…nnection parameters
…on state management
…port - Changed import paths for Vue composables in subscriptions.vue to use sdk.ts. - Enhanced subscribe-client.ts to support multiplexing with createSession() for shared connections. - Updated subscription client methods to return SubscriptionHandle instead of SubscriptionClient. - Added new useSubscriptionSession hook for managing multiplexed subscriptions. - Deprecated generateNuxtSubscriptionComposables function; noted that composables are now generated directly in sdk.ts. - Improved error handling and connection management in subscription logic.
…ment - Updated `useSubscriptionSession` to maintain reactivity by subscribing to session state changes. - Refactored multiplexing logic in `multiplexing-test.vue` to use a single session object for all composables. - Enhanced connection management in `subscribe-client.ts` with a Timer Manager for better handling of timeouts and intervals. - Introduced keep-alive functionality to maintain WebSocket connections. - Improved error handling and state notifications for subscriptions. - Added state change callbacks to `SubscriptionSession` for better reactivity. - Updated client code generation to include detailed JSDoc comments for subscription composables.
…prove code organization - Simplified the subscription client template for easier customization. - Reorganized imports and exports in subscription-related files for clarity. - Updated type generation to include subscription composables and external services. - Enhanced the tsdown configuration to include subscription-related files.
… SSE, and auto mode
…r for subscription data
…ated subscription composables generation
- Bump @antfu/eslint-config from ^6.3.0 to ^6.6.1 - Update @apollo/subgraph from ^2.12.1 to ^2.12.2 - Upgrade @nuxt/kit and @nuxt/schema from ^4.2.1 to ^4.2.2 - Update @types/node from ^24.10.1 to ^24.10.3 - Bump nuxt from ^4.2.1 to ^4.2.2 - Upgrade oxc-parser from ^0.101.0 to ^0.102.0 - Update tailwindcss from ^4.1.17 to ^4.1.18 - Bump tsdown from ^0.16.8 to ^0.17.2 - Update vue-router from ^4.6.3 to ^4.6.4
…dling in client type generation
Remove the `sse: boolean` property from TransportOptions interface to simplify the API. Users should now use `transport: 'sse'` instead. Changes: - Remove `sse` property from TransportOptions (subscribe/index.ts) - Simplify resolveTransport() function - Remove `sse` property from UseSubscriptionOptions (client-codegen.ts) - Update transportOptions object construction 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add changelog configuration (changelogithub.config.ts) - Simplify release workflow for changelog generation - Add security configuration types - Fix unused error parameter in apollo-server.ts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
…cations for various packages
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.
Summary
This PR adds real-time GraphQL subscription support to nitro-graphql with a unified, developer-friendly API that supports multiple transport mechanisms.
Key Features
graphql-transport-wsprotocolSession Multiplexing
Multiple subscriptions can share a single WebSocket connection, reducing resource usage:
Framework-agnostic API:
Usage Guide
1. Define Schema (
server/graphql/schema.graphql)2. Create Resolver (
server/graphql/subscriptions.resolver.ts)3. Define Client Query (
app/graphql/subscriptions/subscriptions.graphql)4. Use in Vue Component
Auto-Generated Config (
app/graphql/default/subscribe.ts)A
subscribe.tsfile is auto-generated once on first run. You can customize it for authentication, custom endpoints, or retry settings:Developer Experience
Before (SSE with boilerplate - 20+ lines):
After (same API as WebSocket - 1 line!):
Technical Details
Server-Side
src/routes/graphql-yoga-ws.ts,apollo-server-ws.ts)crosswsfor H3/Nitro WebSocket supportgraphql-transport-wsprotocolClient-Side
src/subscribe/index.ts)idle → connecting → connected → reconnecting → errorCode Generation
Files Changed
src/subscribe/index.ts,src/routes/*-ws.tssrc/utils/client-codegen.tssrc/types/index.tssrc/templates/subscribe-client.tsplaygrounds/nuxt/*,playgrounds/nitro/*Test Plan
{ transport: 'sse' }optionsubscribe.tsis generated only once (customizations preserved)🤖 Generated with Claude Code