@envelop/execute-subscription-event 8.1.1 → 8.2.0

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.
package/LICENSE CHANGED
@@ -1,6 +1,8 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Dotan Simha
3
+ Copyright (c) 2018-2020 Graphcool
4
+ Copyright (c) 2020-2021 Prisma
5
+ Copyright (c) 2021- The Guild
4
6
 
5
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
8
  of this software and associated documentation files (the "Software"), to deal
package/cjs/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useExtendContextValuePerExecuteSubscriptionEvent = void 0;
4
+ // eslint-disable-next-line no-restricted-imports
4
5
  const graphql_1 = require("graphql");
5
6
  const core_1 = require("@envelop/core");
6
7
  const promise_helpers_1 = require("@whatwg-node/promise-helpers");
package/cjs/subscribe.js CHANGED
@@ -1,15 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.subscribe = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const graphql_1 = require("graphql");
5
6
  const core_1 = require("@envelop/core");
6
7
  const promise_helpers_1 = require("@whatwg-node/promise-helpers");
8
+ const validateSubscriptionArgsPromise = Promise.resolve().then(() => tslib_1.__importStar(require('graphql'))).then(graphqlModule => graphqlModule
9
+ .validateSubscriptionArgs);
10
+ function getSourceEventStream(args, validateSubscriptionArgs) {
11
+ if (validateSubscriptionArgs) {
12
+ const validatedArgs = validateSubscriptionArgs(args);
13
+ if (!('schema' in validatedArgs)) {
14
+ return { errors: validatedArgs };
15
+ }
16
+ // Cast away the installed graphql version's own overloads here for backwards compatability
17
+ const createSourceEventStreamWithValidatedArgs = graphql_1.createSourceEventStream;
18
+ return createSourceEventStreamWithValidatedArgs(validatedArgs);
19
+ }
20
+ const legacyCreateSourceEventStream = graphql_1.createSourceEventStream;
21
+ return legacyCreateSourceEventStream(args.schema, args.document, args.rootValue, args.contextValue, args.variableValues ?? undefined, args.operationName, args.subscribeFieldResolver);
22
+ }
7
23
  /**
8
24
  * This is a almost identical port from graphql-js subscribe.
9
25
  * The only difference is that a custom `execute` function can be injected for customizing the behavior.
10
26
  */
