Skip to content

Commit

Permalink
Allow introspecting onSubscribe from app level. (#952)
Browse files Browse the repository at this point in the history
* allow introspecting onSubscribe from app level

* add changeset

* fix type error

* address feedback
  • Loading branch information
Raynos committed May 1, 2023
1 parent 9b5eb5c commit 36e7c9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-hairs-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-ez/plugin-websockets': patch
---

allow introspecting onSubscribe from app level
19 changes: 14 additions & 5 deletions packages/plugin/websockets/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ export type FilteredSubscriptionsTransportOptions = Omit<
'schema' | 'execute' | 'subscribe' | 'onConnect' | 'validate' | 'parse'
>;

export type FilteredGraphQLWSOptions = Omit<
GraphQLWSOptions,
'schema' | 'execute' | 'subscribe' | 'context' | 'validate' | 'onSubscribe'
>;
export type FilteredGraphQLWSOptions = Omit<GraphQLWSOptions, 'schema' | 'execute' | 'subscribe' | 'context' | 'validate'>;

export interface WebSocketsState {
closing: boolean;
Expand Down Expand Up @@ -88,7 +85,19 @@ export function handleGraphQLWS(
...cleanObject(options),
execute,
subscribe,
async onSubscribe({ connectionParams, extra: { request, socket } }, { payload: { operationName, query, variables } }) {
async onSubscribe(context, message) {
const {
connectionParams,
extra: { request, socket },
} = context;
const {
payload: { operationName, query, variables },
} = message;

if (typeof options?.onSubscribe === 'function') {
options.onSubscribe(context, message);
}

const contextArgsData = {
req: request,
ws: {
Expand Down

1 comment on commit 36e7c9e

@vercel
Copy link

@vercel vercel bot commented on 36e7c9e May 1, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.