@graphql-yoga/plugin-graphql-sse 3.13.0 → 3.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/cjs/index.js +16 -14
  2. package/esm/index.js +16 -14
  3. package/package.json +2 -1
package/cjs/index.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useGraphQLSSE = useGraphQLSSE;
4
4
  const graphql_1 = require("graphql");
5
5
  const fetch_1 = require("graphql-sse/lib/use/fetch");
6
+ const promise_helpers_1 = require("@whatwg-node/promise-helpers");
6
7
  /**
7
8
  * Get [GraphQL over Server-Sent Events Protocol](https://github.com/enisdenjo/graphql-sse/blob/master/PROTOCOL.md) integration with GraphQL Yoga by simply installing this plugin!
8
9
  *
@@ -17,7 +18,7 @@ function useGraphQLSSE(options = {}) {
17
18
  onYogaInit({ yoga }) {
18
19
  handler = (0, fetch_1.createHandler)({
19
20
  ...handlerOptions,
20
- async onSubscribe(req, params) {
21
+ onSubscribe(req, params) {
21
22
  const enveloped = yoga.getEnveloped({
22
23
  ...ctxForReq.get(req.raw),
23
24
  request: req.raw,
@@ -28,25 +29,26 @@ function useGraphQLSSE(options = {}) {
28
29
  if (errors.length > 0) {
29
30
  return { errors };
30
31
  }
31
- const contextValue = await enveloped.contextFactory();
32
- const executionArgs = {
33
- schema: enveloped.schema,
34
- document,
35
- contextValue,
36
- variableValues: params.variables,
37
- operationName: params.operationName,
38
- };
39
- const operation = (0, graphql_1.getOperationAST)(document, params.operationName);
40
- const executeFn = operation?.operation === 'subscription' ? enveloped.subscribe : enveloped.execute;
41
- return executeFn(executionArgs);
32
+ return (0, promise_helpers_1.handleMaybePromise)(() => enveloped.contextFactory(), contextValue => {
33
+ const executionArgs = {
34
+ schema: enveloped.schema,
35
+ document,
36
+ contextValue,
37
+ variableValues: params.variables,
38
+ operationName: params.operationName,
39
+ };
40
+ const operation = (0, graphql_1.getOperationAST)(document, params.operationName);
41
+ const executeFn = operation?.operation === 'subscription' ? enveloped.subscribe : enveloped.execute;
42
+ return executeFn(executionArgs);
43
+ });
42
44
  },
43
45
  }, yoga.fetchAPI);
44
46
  },
45
- async onRequest({ request, endResponse, serverContext }) {
47
+ onRequest({ request, endResponse, serverContext }) {
46
48
  const [path, _search] = request.url.split('?');
47
49
  if (path?.endsWith(endpoint)) {
48
50
  ctxForReq.set(request, serverContext);
49
- endResponse(await handler(request));
51
+ return (0, promise_helpers_1.handleMaybePromise)(() => handler(request), endResponse);
50
52
  }
51
53
  },
52
54
  };
package/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { getOperationAST } from 'graphql';
2
2
  import { createHandler } from 'graphql-sse/lib/use/fetch';
3
+ import { handleMaybePromise } from '@whatwg-node/promise-helpers';
3
4
  /**
4
5
  * Get [GraphQL over Server-Sent Events Protocol](https://github.com/enisdenjo/graphql-sse/blob/master/PROTOCOL.md) integration with GraphQL Yoga by simply installing this plugin!
5
6
  *
@@ -14,7 +15,7 @@ export function useGraphQLSSE(options = {}) {
14
15
  onYogaInit({ yoga }) {
15
16
  handler = createHandler({
16
17
  ...handlerOptions,
17
- async onSubscribe(req, params) {
18
+ onSubscribe(req, params) {
18
19
  const enveloped = yoga.getEnveloped({
19
20
  ...ctxForReq.get(req.raw),
20
21
  request: req.raw,
@@ -25,25 +26,26 @@ export function useGraphQLSSE(options = {}) {
25
26
  if (errors.length > 0) {
26
27
  return { errors };
27
28
  }
28
- const contextValue = await enveloped.contextFactory();
29
- const executionArgs = {
30
- schema: enveloped.schema,
31
- document,
32
- contextValue,
33
- variableValues: params.variables,
34
- operationName: params.operationName,
35
- };
36
- const operation = getOperationAST(document, params.operationName);
37
- const executeFn = operation?.operation === 'subscription' ? enveloped.subscribe : enveloped.execute;
38
- return executeFn(executionArgs);
29
+ return handleMaybePromise(() => enveloped.contextFactory(), contextValue => {
30
+ const executionArgs = {
31
+ schema: enveloped.schema,
32
+ document,
33
+ contextValue,
34
+ variableValues: params.variables,
35
+ operationName: params.operationName,
36
+ };
37
+ const operation = getOperationAST(document, params.operationName);
38
+ const executeFn = operation?.operation === 'subscription' ? enveloped.subscribe : enveloped.execute;
39
+ return executeFn(executionArgs);
40
+ });
39
41
  },
40
42
  }, yoga.fetchAPI);
41
43
  },
42
- async onRequest({ request, endResponse, serverContext }) {
44
+ onRequest({ request, endResponse, serverContext }) {
43
45
  const [path, _search] = request.url.split('?');
44
46
  if (path?.endsWith(endpoint)) {
45
47
  ctxForReq.set(request, serverContext);
46
- endResponse(await handler(request));
48
+ return handleMaybePromise(() => handler(request), endResponse);
47
49
  }
48
50
  },
49
51
  };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@graphql-yoga/plugin-graphql-sse",
3
- "version": "3.13.0",
3
+ "version": "3.13.1",
4
4
  "description": "GraphQL over Server-Sent Events Protocol plugin for GraphQL Yoga.",
5
5
  "peerDependencies": {
6
6
  "graphql": "^15.2.0 || ^16.0.0",
7
7
  "graphql-yoga": "^5.13.0"
8
8
  },
9
9
  "dependencies": {
10
+ "@whatwg-node/promise-helpers": "^1.2.4",
10
11
  "graphql-sse": "^2.0.0"
11
12
  },
12
13
  "repository": {