11
- const subscribe = (execute) => (0, core_1.makeSubscribe)(({ schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver, }) => {
12
- return (0, promise_helpers_1.handleMaybePromise)(() => (0, graphql_1.createSourceEventStream)(schema, document, rootValue, contextValue, variableValues ?? undefined, operationName, subscribeFieldResolver), resultOrStream => {
27
+ const subscribe = (execute) => (0, core_1.makeSubscribe)(args => {
28
+ const { schema, document, contextValue, variableValues, operationName, fieldResolver } = args;
29
+ return (0, promise_helpers_1.handleMaybePromise)(() => validateSubscriptionArgsPromise, (validateSubscriptionArgs) => (0, promise_helpers_1.handleMaybePromise)(() => getSourceEventStream(args, validateSubscriptionArgs), (resultOrStream) => {
13
30
  if (!(0, core_1.isAsyncIterable)(resultOrStream)) {
14
31
  return resultOrStream;
15
32
  }
@@ -30,6 +47,6 @@ const subscribe = (execute) => (0, core_1.makeSubscribe)(({ schema, document, ro
30
47
  operationName,
31
48
  fieldResolver,
32
49
  }));
33
- });
50
+ }));
34
51
  });
35
52
  exports.subscribe = subscribe;
package/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ // eslint-disable-next-line no-restricted-imports
1
2
  import { execute } from 'graphql';
2
3
  import { makeExecute } from '@envelop/core';
3
4
  import { handleMaybePromise } from '@whatwg-node/promise-helpers';
package/esm/subscribe.js CHANGED
@@ -1,12 +1,28 @@
1
1
  import { createSourceEventStream } from 'graphql';
2
- import { isAsyncIterable, makeSubscribe, mapAsyncIterator, } from '@envelop/core';
2
+ import { isAsyncIterable, makeSubscribe, mapAsyncIterator } from '@envelop/core';
3
3
  import { handleMaybePromise } from '@whatwg-node/promise-helpers';
4
+ const validateSubscriptionArgsPromise = import('graphql').then(graphqlModule => graphqlModule
5
+ .validateSubscriptionArgs);
6
+ function getSourceEventStream(args, validateSubscriptionArgs) {
7
+ if (validateSubscriptionArgs) {
8
+ const validatedArgs = validateSubscriptionArgs(args);
9
+ if (!('schema' in validatedArgs)) {
10
+ return { errors: validatedArgs };
11
+ }
12
+ // Cast away the installed graphql version's own overloads here for backwards compatability
13
+ const createSourceEventStreamWithValidatedArgs = createSourceEventStream;
14
+ return createSourceEventStreamWithValidatedArgs(validatedArgs);
15
+ }
16
+ const legacyCreateSourceEventStream = createSourceEventStream;
17
+ return legacyCreateSourceEventStream(args.schema, args.document, args.rootValue, args.contextValue, args.variableValues ?? undefined, args.operationName, args.subscribeFieldResolver);
18
+ }
4
19
  /**
5
20
  * This is a almost identical port from graphql-js subscribe.
6
21
  * The only difference is that a custom `execute` function can be injected for customizing the behavior.
7
22
  */
8
- export const subscribe = (execute) => makeSubscribe(({ schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver, }) => {
9
- return handleMaybePromise(() => createSourceEventStream(schema, document, rootValue, contextValue, variableValues ?? undefined, operationName, subscribeFieldResolver), resultOrStream => {
23
+ export const subscribe = (execute) => makeSubscribe(args => {
24
+ const { schema, document, contextValue, variableValues, operationName, fieldResolver } = args;
25
+ return handleMaybePromise(() => validateSubscriptionArgsPromise, (validateSubscriptionArgs) => handleMaybePromise(() => getSourceEventStream(args, validateSubscriptionArgs), (resultOrStream) => {
10
26
  if (!isAsyncIterable(resultOrStream)) {
11
27
  return resultOrStream;
12
28
  }
@@ -27,5 +43,5 @@ export const subscribe = (execute) => makeSubscribe(({ schema, document, rootVal
27
43
  operationName,
28
44
  fieldResolver,
29
45
  }));
30
- });
46
+ }));
31
47
  });
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@envelop/execute-subscription-event",
3
- "version": "8.1.1",
3
+ "version": "8.2.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
7
- "@envelop/core": "^5.5.1"
6
+ "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0",
7
+ "@envelop/core": "^5.6.0"
8
8
  },
9
9
  "dependencies": {
10
10
  "@whatwg-node/promise-helpers": "^1.2.1",
@@ -12,8 +12,8 @@
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "https://github.com/graphql-hive/envelop.git",
16
- "directory": "packages/plugins/execute-subscription-event"
15
+ "url": "https://github.com/graphql-hive/graphql-yoga.git",
16
+ "directory": "packages/envelop/plugins/execute-subscription-event"
17
17
  },
18
18
  "author": "Laurin Quast <laurinquast@googlemail.com>",
19
19
  "license": "MIT",
@@ -1,8 +1,8 @@
1
- import { SubscriptionArgs } from 'graphql';
2
- import { DefaultContext, Plugin, PromiseOrValue } from '@envelop/core';
1
+ import type { ExecutionArgs } from 'graphql';
2
+ import type { DefaultContext, Plugin, PromiseOrValue } from '@envelop/core';
3
3
  export type ContextFactoryOptions = {
4
4
  /** The arguments with which the subscription was set up. */
5
- args: SubscriptionArgs;
5
+ args: ExecutionArgs;
6
6
  };
7
7
  export type ContextFactoryHook<TContextValue> = {
8
8
  /** Context that will be used for the "ExecuteSubscriptionEvent" phase. */
@@ -1,8 +1,8 @@
1
- import { SubscriptionArgs } from 'graphql';
2
- import { DefaultContext, Plugin, PromiseOrValue } from '@envelop/core';
1
+ import type { ExecutionArgs } from 'graphql';
2
+ import type { DefaultContext, Plugin, PromiseOrValue } from '@envelop/core';
3
3
  export type ContextFactoryOptions = {
4
4
  /** The arguments with which the subscription was set up. */
5
- args: SubscriptionArgs;
5
+ args: ExecutionArgs;
6
6
  };
7
7
  export type ContextFactoryHook<TContextValue> = {
8
8
  /** Context that will be used for the "ExecuteSubscriptionEvent" phase. */
@@ -1,4 +1,4 @@
1
- import { ExecuteFunction, SubscribeFunction } from '@envelop/core';
1
+ import type { ExecuteFunction, SubscribeFunction } from '@envelop/core';
2
2
  /**
3
3
  * This is a almost identical port from graphql-js subscribe.
4
4
  * The only difference is that a custom `execute` function can be injected for customizing the behavior.
@@ -1,4 +1,4 @@
1
- import { ExecuteFunction, SubscribeFunction } from '@envelop/core';
1
+ import type { ExecuteFunction, SubscribeFunction } from '@envelop/core';
2
2
  /**
3
3
  * This is a almost identical port from graphql-js subscribe.
4
4
  * The only difference is that a custom `execute` function can be injected for customizing the behavior.