@envelop/execute-subscription-event 0.1.0 → 0.2.2-alpha-1e6c37b.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/README.md CHANGED
@@ -4,20 +4,48 @@ Utilities for hooking into the [ExecuteSubscriptionEvent](<https://spec.graphql.
4
4
 
5
5
  ### `useContextValuePerExecuteSubscriptionEvent`
6
6
 
7
- Create a new context object per `ExecuteSubscriptionEvent` phase, allowing to bypass common issues with context objects such as [`DataLoader` caching issues](https://github.com/dotansimha/envelop/issues/80).
7
+ Create a new context object per `ExecuteSubscriptionEvent` phase, allowing to bypass common issues with context objects such as [`DataLoader`](https://github.com/dotansimha/envelop/issues/80) [caching](https://github.com/graphql/graphql-js/issues/894) [issues](https://github.com/apollographql/subscriptions-transport-ws/issues/330).
8
8
 
9
9
  ```ts
10
10
  import { envelop } from '@envelop/core';
11
11
  import { useContextValuePerExecuteSubscriptionEvent } from '@envelop/execute-subscription-event';
12
+ import { createContext, createDataLoaders } from './context';
12
13
 
13
14
  const getEnveloped = envelop({
14
15
  plugins: [
16
+ useContext(() => createContext())
15
17
  useContextValuePerExecuteSubscriptionEvent(() => ({
16
- contextValue: {
17
- value: 'This context value is re-created every time the ExecuteSubscriptionEvent phase starts',
18
+ // Existing context is merged with this context partial
19
+ // By recreating the DataLoader we ensure no DataLoader caches from the previous event/initial field subscribe call are are hit
20
+ contextPartial: {
21
+ dataLoaders: createDataLoaders()
18
22
  },
19
23
  })),
20
24
  // ... other plugins ...
21
25
  ],
22
26
  });
23
27
  ```
28
+
29
+ Alternatively, you can also provide a callback that is invoked after each [`ExecuteSubscriptionEvent`](<https://spec.graphql.org/draft/#ExecuteSubscriptionEvent()>) phase.
30
+
31
+ ```ts
32
+ import { envelop } from '@envelop/core';
33
+ import { useContextValuePerExecuteSubscriptionEvent } from '@envelop/execute-subscription-event';
34
+ import { createContext, createDataLoaders } from './context';
35
+
36
+ const getEnveloped = envelop({
37
+ plugins: [
38
+ useContext(() => createContext())
39
+ useContextValuePerExecuteSubscriptionEvent(({ args }) => ({
40
+ onEnd: () => {
41
+ // Note that onEnd is invoked only after each ExecuteSubscriptionEvent phase
42
+ // This means the initial event will still use the cache from potential subscribe dataloader calls
43
+ // If you use this to clear DataLoader caches it is recommended to not do any DataLoader calls within your field subscribe function.
44
+ args.contextValue.dataLoaders.users.clearAll()
45
+ args.contextValue.dataLoaders.posts.clearAll()
46
+ }
47
+ })),
48
+ // ... other plugins ...
49
+ ],
50
+ });
51
+ ```
package/index.d.ts CHANGED
@@ -1 +1,14 @@
1
- export * from './use-context-value-per-execute-subscription-event';
1
+ import { SubscriptionArgs } from 'graphql';
2
+ import { Plugin, PromiseOrValue, DefaultContext } from '@envelop/core';
3
+ export declare type ContextFactoryOptions = {
4
+ /** The arguments with which the subscription was set up. */
5
+ args: SubscriptionArgs;
6
+ };
7
+ export declare type ContextFactoryHook<TContextValue> = {
8
+ /** Context that will be used for the "ExecuteSubscriptionEvent" phase. */
9
+ contextPartial: Partial<TContextValue>;
10
+ /** Optional callback that is invoked once the "ExecuteSubscriptionEvent" phase has ended. Useful for cleanup, such as tearing down database connections. */
11
+ onEnd?: () => void;
12
+ };
13
+ export declare type ContextFactoryType<TContextValue = DefaultContext> = (options: ContextFactoryOptions) => PromiseOrValue<ContextFactoryHook<TContextValue> | void>;
14
+ export declare const useExtendContextValuePerExecuteSubscriptionEvent: <TContextValue = unknown>(createContext: ContextFactoryType<TContextValue>) => Plugin<TContextValue>;
package/index.js ADDED
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const graphql = require('graphql');
6
+ const core = require('@envelop/core');
7
+
8
+ /**
9
+ * This is a almost identical port from graphql-js subscribe.
10
+ * The only difference is that a custom `execute` function can be injected for customizing the behavior.
11
+ */
12
+ const subscribe = (execute) => core.makeSubscribe(async (args) => {
13
+ const { schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver } = args;
14
+ const resultOrStream = await graphql.createSourceEventStream(schema, document, rootValue, contextValue, variableValues !== null && variableValues !== void 0 ? variableValues : undefined, operationName, subscribeFieldResolver);
15
+ if (!core.isAsyncIterable(resultOrStream)) {
16
+ return resultOrStream;
17
+ }
18
+ // For each payload yielded from a subscription, map it over the normal
19
+ // GraphQL `execute` function, with `payload` as the rootValue.
20
+ // This implements the "MapSourceToResponseEvent" algorithm described in
21
+ // the GraphQL specification. The `execute` function provides the
22
+ // "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
23
+ // "ExecuteQuery" algorithm, for which `execute` is also used.
24
+ const mapSourceToResponse = (payload) => execute({
25
+ schema,
26
+ document,
27
+ rootValue: payload,
28
+ contextValue,
29
+ variableValues,
30
+ operationName,
31
+ fieldResolver,
32
+ });
33
+ // Map every source value to a ExecutionResult value as described above.
34
+ return core.mapAsyncIterator(resultOrStream, mapSourceToResponse);
35
+ });
36
+
37
+ const useExtendContextValuePerExecuteSubscriptionEvent = (createContext) => {
38
+ return {
39
+ onSubscribe({ args, setSubscribeFn }) {
40
+ const executeNew = core.makeExecute(async (executionArgs) => {
41
+ var _a;
42
+ const context = await createContext({ args });
43
+ try {
44
+ return await graphql.execute({
45
+ ...executionArgs,
46
+ // GraphQL.js 16 changed the type of contextValue to unknown
47
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
48
+ // @ts-ignore
49
+ contextValue: { ...executionArgs.contextValue, ...context === null || context === void 0 ? void 0 : context.contextPartial },
50
+ });
51
+ }
52
+ finally {
53
+ (_a = context === null || context === void 0 ? void 0 : context.onEnd) === null || _a === void 0 ? void 0 : _a.call(context);
54
+ }
55
+ });
56
+ setSubscribeFn(subscribe(executeNew));
57
+ },
58
+ };
59
+ };
60
+
61
+ exports.useExtendContextValuePerExecuteSubscriptionEvent = useExtendContextValuePerExecuteSubscriptionEvent;
package/index.mjs ADDED
@@ -0,0 +1,57 @@
1
+ import { createSourceEventStream, execute } from 'graphql';
2
+ import { makeSubscribe, isAsyncIterable, mapAsyncIterator, makeExecute } from '@envelop/core';
3
+
4
+ /**
5
+ * This is a almost identical port from graphql-js subscribe.
6
+ * The only difference is that a custom `execute` function can be injected for customizing the behavior.
7
+ */
8
+ const subscribe = (execute) => makeSubscribe(async (args) => {
9
+ const { schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver } = args;
10
+ const resultOrStream = await createSourceEventStream(schema, document, rootValue, contextValue, variableValues !== null && variableValues !== void 0 ? variableValues : undefined, operationName, subscribeFieldResolver);
11
+ if (!isAsyncIterable(resultOrStream)) {
12
+ return resultOrStream;
13
+ }
14
+ // For each payload yielded from a subscription, map it over the normal
15
+ // GraphQL `execute` function, with `payload` as the rootValue.
16
+ // This implements the "MapSourceToResponseEvent" algorithm described in
17
+ // the GraphQL specification. The `execute` function provides the
18
+ // "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
19
+ // "ExecuteQuery" algorithm, for which `execute` is also used.
20
+ const mapSourceToResponse = (payload) => execute({
21
+ schema,
22
+ document,
23
+ rootValue: payload,
24
+ contextValue,
25
+ variableValues,
26
+ operationName,
27
+ fieldResolver,
28
+ });
29
+ // Map every source value to a ExecutionResult value as described above.
30
+ return mapAsyncIterator(resultOrStream, mapSourceToResponse);
31
+ });
32
+
33
+ const useExtendContextValuePerExecuteSubscriptionEvent = (createContext) => {
34
+ return {
35
+ onSubscribe({ args, setSubscribeFn }) {
36
+ const executeNew = makeExecute(async (executionArgs) => {
37
+ var _a;
38
+ const context = await createContext({ args });
39
+ try {
40
+ return await execute({
41
+ ...executionArgs,
42
+ // GraphQL.js 16 changed the type of contextValue to unknown
43
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
44
+ // @ts-ignore
45
+ contextValue: { ...executionArgs.contextValue, ...context === null || context === void 0 ? void 0 : context.contextPartial },
46
+ });
47
+ }
48
+ finally {
49
+ (_a = context === null || context === void 0 ? void 0 : context.onEnd) === null || _a === void 0 ? void 0 : _a.call(context);
50
+ }
51
+ });
52
+ setSubscribeFn(subscribe(executeNew));
53
+ },
54
+ };
55
+ };
56
+
57
+ export { useExtendContextValuePerExecuteSubscriptionEvent };
package/package.json CHANGED
@@ -1,21 +1,33 @@
1
1
  {
2
2
  "name": "@envelop/execute-subscription-event",
3
- "version": "0.1.0",
3
+ "version": "0.2.2-alpha-1e6c37b.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "graphql": "^14.0.0 || ^15.0.0"
6
+ "@envelop/core": "1.6.6-alpha-1e6c37b.0",
7
+ "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
7
8
  },
8
9
  "repository": {
9
10
  "type": "git",
10
11
  "url": "https://github.com/dotansimha/envelop.git",
11
12
  "directory": "packages/plugins/execute-subscription-event"
12
13
  },
13
- "author": "Dotan Simha <dotansimha@gmail.com>",
14
+ "author": "Laurin Quast <laurinquast@googlemail.com>",
14
15
  "license": "MIT",
15
- "main": "index.cjs.js",
16
- "module": "index.esm.js",
16
+ "main": "index.js",
17
+ "module": "index.mjs",
17
18
  "typings": "index.d.ts",
18
19
  "typescript": {
19
20
  "definition": "index.d.ts"
21
+ },
22
+ "exports": {
23
+ ".": {
24
+ "require": "./index.js",
25
+ "import": "./index.mjs"
26
+ },
27
+ "./*": {
28
+ "require": "./*.js",
29
+ "import": "./*.mjs"
30
+ },
31
+ "./package.json": "./package.json"
20
32
  }
21
33
  }
package/subscribe.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ExecuteFunction, SubscribeFunction } from '@envelop/types';
1
+ import { 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.
package/index.cjs.js DELETED
@@ -1,189 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const graphql = require('graphql');
6
-
7
- function getExecuteArgs(args) {
8
- return args.length === 1
9
- ? args[0]
10
- : {
11
- schema: args[0],
12
- document: args[1],
13
- rootValue: args[2],
14
- contextValue: args[3],
15
- variableValues: args[4],
16
- operationName: args[5],
17
- fieldResolver: args[6],
18
- typeResolver: args[7],
19
- };
20
- }
21
- /**
22
- * Utility function for making a execute function that handles polymorphic arguments.
23
- */
24
- const makeExecute = (executeFn) => (...polyArgs) => executeFn(getExecuteArgs(polyArgs));
25
- function getSubscribeArgs(args) {
26
- return args.length === 1
27
- ? args[0]
28
- : {
29
- schema: args[0],
30
- document: args[1],
31
- rootValue: args[2],
32
- contextValue: args[3],
33
- variableValues: args[4],
34
- operationName: args[5],
35
- fieldResolver: args[6],
36
- subscribeFieldResolver: args[7],
37
- };
38
- }
39
- /**
40
- * Utility function for making a subscribe function that handles polymorphic arguments.
41
- */
42
- const makeSubscribe = (subscribeFn) => (...polyArgs) => subscribeFn(getSubscribeArgs(polyArgs));
43
-
44
- // In ES2015 (or a polyfilled) environment, this will be Symbol.iterator
45
- // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
46
-
47
- var SYMBOL_ASYNC_ITERATOR = typeof Symbol === 'function' && Symbol.asyncIterator != null ? Symbol.asyncIterator : '@@asyncIterator'; // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
48
-
49
- /**
50
- * Returns true if the provided object implements the AsyncIterator protocol via
51
- * either implementing a `Symbol.asyncIterator` or `"@@asyncIterator"` method.
52
- */
53
-
54
- // eslint-disable-next-line no-redeclare
55
- function isAsyncIterable(maybeAsyncIterable) {
56
- return typeof (maybeAsyncIterable === null || maybeAsyncIterable === void 0 ? void 0 : maybeAsyncIterable[SYMBOL_ASYNC_ITERATOR]) === 'function';
57
- }
58
-
59
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
60
-
61
- /**
62
- * Given an AsyncIterable and a callback function, return an AsyncIterator
63
- * which produces values mapped via calling the callback function.
64
- */
65
- function mapAsyncIterator(iterable, callback, rejectCallback) {
66
- // $FlowFixMe[prop-missing]
67
- var iteratorMethod = iterable[SYMBOL_ASYNC_ITERATOR];
68
- var iterator = iteratorMethod.call(iterable);
69
- var $return;
70
- var abruptClose;
71
-
72
- if (typeof iterator.return === 'function') {
73
- $return = iterator.return;
74
-
75
- abruptClose = function abruptClose(error) {
76
- var rethrow = function rethrow() {
77
- return Promise.reject(error);
78
- };
79
-
80
- return $return.call(iterator).then(rethrow, rethrow);
81
- };
82
- }
83
-
84
- function mapResult(result) {
85
- return result.done ? result : asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);
86
- }
87
-
88
- var mapReject;
89
-
90
- if (rejectCallback) {
91
- // Capture rejectCallback to ensure it cannot be null.
92
- var reject = rejectCallback;
93
-
94
- mapReject = function mapReject(error) {
95
- return asyncMapValue(error, reject).then(iteratorResult, abruptClose);
96
- };
97
- }
98
- /* TODO: Flow doesn't support symbols as keys:
99
- https://github.com/facebook/flow/issues/3258 */
100
-
101
-
102
- return _defineProperty({
103
- next: function next() {
104
- return iterator.next().then(mapResult, mapReject);
105
- },
106
- return: function _return() {
107
- return $return ? $return.call(iterator).then(mapResult, mapReject) : Promise.resolve({
108
- value: undefined,
109
- done: true
110
- });
111
- },
112
- throw: function _throw(error) {
113
- if (typeof iterator.throw === 'function') {
114
- return iterator.throw(error).then(mapResult, mapReject);
115
- }
116
-
117
- return Promise.reject(error).catch(abruptClose);
118
- }
119
- }, SYMBOL_ASYNC_ITERATOR, function () {
120
- return this;
121
- });
122
- }
123
-
124
- function asyncMapValue(value, callback) {
125
- return new Promise(function (resolve) {
126
- return resolve(callback(value));
127
- });
128
- }
129
-
130
- function iteratorResult(value) {
131
- return {
132
- value: value,
133
- done: false
134
- };
135
- }
136
-
137
- /**
138
- * This is a almost identical port from graphql-js subscribe.
139
- * The only difference is that a custom `execute` function can be injected for customizing the behavior.
140
- */
141
- const subscribe = (execute) => makeSubscribe(async (args) => {
142
- const { schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver } = args;
143
- const resultOrStream = await graphql.createSourceEventStream(schema, document, rootValue, contextValue, variableValues !== null && variableValues !== void 0 ? variableValues : undefined, operationName, subscribeFieldResolver);
144
- if (!isAsyncIterable(resultOrStream)) {
145
- return resultOrStream;
146
- }
147
- // For each payload yielded from a subscription, map it over the normal
148
- // GraphQL `execute` function, with `payload` as the rootValue.
149
- // This implements the "MapSourceToResponseEvent" algorithm described in
150
- // the GraphQL specification. The `execute` function provides the
151
- // "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
152
- // "ExecuteQuery" algorithm, for which `execute` is also used.
153
- const mapSourceToResponse = async (payload) => execute({
154
- schema,
155
- document,
156
- rootValue: payload,
157
- contextValue,
158
- variableValues,
159
- operationName,
160
- fieldResolver,
161
- });
162
- // Map every source value to a ExecutionResult value as described above.
163
- return mapAsyncIterator(resultOrStream, mapSourceToResponse);
164
- });
165
-
166
- const useContextValuePerExecuteSubscriptionEvent = (createContext) => {
167
- return {
168
- onSubscribe({ args, setSubscribeFn }) {
169
- const executeNew = makeExecute(async (executionArgs) => {
170
- const context = await createContext({ args });
171
- try {
172
- return graphql.execute({
173
- ...executionArgs,
174
- contextValue: context ? context.contextValue : executionArgs.contextValue,
175
- });
176
- }
177
- finally {
178
- if (context && context.onEnd) {
179
- context.onEnd();
180
- }
181
- }
182
- });
183
- setSubscribeFn(subscribe(executeNew));
184
- },
185
- };
186
- };
187
-
188
- exports.useContextValuePerExecuteSubscriptionEvent = useContextValuePerExecuteSubscriptionEvent;
189
- //# sourceMappingURL=index.cjs.js.map
package/index.cjs.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../../../packages/core/dist/index.esm.js","../../../node_modules/graphql/polyfills/symbols.mjs","../../../node_modules/graphql/jsutils/isAsyncIterable.mjs","../../../node_modules/graphql/subscription/mapAsyncIterator.mjs","../../../dist/plugins/execute-subscription-event/src/subscribe.js","../../../dist/plugins/execute-subscription-event/src/use-context-value-per-execute-subscription-event.js"],"sourcesContent":["export * from '@envelop/types';\nimport { parse, specifiedRules, validate, execute, isIntrospectionType, isObjectType, defaultFieldResolver, subscribe, getOperationAST, GraphQLError } from 'graphql';\n\nfunction getExecuteArgs(args) {\n return args.length === 1\n ? args[0]\n : {\n schema: args[0],\n document: args[1],\n rootValue: args[2],\n contextValue: args[3],\n variableValues: args[4],\n operationName: args[5],\n fieldResolver: args[6],\n typeResolver: args[7],\n };\n}\n/**\n * Utility function for making a execute function that handles polymorphic arguments.\n */\nconst makeExecute = (executeFn) => (...polyArgs) => executeFn(getExecuteArgs(polyArgs));\nfunction getSubscribeArgs(args) {\n return args.length === 1\n ? args[0]\n : {\n schema: args[0],\n document: args[1],\n rootValue: args[2],\n contextValue: args[3],\n variableValues: args[4],\n operationName: args[5],\n fieldResolver: args[6],\n subscribeFieldResolver: args[7],\n };\n}\n/**\n * Utility function for making a subscribe function that handles polymorphic arguments.\n */\nconst makeSubscribe = (subscribeFn) => (...polyArgs) => subscribeFn(getSubscribeArgs(polyArgs));\n\nconst trackedSchemaSymbol = Symbol('TRACKED_SCHEMA');\nconst resolversHooksSymbol = Symbol('RESOLVERS_HOOKS');\nfunction envelop({ plugins }) {\n let schema = null;\n let initDone = false;\n const replaceSchema = (newSchema, ignorePluginIndex = -1) => {\n schema = newSchema;\n if (initDone) {\n for (const [i, plugin] of plugins.entries()) {\n if (i !== ignorePluginIndex) {\n plugin.onSchemaChange &&\n plugin.onSchemaChange({\n schema,\n replaceSchema: schemaToSet => {\n replaceSchema(schemaToSet, i);\n },\n });\n }\n }\n }\n };\n for (const [i, plugin] of plugins.entries()) {\n plugin.onPluginInit &&\n plugin.onPluginInit({\n plugins,\n addPlugin: newPlugin => {\n plugins.push(newPlugin);\n },\n setSchema: modifiedSchema => replaceSchema(modifiedSchema, i),\n });\n }\n const onContextBuildingCbs = [];\n const onExecuteCbs = [];\n const onParseCbs = [];\n const onSubscribeCbs = [];\n const onValidateCbs = [];\n for (const { onContextBuilding, onExecute, onParse, onSubscribe, onValidate } of plugins) {\n onContextBuilding && onContextBuildingCbs.push(onContextBuilding);\n onExecute && onExecuteCbs.push(onExecute);\n onParse && onParseCbs.push(onParse);\n onSubscribe && onSubscribeCbs.push(onSubscribe);\n onValidate && onValidateCbs.push(onValidate);\n }\n const customParse = onParseCbs.length\n ? (source, parseOptions) => {\n let result = null;\n let parseFn = parse;\n const afterCalls = [];\n for (const onParse of onParseCbs) {\n const afterFn = onParse({\n params: { source, options: parseOptions },\n parseFn,\n setParseFn: newFn => {\n parseFn = newFn;\n },\n setParsedDocument: newDoc => {\n result = newDoc;\n },\n });\n afterFn && afterCalls.push(afterFn);\n }\n if (result === null) {\n try {\n result = parseFn(source, parseOptions);\n }\n catch (e) {\n result = e;\n }\n }\n for (const afterCb of afterCalls) {\n afterCb({\n replaceParseResult: newResult => {\n result = newResult;\n },\n result,\n });\n }\n if (result === null) {\n throw new Error(`Failed to parse document.`);\n }\n if (result instanceof Error) {\n throw result;\n }\n return result;\n }\n : parse;\n const customValidate = onValidateCbs.length\n ? (schema, documentAST, rules, typeInfo, validationOptions) => {\n let actualRules = rules ? [...rules] : undefined;\n let validateFn = validate;\n let result = null;\n const afterCalls = [];\n for (const onValidate of onValidateCbs) {\n const afterFn = onValidate({\n params: {\n schema,\n documentAST,\n rules: actualRules,\n typeInfo,\n options: validationOptions,\n },\n validateFn,\n addValidationRule: rule => {\n if (!actualRules) {\n actualRules = [...specifiedRules];\n }\n actualRules.push(rule);\n },\n setValidationFn: newFn => {\n validateFn = newFn;\n },\n setResult: newResults => {\n result = newResults;\n },\n });\n afterFn && afterCalls.push(afterFn);\n }\n if (!result) {\n result = validateFn(schema, documentAST, actualRules, typeInfo, validationOptions);\n }\n const valid = result.length === 0;\n for (const afterCb of afterCalls) {\n afterCb({ valid, result });\n }\n return result;\n }\n : validate;\n const customContextFactory = onContextBuildingCbs.length\n ? async (initialContext) => {\n let context = initialContext;\n const afterCalls = [];\n for (const onContext of onContextBuildingCbs) {\n const afterFn = await onContext({\n context,\n extendContext: extension => {\n if (typeof extension === 'object') {\n context = {\n ...(context || {}),\n ...extension,\n };\n }\n else {\n throw new Error(`Invalid context extension provided! Expected \"object\", got: \"${JSON.stringify(extension)}\" (${typeof extension})`);\n }\n },\n });\n afterFn && afterCalls.push(afterFn);\n }\n for (const afterCb of afterCalls) {\n afterCb({ context });\n }\n return context;\n }\n : (ctx) => ctx;\n const customSubscribe = makeSubscribe(async (args) => {\n const onResolversHandlers = [];\n let subscribeFn = subscribe;\n const afterCalls = [];\n let context = args.contextValue;\n for (const onSubscribe of onSubscribeCbs) {\n const after = onSubscribe({\n subscribeFn,\n setSubscribeFn: newSubscribeFn => {\n subscribeFn = newSubscribeFn;\n },\n extendContext: extension => {\n if (typeof extension === 'object') {\n context = {\n ...(context || {}),\n ...extension,\n };\n }\n else {\n throw new Error(`Invalid context extension provided! Expected \"object\", got: \"${JSON.stringify(extension)}\" (${typeof extension})`);\n }\n },\n args,\n });\n if (after) {\n if (after.onSubscribeResult) {\n afterCalls.push(after.onSubscribeResult);\n }\n if (after.onResolverCalled) {\n onResolversHandlers.push(after.onResolverCalled);\n }\n }\n }\n if (onResolversHandlers.length) {\n context[resolversHooksSymbol] = onResolversHandlers;\n }\n let result = await subscribeFn({\n ...args,\n contextValue: context,\n });\n for (const afterCb of afterCalls) {\n afterCb({\n result,\n setResult: newResult => {\n result = newResult;\n },\n });\n }\n return result;\n });\n const customExecute = (onExecuteCbs.length\n ? makeExecute(async (args) => {\n const onResolversHandlers = [];\n let executeFn = execute;\n let result;\n const afterCalls = [];\n let context = args.contextValue;\n for (const onExecute of onExecuteCbs) {\n let stopCalled = false;\n const after = onExecute({\n executeFn,\n setExecuteFn: newExecuteFn => {\n executeFn = newExecuteFn;\n },\n setResultAndStopExecution: stopResult => {\n stopCalled = true;\n result = stopResult;\n },\n extendContext: extension => {\n if (typeof extension === 'object') {\n context = {\n ...(context || {}),\n ...extension,\n };\n }\n else {\n throw new Error(`Invalid context extension provided! Expected \"object\", got: \"${JSON.stringify(extension)}\" (${typeof extension})`);\n }\n },\n args,\n });\n if (stopCalled) {\n return result;\n }\n if (after) {\n if (after.onExecuteDone) {\n afterCalls.push(after.onExecuteDone);\n }\n if (after.onResolverCalled) {\n onResolversHandlers.push(after.onResolverCalled);\n }\n }\n }\n if (onResolversHandlers.length) {\n context[resolversHooksSymbol] = onResolversHandlers;\n }\n result = await executeFn({\n ...args,\n contextValue: context,\n });\n for (const afterCb of afterCalls) {\n afterCb({\n result,\n setResult: newResult => {\n result = newResult;\n },\n });\n }\n return result;\n })\n : execute);\n function prepareSchema() {\n if (!schema || schema[trackedSchemaSymbol]) {\n return;\n }\n schema[trackedSchemaSymbol] = true;\n const entries = Object.values(schema.getTypeMap());\n for (const type of entries) {\n if (!isIntrospectionType(type) && isObjectType(type)) {\n const fields = Object.values(type.getFields());\n for (const field of fields) {\n const originalFn = field.resolve || defaultFieldResolver;\n field.resolve = async (root, args, context, info) => {\n if (context && context[resolversHooksSymbol]) {\n const hooks = context[resolversHooksSymbol];\n const afterCalls = [];\n for (const hook of hooks) {\n const afterFn = await hook({ root, args, context, info });\n afterFn && afterCalls.push(afterFn);\n }\n try {\n let result = await originalFn(root, args, context, info);\n for (const afterFn of afterCalls) {\n afterFn({\n result,\n setResult: newResult => {\n result = newResult;\n },\n });\n }\n return result;\n }\n catch (e) {\n let resultErr = e;\n for (const afterFn of afterCalls) {\n afterFn({\n result: resultErr,\n setResult: newResult => {\n resultErr = newResult;\n },\n });\n }\n throw resultErr;\n }\n }\n else {\n return originalFn(root, args, context, info);\n }\n };\n }\n }\n }\n }\n initDone = true;\n // This is done in order to trigger the first schema available, to allow plugins that needs the schema\n // eagerly to have it.\n if (schema) {\n for (const [i, plugin] of plugins.entries()) {\n plugin.onSchemaChange &&\n plugin.onSchemaChange({\n schema,\n replaceSchema: modifiedSchema => replaceSchema(modifiedSchema, i),\n });\n }\n }\n const envelop = () => {\n prepareSchema();\n return {\n parse: customParse,\n validate: customValidate,\n contextFactory: customContextFactory,\n execute: customExecute,\n subscribe: customSubscribe,\n get schema() {\n return schema;\n },\n };\n };\n envelop._plugins = plugins;\n return envelop;\n}\n\nconst DEFAULT_OPTIONS = {\n logFn: console.log,\n};\nconst useLogger = (rawOptions = DEFAULT_OPTIONS) => {\n const options = {\n DEFAULT_OPTIONS,\n ...rawOptions,\n };\n return {\n onExecute({ args }) {\n options.logFn('execute-start', { args });\n return {\n onExecuteDone: ({ result }) => {\n options.logFn('execute-end', { args, result });\n },\n };\n },\n onSubscribe({ args }) {\n options.logFn('subscribe-start', { args });\n return {\n onSubscribeResult: ({ result }) => {\n options.logFn('subscribe-end', { args, result });\n },\n };\n },\n };\n};\n\nconst HR_TO_NS = 1e9;\nconst NS_TO_MS = 1e6;\nconst DEFAULT_OPTIONS$1 = {\n onExecutionMeasurement: (args, timing) => console.log(`Operation execution \"${args.operationName}\" done in ${timing.ms}ms`),\n onSubscriptionMeasurement: (args, timing) => console.log(`Operation subsctiption \"${args.operationName}\" done in ${timing.ms}ms`),\n onParsingMeasurement: (source, timing) => console.log(`Parsing \"${source}\" done in ${timing.ms}ms`),\n onValidationMeasurement: (document, timing) => { var _a, _b; return console.log(`Validation \"${((_b = (_a = getOperationAST(document)) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value) || '-'}\" done in ${timing.ms}ms`); },\n onResolverMeasurement: (info, timing) => console.log(`\\tResolver of \"${info.parentType.toString()}.${info.fieldName}\" done in ${timing.ms}ms`),\n onContextBuildingMeasurement: (timing) => console.log(`Context building done in ${timing.ms}ms`),\n};\nconst deltaFrom = (hrtime) => {\n const delta = process.hrtime(hrtime);\n const ns = delta[0] * HR_TO_NS + delta[1];\n return {\n ns,\n get ms() {\n return ns / NS_TO_MS;\n },\n };\n};\nconst useTiming = (rawOptions) => {\n const options = {\n ...DEFAULT_OPTIONS$1,\n ...(rawOptions || {}),\n };\n const result = {};\n if (options.onContextBuildingMeasurement) {\n result.onContextBuilding = () => {\n const contextStartTime = process.hrtime();\n return () => {\n options.onContextBuildingMeasurement(deltaFrom(contextStartTime));\n };\n };\n }\n if (options.onParsingMeasurement) {\n result.onParse = ({ params }) => {\n const parseStartTime = process.hrtime();\n return () => {\n options.onParsingMeasurement(params.source, deltaFrom(parseStartTime));\n };\n };\n }\n if (options.onValidationMeasurement) {\n result.onValidate = ({ params }) => {\n const validateStartTime = process.hrtime();\n return () => {\n options.onValidationMeasurement(params.documentAST, deltaFrom(validateStartTime));\n };\n };\n }\n if (options.onExecutionMeasurement) {\n if (options.onResolverMeasurement) {\n result.onExecute = ({ args }) => {\n const executeStartTime = process.hrtime();\n return {\n onExecuteDone: () => {\n options.onExecutionMeasurement(args, deltaFrom(executeStartTime));\n },\n onResolverCalled: ({ info }) => {\n const resolverStartTime = process.hrtime();\n return () => {\n options.onResolverMeasurement(info, deltaFrom(resolverStartTime));\n };\n },\n };\n };\n }\n else {\n result.onExecute = ({ args }) => {\n const executeStartTime = process.hrtime();\n return {\n onExecuteDone: () => {\n options.onExecutionMeasurement(args, deltaFrom(executeStartTime));\n },\n };\n };\n }\n }\n if (options.onSubscriptionMeasurement) {\n if (options.onResolverMeasurement) {\n result.onSubscribe = ({ args }) => {\n const subscribeStartTime = process.hrtime();\n return {\n onSubscribeResult: () => {\n options.onSubscriptionMeasurement && options.onSubscriptionMeasurement(args, deltaFrom(subscribeStartTime));\n },\n onResolverCalled: ({ info }) => {\n const resolverStartTime = process.hrtime();\n return () => {\n options.onResolverMeasurement && options.onResolverMeasurement(info, deltaFrom(resolverStartTime));\n };\n },\n };\n };\n }\n else {\n result.onSubscribe = ({ args }) => {\n const subscribeStartTime = process.hrtime();\n return {\n onSubscribeResult: () => {\n options.onSubscriptionMeasurement && options.onSubscriptionMeasurement(args, deltaFrom(subscribeStartTime));\n },\n };\n };\n }\n }\n return result;\n};\n\nconst useSchema = (schema) => {\n return {\n onPluginInit({ setSchema }) {\n setSchema(schema);\n },\n };\n};\n\nconst useErrorHandler = (errorHandler) => ({\n onExecute() {\n return {\n onExecuteDone: ({ result }) => {\n var _a;\n if ((_a = result.errors) === null || _a === void 0 ? void 0 : _a.length) {\n errorHandler(result.errors);\n }\n },\n };\n },\n});\n\nconst useExtendContext = (contextFactory) => ({\n async onContextBuilding({ context, extendContext }) {\n extendContext((await contextFactory(context)));\n },\n});\n\nconst usePayloadFormatter = (formatter) => ({\n onExecute() {\n return {\n onExecuteDone: ({ result, setResult }) => {\n const modified = formatter(result);\n if (modified !== false) {\n setResult(modified);\n }\n },\n };\n },\n});\n\nclass EnvelopError extends GraphQLError {\n constructor(message, extensions) {\n super(message, undefined, undefined, undefined, undefined, undefined, extensions);\n }\n}\nconst formatError = err => {\n if (err.originalError && err.originalError instanceof EnvelopError === false) {\n return new GraphQLError('Unexpected error.', err.nodes, err.source, err.positions, err.path, undefined);\n }\n return err;\n};\nconst useMaskedErrors = (opts) => {\n var _a;\n const format = (_a = opts === null || opts === void 0 ? void 0 : opts.formatError) !== null && _a !== void 0 ? _a : formatError;\n return {\n onExecute: () => {\n return {\n onExecuteDone: ({ result, setResult }) => {\n if (result.errors != null) {\n setResult({ ...result, errors: result.errors.map(error => format(error)) });\n }\n },\n };\n },\n };\n};\n\nexport { EnvelopError, envelop, formatError, getExecuteArgs, getSubscribeArgs, makeExecute, makeSubscribe, resolversHooksSymbol, useErrorHandler, useExtendContext, useLogger, useMaskedErrors, usePayloadFormatter, useSchema, useTiming };\n//# sourceMappingURL=index.esm.js.map\n","// In ES2015 (or a polyfilled) environment, this will be Symbol.iterator\n// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')\nexport var SYMBOL_ITERATOR = typeof Symbol === 'function' && Symbol.iterator != null ? Symbol.iterator : '@@iterator'; // In ES2017 (or a polyfilled) environment, this will be Symbol.asyncIterator\n// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')\n\nexport var SYMBOL_ASYNC_ITERATOR = typeof Symbol === 'function' && Symbol.asyncIterator != null ? Symbol.asyncIterator : '@@asyncIterator'; // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')\n\nexport var SYMBOL_TO_STRING_TAG = typeof Symbol === 'function' && Symbol.toStringTag != null ? Symbol.toStringTag : '@@toStringTag';\n","import { SYMBOL_ASYNC_ITERATOR } from \"../polyfills/symbols.mjs\";\n/**\n * Returns true if the provided object implements the AsyncIterator protocol via\n * either implementing a `Symbol.asyncIterator` or `\"@@asyncIterator\"` method.\n */\n\n// eslint-disable-next-line no-redeclare\nexport default function isAsyncIterable(maybeAsyncIterable) {\n return typeof (maybeAsyncIterable === null || maybeAsyncIterable === void 0 ? void 0 : maybeAsyncIterable[SYMBOL_ASYNC_ITERATOR]) === 'function';\n}\n","function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nimport { SYMBOL_ASYNC_ITERATOR } from \"../polyfills/symbols.mjs\";\n\n/**\n * Given an AsyncIterable and a callback function, return an AsyncIterator\n * which produces values mapped via calling the callback function.\n */\nexport default function mapAsyncIterator(iterable, callback, rejectCallback) {\n // $FlowFixMe[prop-missing]\n var iteratorMethod = iterable[SYMBOL_ASYNC_ITERATOR];\n var iterator = iteratorMethod.call(iterable);\n var $return;\n var abruptClose;\n\n if (typeof iterator.return === 'function') {\n $return = iterator.return;\n\n abruptClose = function abruptClose(error) {\n var rethrow = function rethrow() {\n return Promise.reject(error);\n };\n\n return $return.call(iterator).then(rethrow, rethrow);\n };\n }\n\n function mapResult(result) {\n return result.done ? result : asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);\n }\n\n var mapReject;\n\n if (rejectCallback) {\n // Capture rejectCallback to ensure it cannot be null.\n var reject = rejectCallback;\n\n mapReject = function mapReject(error) {\n return asyncMapValue(error, reject).then(iteratorResult, abruptClose);\n };\n }\n /* TODO: Flow doesn't support symbols as keys:\n https://github.com/facebook/flow/issues/3258 */\n\n\n return _defineProperty({\n next: function next() {\n return iterator.next().then(mapResult, mapReject);\n },\n return: function _return() {\n return $return ? $return.call(iterator).then(mapResult, mapReject) : Promise.resolve({\n value: undefined,\n done: true\n });\n },\n throw: function _throw(error) {\n if (typeof iterator.throw === 'function') {\n return iterator.throw(error).then(mapResult, mapReject);\n }\n\n return Promise.reject(error).catch(abruptClose);\n }\n }, SYMBOL_ASYNC_ITERATOR, function () {\n return this;\n });\n}\n\nfunction asyncMapValue(value, callback) {\n return new Promise(function (resolve) {\n return resolve(callback(value));\n });\n}\n\nfunction iteratorResult(value) {\n return {\n value: value,\n done: false\n };\n}\n","import { createSourceEventStream } from 'graphql';\nimport isAsyncIterable from 'graphql/jsutils/isAsyncIterable';\nimport mapAsyncIterator from 'graphql/subscription/mapAsyncIterator';\nimport { makeSubscribe } from '@envelop/core';\n/**\n * This is a almost identical port from graphql-js subscribe.\n * The only difference is that a custom `execute` function can be injected for customizing the behavior.\n */\nexport const subscribe = (execute) => makeSubscribe(async (args) => {\n const { schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver } = args;\n const resultOrStream = await createSourceEventStream(schema, document, rootValue, contextValue, variableValues !== null && variableValues !== void 0 ? variableValues : undefined, operationName, subscribeFieldResolver);\n if (!isAsyncIterable(resultOrStream)) {\n return resultOrStream;\n }\n // For each payload yielded from a subscription, map it over the normal\n // GraphQL `execute` function, with `payload` as the rootValue.\n // This implements the \"MapSourceToResponseEvent\" algorithm described in\n // the GraphQL specification. The `execute` function provides the\n // \"ExecuteSubscriptionEvent\" algorithm, as it is nearly identical to the\n // \"ExecuteQuery\" algorithm, for which `execute` is also used.\n const mapSourceToResponse = async (payload) => execute({\n schema,\n document,\n rootValue: payload,\n contextValue,\n variableValues,\n operationName,\n fieldResolver,\n });\n // Map every source value to a ExecutionResult value as described above.\n return mapAsyncIterator(resultOrStream, mapSourceToResponse);\n});\n//# sourceMappingURL=subscribe.js.map","import { execute } from 'graphql';\nimport { makeExecute } from '@envelop/core';\nimport { subscribe } from './subscribe';\nexport const useContextValuePerExecuteSubscriptionEvent = (createContext) => {\n return {\n onSubscribe({ args, setSubscribeFn }) {\n const executeNew = makeExecute(async (executionArgs) => {\n const context = await createContext({ args });\n try {\n return execute({\n ...executionArgs,\n contextValue: context ? context.contextValue : executionArgs.contextValue,\n });\n }\n finally {\n if (context && context.onEnd) {\n context.onEnd();\n }\n }\n });\n setSubscribeFn(subscribe(executeNew));\n },\n };\n};\n//# sourceMappingURL=use-context-value-per-execute-subscription-event.js.map"],"names":["createSourceEventStream","execute"],"mappings":";;;;;;AAGA,SAAS,cAAc,CAAC,IAAI,EAAE;AAC9B,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC;AAC5B,UAAU,IAAI,CAAC,CAAC,CAAC;AACjB,UAAU;AACV,YAAY,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AAC3B,YAAY,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;AAC7B,YAAY,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;AAC9B,YAAY,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;AACjC,YAAY,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC;AACnC,YAAY,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC;AAClC,YAAY,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC;AAClC,YAAY,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;AACjC,SAAS,CAAC;AACV,CAAC;AACD;AACA;AACA;AACA,MAAM,WAAW,GAAG,CAAC,SAAS,KAAK,CAAC,GAAG,QAAQ,KAAK,SAAS,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;AACxF,SAAS,gBAAgB,CAAC,IAAI,EAAE;AAChC,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC;AAC5B,UAAU,IAAI,CAAC,CAAC,CAAC;AACjB,UAAU;AACV,YAAY,MAAM,EAAE,IAAI,CAAC,CA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,EAAE,CAAC,CAAC;AAC9D,gBAAgB,IAAI;AACpB,oBAAoB,OAAOC,eAAO,CAAC;AACnC,wBAAwB,GAAG,aAAa;AACxC,wBAAwB,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,GAAG,aAAa,CAAC,YAAY;AACjG,qBAAqB,CAAC,CAAC;AACvB,iBAAiB;AACjB,wBAAwB;AACxB,oBAAoB,IAAI,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE;AAClD,wBAAwB,OAAO,CAAC,KAAK,EAAE,CAAC;AACxC,qBAAqB;AACrB,iBAAiB;AACjB,aAAa,CAAC,CAAC;AACf,YAAY,cAAc,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;AAClD,SAAS;AACT,KAAK,CAAC;AACN;;;;"}
package/index.esm.js DELETED
@@ -1,185 +0,0 @@
1
- import { createSourceEventStream, execute } from 'graphql';
2
-
3
- function getExecuteArgs(args) {
4
- return args.length === 1
5
- ? args[0]
6
- : {
7
- schema: args[0],
8
- document: args[1],
9
- rootValue: args[2],
10
- contextValue: args[3],
11
- variableValues: args[4],
12
- operationName: args[5],
13
- fieldResolver: args[6],
14
- typeResolver: args[7],
15
- };
16
- }
17
- /**
18
- * Utility function for making a execute function that handles polymorphic arguments.
19
- */
20
- const makeExecute = (executeFn) => (...polyArgs) => executeFn(getExecuteArgs(polyArgs));
21
- function getSubscribeArgs(args) {
22
- return args.length === 1
23
- ? args[0]
24
- : {
25
- schema: args[0],
26
- document: args[1],
27
- rootValue: args[2],
28
- contextValue: args[3],
29
- variableValues: args[4],
30
- operationName: args[5],
31
- fieldResolver: args[6],
32
- subscribeFieldResolver: args[7],
33
- };
34
- }
35
- /**
36
- * Utility function for making a subscribe function that handles polymorphic arguments.
37
- */
38
- const makeSubscribe = (subscribeFn) => (...polyArgs) => subscribeFn(getSubscribeArgs(polyArgs));
39
-
40
- // In ES2015 (or a polyfilled) environment, this will be Symbol.iterator
41
- // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
42
-
43
- var SYMBOL_ASYNC_ITERATOR = typeof Symbol === 'function' && Symbol.asyncIterator != null ? Symbol.asyncIterator : '@@asyncIterator'; // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
44
-
45
- /**
46
- * Returns true if the provided object implements the AsyncIterator protocol via
47
- * either implementing a `Symbol.asyncIterator` or `"@@asyncIterator"` method.
48
- */
49
-
50
- // eslint-disable-next-line no-redeclare
51
- function isAsyncIterable(maybeAsyncIterable) {
52
- return typeof (maybeAsyncIterable === null || maybeAsyncIterable === void 0 ? void 0 : maybeAsyncIterable[SYMBOL_ASYNC_ITERATOR]) === 'function';
53
- }
54
-
55
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
56
-
57
- /**
58
- * Given an AsyncIterable and a callback function, return an AsyncIterator
59
- * which produces values mapped via calling the callback function.
60
- */
61
- function mapAsyncIterator(iterable, callback, rejectCallback) {
62
- // $FlowFixMe[prop-missing]
63
- var iteratorMethod = iterable[SYMBOL_ASYNC_ITERATOR];
64
- var iterator = iteratorMethod.call(iterable);
65
- var $return;
66
- var abruptClose;
67
-
68
- if (typeof iterator.return === 'function') {
69
- $return = iterator.return;
70
-
71
- abruptClose = function abruptClose(error) {
72
- var rethrow = function rethrow() {
73
- return Promise.reject(error);
74
- };
75
-
76
- return $return.call(iterator).then(rethrow, rethrow);
77
- };
78
- }
79
-
80
- function mapResult(result) {
81
- return result.done ? result : asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);
82
- }
83
-
84
- var mapReject;
85
-
86
- if (rejectCallback) {
87
- // Capture rejectCallback to ensure it cannot be null.
88
- var reject = rejectCallback;
89
-
90
- mapReject = function mapReject(error) {
91
- return asyncMapValue(error, reject).then(iteratorResult, abruptClose);
92
- };
93
- }
94
- /* TODO: Flow doesn't support symbols as keys:
95
- https://github.com/facebook/flow/issues/3258 */
96
-
97
-
98
- return _defineProperty({
99
- next: function next() {
100
- return iterator.next().then(mapResult, mapReject);
101
- },
102
- return: function _return() {
103
- return $return ? $return.call(iterator).then(mapResult, mapReject) : Promise.resolve({
104
- value: undefined,
105
- done: true
106
- });
107
- },
108
- throw: function _throw(error) {
109
- if (typeof iterator.throw === 'function') {
110
- return iterator.throw(error).then(mapResult, mapReject);
111
- }
112
-
113
- return Promise.reject(error).catch(abruptClose);
114
- }
115
- }, SYMBOL_ASYNC_ITERATOR, function () {
116
- return this;
117
- });
118
- }
119
-
120
- function asyncMapValue(value, callback) {
121
- return new Promise(function (resolve) {
122
- return resolve(callback(value));
123
- });
124
- }
125
-
126
- function iteratorResult(value) {
127
- return {
128
- value: value,
129
- done: false
130
- };
131
- }
132
-
133
- /**
134
- * This is a almost identical port from graphql-js subscribe.
135
- * The only difference is that a custom `execute` function can be injected for customizing the behavior.
136
- */
137
- const subscribe = (execute) => makeSubscribe(async (args) => {
138
- const { schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver } = args;
139
- const resultOrStream = await createSourceEventStream(schema, document, rootValue, contextValue, variableValues !== null && variableValues !== void 0 ? variableValues : undefined, operationName, subscribeFieldResolver);
140
- if (!isAsyncIterable(resultOrStream)) {
141
- return resultOrStream;
142
- }
143
- // For each payload yielded from a subscription, map it over the normal
144
- // GraphQL `execute` function, with `payload` as the rootValue.
145
- // This implements the "MapSourceToResponseEvent" algorithm described in
146
- // the GraphQL specification. The `execute` function provides the
147
- // "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
148
- // "ExecuteQuery" algorithm, for which `execute` is also used.
149
- const mapSourceToResponse = async (payload) => execute({
150
- schema,
151
- document,
152
- rootValue: payload,
153
- contextValue,
154
- variableValues,
155
- operationName,
156
- fieldResolver,
157
- });
158
- // Map every source value to a ExecutionResult value as described above.
159
- return mapAsyncIterator(resultOrStream, mapSourceToResponse);
160
- });
161
-
162
- const useContextValuePerExecuteSubscriptionEvent = (createContext) => {
163
- return {
164
- onSubscribe({ args, setSubscribeFn }) {
165
- const executeNew = makeExecute(async (executionArgs) => {
166
- const context = await createContext({ args });
167
- try {
168
- return execute({
169
- ...executionArgs,
170
- contextValue: context ? context.contextValue : executionArgs.contextValue,
171
- });
172
- }
173
- finally {
174
- if (context && context.onEnd) {
175
- context.onEnd();
176
- }
177
- }
178
- });
179
- setSubscribeFn(subscribe(executeNew));
180
- },
181
- };
182
- };
183
-
184
- export { useContextValuePerExecuteSubscriptionEvent };
185
- //# sourceMappingURL=index.esm.js.map
package/index.esm.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":["../../../packages/core/dist/index.esm.js","../../../node_modules/graphql/polyfills/symbols.mjs","../../../node_modules/graphql/jsutils/isAsyncIterable.mjs","../../../node_modules/graphql/subscription/mapAsyncIterator.mjs","../../../dist/plugins/execute-subscription-event/src/subscribe.js","../../../dist/plugins/execute-subscription-event/src/use-context-value-per-execute-subscription-event.js"],"sourcesContent":["export * from '@envelop/types';\nimport { parse, specifiedRules, validate, execute, isIntrospectionType, isObjectType, defaultFieldResolver, subscribe, getOperationAST, GraphQLError } from 'graphql';\n\nfunction getExecuteArgs(args) {\n return args.length === 1\n ? args[0]\n : {\n schema: args[0],\n document: args[1],\n rootValue: args[2],\n contextValue: args[3],\n variableValues: args[4],\n operationName: args[5],\n fieldResolver: args[6],\n typeResolver: args[7],\n };\n}\n/**\n * Utility function for making a execute function that handles polymorphic arguments.\n */\nconst makeExecute = (executeFn) => (...polyArgs) => executeFn(getExecuteArgs(polyArgs));\nfunction getSubscribeArgs(args) {\n return args.length === 1\n ? args[0]\n : {\n schema: args[0],\n document: args[1],\n rootValue: args[2],\n contextValue: args[3],\n variableValues: args[4],\n operationName: args[5],\n fieldResolver: args[6],\n subscribeFieldResolver: args[7],\n };\n}\n/**\n * Utility function for making a subscribe function that handles polymorphic arguments.\n */\nconst makeSubscribe = (subscribeFn) => (...polyArgs) => subscribeFn(getSubscribeArgs(polyArgs));\n\nconst trackedSchemaSymbol = Symbol('TRACKED_SCHEMA');\nconst resolversHooksSymbol = Symbol('RESOLVERS_HOOKS');\nfunction envelop({ plugins }) {\n let schema = null;\n let initDone = false;\n const replaceSchema = (newSchema, ignorePluginIndex = -1) => {\n schema = newSchema;\n if (initDone) {\n for (const [i, plugin] of plugins.entries()) {\n if (i !== ignorePluginIndex) {\n plugin.onSchemaChange &&\n plugin.onSchemaChange({\n schema,\n replaceSchema: schemaToSet => {\n replaceSchema(schemaToSet, i);\n },\n });\n }\n }\n }\n };\n for (const [i, plugin] of plugins.entries()) {\n plugin.onPluginInit &&\n plugin.onPluginInit({\n plugins,\n addPlugin: newPlugin => {\n plugins.push(newPlugin);\n },\n setSchema: modifiedSchema => replaceSchema(modifiedSchema, i),\n });\n }\n const onContextBuildingCbs = [];\n const onExecuteCbs = [];\n const onParseCbs = [];\n const onSubscribeCbs = [];\n const onValidateCbs = [];\n for (const { onContextBuilding, onExecute, onParse, onSubscribe, onValidate } of plugins) {\n onContextBuilding && onContextBuildingCbs.push(onContextBuilding);\n onExecute && onExecuteCbs.push(onExecute);\n onParse && onParseCbs.push(onParse);\n onSubscribe && onSubscribeCbs.push(onSubscribe);\n onValidate && onValidateCbs.push(onValidate);\n }\n const customParse = onParseCbs.length\n ? (source, parseOptions) => {\n let result = null;\n let parseFn = parse;\n const afterCalls = [];\n for (const onParse of onParseCbs) {\n const afterFn = onParse({\n params: { source, options: parseOptions },\n parseFn,\n setParseFn: newFn => {\n parseFn = newFn;\n },\n setParsedDocument: newDoc => {\n result = newDoc;\n },\n });\n afterFn && afterCalls.push(afterFn);\n }\n if (result === null) {\n try {\n result = parseFn(source, parseOptions);\n }\n catch (e) {\n result = e;\n }\n }\n for (const afterCb of afterCalls) {\n afterCb({\n replaceParseResult: newResult => {\n result = newResult;\n },\n result,\n });\n }\n if (result === null) {\n throw new Error(`Failed to parse document.`);\n }\n if (result instanceof Error) {\n throw result;\n }\n return result;\n }\n : parse;\n const customValidate = onValidateCbs.length\n ? (schema, documentAST, rules, typeInfo, validationOptions) => {\n let actualRules = rules ? [...rules] : undefined;\n let validateFn = validate;\n let result = null;\n const afterCalls = [];\n for (const onValidate of onValidateCbs) {\n const afterFn = onValidate({\n params: {\n schema,\n documentAST,\n rules: actualRules,\n typeInfo,\n options: validationOptions,\n },\n validateFn,\n addValidationRule: rule => {\n if (!actualRules) {\n actualRules = [...specifiedRules];\n }\n actualRules.push(rule);\n },\n setValidationFn: newFn => {\n validateFn = newFn;\n },\n setResult: newResults => {\n result = newResults;\n },\n });\n afterFn && afterCalls.push(afterFn);\n }\n if (!result) {\n result = validateFn(schema, documentAST, actualRules, typeInfo, validationOptions);\n }\n const valid = result.length === 0;\n for (const afterCb of afterCalls) {\n afterCb({ valid, result });\n }\n return result;\n }\n : validate;\n const customContextFactory = onContextBuildingCbs.length\n ? async (initialContext) => {\n let context = initialContext;\n const afterCalls = [];\n for (const onContext of onContextBuildingCbs) {\n const afterFn = await onContext({\n context,\n extendContext: extension => {\n if (typeof extension === 'object') {\n context = {\n ...(context || {}),\n ...extension,\n };\n }\n else {\n throw new Error(`Invalid context extension provided! Expected \"object\", got: \"${JSON.stringify(extension)}\" (${typeof extension})`);\n }\n },\n });\n afterFn && afterCalls.push(afterFn);\n }\n for (const afterCb of afterCalls) {\n afterCb({ context });\n }\n return context;\n }\n : (ctx) => ctx;\n const customSubscribe = makeSubscribe(async (args) => {\n const onResolversHandlers = [];\n let subscribeFn = subscribe;\n const afterCalls = [];\n let context = args.contextValue;\n for (const onSubscribe of onSubscribeCbs) {\n const after = onSubscribe({\n subscribeFn,\n setSubscribeFn: newSubscribeFn => {\n subscribeFn = newSubscribeFn;\n },\n extendContext: extension => {\n if (typeof extension === 'object') {\n context = {\n ...(context || {}),\n ...extension,\n };\n }\n else {\n throw new Error(`Invalid context extension provided! Expected \"object\", got: \"${JSON.stringify(extension)}\" (${typeof extension})`);\n }\n },\n args,\n });\n if (after) {\n if (after.onSubscribeResult) {\n afterCalls.push(after.onSubscribeResult);\n }\n if (after.onResolverCalled) {\n onResolversHandlers.push(after.onResolverCalled);\n }\n }\n }\n if (onResolversHandlers.length) {\n context[resolversHooksSymbol] = onResolversHandlers;\n }\n let result = await subscribeFn({\n ...args,\n contextValue: context,\n });\n for (const afterCb of afterCalls) {\n afterCb({\n result,\n setResult: newResult => {\n result = newResult;\n },\n });\n }\n return result;\n });\n const customExecute = (onExecuteCbs.length\n ? makeExecute(async (args) => {\n const onResolversHandlers = [];\n let executeFn = execute;\n let result;\n const afterCalls = [];\n let context = args.contextValue;\n for (const onExecute of onExecuteCbs) {\n let stopCalled = false;\n const after = onExecute({\n executeFn,\n setExecuteFn: newExecuteFn => {\n executeFn = newExecuteFn;\n },\n setResultAndStopExecution: stopResult => {\n stopCalled = true;\n result = stopResult;\n },\n extendContext: extension => {\n if (typeof extension === 'object') {\n context = {\n ...(context || {}),\n ...extension,\n };\n }\n else {\n throw new Error(`Invalid context extension provided! Expected \"object\", got: \"${JSON.stringify(extension)}\" (${typeof extension})`);\n }\n },\n args,\n });\n if (stopCalled) {\n return result;\n }\n if (after) {\n if (after.onExecuteDone) {\n afterCalls.push(after.onExecuteDone);\n }\n if (after.onResolverCalled) {\n onResolversHandlers.push(after.onResolverCalled);\n }\n }\n }\n if (onResolversHandlers.length) {\n context[resolversHooksSymbol] = onResolversHandlers;\n }\n result = await executeFn({\n ...args,\n contextValue: context,\n });\n for (const afterCb of afterCalls) {\n afterCb({\n result,\n setResult: newResult => {\n result = newResult;\n },\n });\n }\n return result;\n })\n : execute);\n function prepareSchema() {\n if (!schema || schema[trackedSchemaSymbol]) {\n return;\n }\n schema[trackedSchemaSymbol] = true;\n const entries = Object.values(schema.getTypeMap());\n for (const type of entries) {\n if (!isIntrospectionType(type) && isObjectType(type)) {\n const fields = Object.values(type.getFields());\n for (const field of fields) {\n const originalFn = field.resolve || defaultFieldResolver;\n field.resolve = async (root, args, context, info) => {\n if (context && context[resolversHooksSymbol]) {\n const hooks = context[resolversHooksSymbol];\n const afterCalls = [];\n for (const hook of hooks) {\n const afterFn = await hook({ root, args, context, info });\n afterFn && afterCalls.push(afterFn);\n }\n try {\n let result = await originalFn(root, args, context, info);\n for (const afterFn of afterCalls) {\n afterFn({\n result,\n setResult: newResult => {\n result = newResult;\n },\n });\n }\n return result;\n }\n catch (e) {\n let resultErr = e;\n for (const afterFn of afterCalls) {\n afterFn({\n result: resultErr,\n setResult: newResult => {\n resultErr = newResult;\n },\n });\n }\n throw resultErr;\n }\n }\n else {\n return originalFn(root, args, context, info);\n }\n };\n }\n }\n }\n }\n initDone = true;\n // This is done in order to trigger the first schema available, to allow plugins that needs the schema\n // eagerly to have it.\n if (schema) {\n for (const [i, plugin] of plugins.entries()) {\n plugin.onSchemaChange &&\n plugin.onSchemaChange({\n schema,\n replaceSchema: modifiedSchema => replaceSchema(modifiedSchema, i),\n });\n }\n }\n const envelop = () => {\n prepareSchema();\n return {\n parse: customParse,\n validate: customValidate,\n contextFactory: customContextFactory,\n execute: customExecute,\n subscribe: customSubscribe,\n get schema() {\n return schema;\n },\n };\n };\n envelop._plugins = plugins;\n return envelop;\n}\n\nconst DEFAULT_OPTIONS = {\n logFn: console.log,\n};\nconst useLogger = (rawOptions = DEFAULT_OPTIONS) => {\n const options = {\n DEFAULT_OPTIONS,\n ...rawOptions,\n };\n return {\n onExecute({ args }) {\n options.logFn('execute-start', { args });\n return {\n onExecuteDone: ({ result }) => {\n options.logFn('execute-end', { args, result });\n },\n };\n },\n onSubscribe({ args }) {\n options.logFn('subscribe-start', { args });\n return {\n onSubscribeResult: ({ result }) => {\n options.logFn('subscribe-end', { args, result });\n },\n };\n },\n };\n};\n\nconst HR_TO_NS = 1e9;\nconst NS_TO_MS = 1e6;\nconst DEFAULT_OPTIONS$1 = {\n onExecutionMeasurement: (args, timing) => console.log(`Operation execution \"${args.operationName}\" done in ${timing.ms}ms`),\n onSubscriptionMeasurement: (args, timing) => console.log(`Operation subsctiption \"${args.operationName}\" done in ${timing.ms}ms`),\n onParsingMeasurement: (source, timing) => console.log(`Parsing \"${source}\" done in ${timing.ms}ms`),\n onValidationMeasurement: (document, timing) => { var _a, _b; return console.log(`Validation \"${((_b = (_a = getOperationAST(document)) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value) || '-'}\" done in ${timing.ms}ms`); },\n onResolverMeasurement: (info, timing) => console.log(`\\tResolver of \"${info.parentType.toString()}.${info.fieldName}\" done in ${timing.ms}ms`),\n onContextBuildingMeasurement: (timing) => console.log(`Context building done in ${timing.ms}ms`),\n};\nconst deltaFrom = (hrtime) => {\n const delta = process.hrtime(hrtime);\n const ns = delta[0] * HR_TO_NS + delta[1];\n return {\n ns,\n get ms() {\n return ns / NS_TO_MS;\n },\n };\n};\nconst useTiming = (rawOptions) => {\n const options = {\n ...DEFAULT_OPTIONS$1,\n ...(rawOptions || {}),\n };\n const result = {};\n if (options.onContextBuildingMeasurement) {\n result.onContextBuilding = () => {\n const contextStartTime = process.hrtime();\n return () => {\n options.onContextBuildingMeasurement(deltaFrom(contextStartTime));\n };\n };\n }\n if (options.onParsingMeasurement) {\n result.onParse = ({ params }) => {\n const parseStartTime = process.hrtime();\n return () => {\n options.onParsingMeasurement(params.source, deltaFrom(parseStartTime));\n };\n };\n }\n if (options.onValidationMeasurement) {\n result.onValidate = ({ params }) => {\n const validateStartTime = process.hrtime();\n return () => {\n options.onValidationMeasurement(params.documentAST, deltaFrom(validateStartTime));\n };\n };\n }\n if (options.onExecutionMeasurement) {\n if (options.onResolverMeasurement) {\n result.onExecute = ({ args }) => {\n const executeStartTime = process.hrtime();\n return {\n onExecuteDone: () => {\n options.onExecutionMeasurement(args, deltaFrom(executeStartTime));\n },\n onResolverCalled: ({ info }) => {\n const resolverStartTime = process.hrtime();\n return () => {\n options.onResolverMeasurement(info, deltaFrom(resolverStartTime));\n };\n },\n };\n };\n }\n else {\n result.onExecute = ({ args }) => {\n const executeStartTime = process.hrtime();\n return {\n onExecuteDone: () => {\n options.onExecutionMeasurement(args, deltaFrom(executeStartTime));\n },\n };\n };\n }\n }\n if (options.onSubscriptionMeasurement) {\n if (options.onResolverMeasurement) {\n result.onSubscribe = ({ args }) => {\n const subscribeStartTime = process.hrtime();\n return {\n onSubscribeResult: () => {\n options.onSubscriptionMeasurement && options.onSubscriptionMeasurement(args, deltaFrom(subscribeStartTime));\n },\n onResolverCalled: ({ info }) => {\n const resolverStartTime = process.hrtime();\n return () => {\n options.onResolverMeasurement && options.onResolverMeasurement(info, deltaFrom(resolverStartTime));\n };\n },\n };\n };\n }\n else {\n result.onSubscribe = ({ args }) => {\n const subscribeStartTime = process.hrtime();\n return {\n onSubscribeResult: () => {\n options.onSubscriptionMeasurement && options.onSubscriptionMeasurement(args, deltaFrom(subscribeStartTime));\n },\n };\n };\n }\n }\n return result;\n};\n\nconst useSchema = (schema) => {\n return {\n onPluginInit({ setSchema }) {\n setSchema(schema);\n },\n };\n};\n\nconst useErrorHandler = (errorHandler) => ({\n onExecute() {\n return {\n onExecuteDone: ({ result }) => {\n var _a;\n if ((_a = result.errors) === null || _a === void 0 ? void 0 : _a.length) {\n errorHandler(result.errors);\n }\n },\n };\n },\n});\n\nconst useExtendContext = (contextFactory) => ({\n async onContextBuilding({ context, extendContext }) {\n extendContext((await contextFactory(context)));\n },\n});\n\nconst usePayloadFormatter = (formatter) => ({\n onExecute() {\n return {\n onExecuteDone: ({ result, setResult }) => {\n const modified = formatter(result);\n if (modified !== false) {\n setResult(modified);\n }\n },\n };\n },\n});\n\nclass EnvelopError extends GraphQLError {\n constructor(message, extensions) {\n super(message, undefined, undefined, undefined, undefined, undefined, extensions);\n }\n}\nconst formatError = err => {\n if (err.originalError && err.originalError instanceof EnvelopError === false) {\n return new GraphQLError('Unexpected error.', err.nodes, err.source, err.positions, err.path, undefined);\n }\n return err;\n};\nconst useMaskedErrors = (opts) => {\n var _a;\n const format = (_a = opts === null || opts === void 0 ? void 0 : opts.formatError) !== null && _a !== void 0 ? _a : formatError;\n return {\n onExecute: () => {\n return {\n onExecuteDone: ({ result, setResult }) => {\n if (result.errors != null) {\n setResult({ ...result, errors: result.errors.map(error => format(error)) });\n }\n },\n };\n },\n };\n};\n\nexport { EnvelopError, envelop, formatError, getExecuteArgs, getSubscribeArgs, makeExecute, makeSubscribe, resolversHooksSymbol, useErrorHandler, useExtendContext, useLogger, useMaskedErrors, usePayloadFormatter, useSchema, useTiming };\n//# sourceMappingURL=index.esm.js.map\n","// In ES2015 (or a polyfilled) environment, this will be Symbol.iterator\n// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')\nexport var SYMBOL_ITERATOR = typeof Symbol === 'function' && Symbol.iterator != null ? Symbol.iterator : '@@iterator'; // In ES2017 (or a polyfilled) environment, this will be Symbol.asyncIterator\n// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')\n\nexport var SYMBOL_ASYNC_ITERATOR = typeof Symbol === 'function' && Symbol.asyncIterator != null ? Symbol.asyncIterator : '@@asyncIterator'; // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')\n\nexport var SYMBOL_TO_STRING_TAG = typeof Symbol === 'function' && Symbol.toStringTag != null ? Symbol.toStringTag : '@@toStringTag';\n","import { SYMBOL_ASYNC_ITERATOR } from \"../polyfills/symbols.mjs\";\n/**\n * Returns true if the provided object implements the AsyncIterator protocol via\n * either implementing a `Symbol.asyncIterator` or `\"@@asyncIterator\"` method.\n */\n\n// eslint-disable-next-line no-redeclare\nexport default function isAsyncIterable(maybeAsyncIterable) {\n return typeof (maybeAsyncIterable === null || maybeAsyncIterable === void 0 ? void 0 : maybeAsyncIterable[SYMBOL_ASYNC_ITERATOR]) === 'function';\n}\n","function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nimport { SYMBOL_ASYNC_ITERATOR } from \"../polyfills/symbols.mjs\";\n\n/**\n * Given an AsyncIterable and a callback function, return an AsyncIterator\n * which produces values mapped via calling the callback function.\n */\nexport default function mapAsyncIterator(iterable, callback, rejectCallback) {\n // $FlowFixMe[prop-missing]\n var iteratorMethod = iterable[SYMBOL_ASYNC_ITERATOR];\n var iterator = iteratorMethod.call(iterable);\n var $return;\n var abruptClose;\n\n if (typeof iterator.return === 'function') {\n $return = iterator.return;\n\n abruptClose = function abruptClose(error) {\n var rethrow = function rethrow() {\n return Promise.reject(error);\n };\n\n return $return.call(iterator).then(rethrow, rethrow);\n };\n }\n\n function mapResult(result) {\n return result.done ? result : asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);\n }\n\n var mapReject;\n\n if (rejectCallback) {\n // Capture rejectCallback to ensure it cannot be null.\n var reject = rejectCallback;\n\n mapReject = function mapReject(error) {\n return asyncMapValue(error, reject).then(iteratorResult, abruptClose);\n };\n }\n /* TODO: Flow doesn't support symbols as keys:\n https://github.com/facebook/flow/issues/3258 */\n\n\n return _defineProperty({\n next: function next() {\n return iterator.next().then(mapResult, mapReject);\n },\n return: function _return() {\n return $return ? $return.call(iterator).then(mapResult, mapReject) : Promise.resolve({\n value: undefined,\n done: true\n });\n },\n throw: function _throw(error) {\n if (typeof iterator.throw === 'function') {\n return iterator.throw(error).then(mapResult, mapReject);\n }\n\n return Promise.reject(error).catch(abruptClose);\n }\n }, SYMBOL_ASYNC_ITERATOR, function () {\n return this;\n });\n}\n\nfunction asyncMapValue(value, callback) {\n return new Promise(function (resolve) {\n return resolve(callback(value));\n });\n}\n\nfunction iteratorResult(value) {\n return {\n value: value,\n done: false\n };\n}\n","import { createSourceEventStream } from 'graphql';\nimport isAsyncIterable from 'graphql/jsutils/isAsyncIterable';\nimport mapAsyncIterator from 'graphql/subscription/mapAsyncIterator';\nimport { makeSubscribe } from '@envelop/core';\n/**\n * This is a almost identical port from graphql-js subscribe.\n * The only difference is that a custom `execute` function can be injected for customizing the behavior.\n */\nexport const subscribe = (execute) => makeSubscribe(async (args) => {\n const { schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver } = args;\n const resultOrStream = await createSourceEventStream(schema, document, rootValue, contextValue, variableValues !== null && variableValues !== void 0 ? variableValues : undefined, operationName, subscribeFieldResolver);\n if (!isAsyncIterable(resultOrStream)) {\n return resultOrStream;\n }\n // For each payload yielded from a subscription, map it over the normal\n // GraphQL `execute` function, with `payload` as the rootValue.\n // This implements the \"MapSourceToResponseEvent\" algorithm described in\n // the GraphQL specification. The `execute` function provides the\n // \"ExecuteSubscriptionEvent\" algorithm, as it is nearly identical to the\n // \"ExecuteQuery\" algorithm, for which `execute` is also used.\n const mapSourceToResponse = async (payload) => execute({\n schema,\n document,\n rootValue: payload,\n contextValue,\n variableValues,\n operationName,\n fieldResolver,\n });\n // Map every source value to a ExecutionResult value as described above.\n return mapAsyncIterator(resultOrStream, mapSourceToResponse);\n});\n//# sourceMappingURL=subscribe.js.map","import { execute } from 'graphql';\nimport { makeExecute } from '@envelop/core';\nimport { subscribe } from './subscribe';\nexport const useContextValuePerExecuteSubscriptionEvent = (createContext) => {\n return {\n onSubscribe({ args, setSubscribeFn }) {\n const executeNew = makeExecute(async (executionArgs) => {\n const context = await createContext({ args });\n try {\n return execute({\n ...executionArgs,\n contextValue: context ? context.contextValue : executionArgs.contextValue,\n });\n }\n finally {\n if (context && context.onEnd) {\n context.onEnd();\n }\n }\n });\n setSubscribeFn(subscribe(executeNew));\n },\n };\n};\n//# sourceMappingURL=use-context-value-per-execute-subscription-event.js.map"],"names":[],"mappings":";;AAGA,SAAS,cAAc,CAAC,IAAI,EAAE;AAC9B,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC;AAC5B,UAAU,IAAI,CAAC,CAAC,CAAC;AACjB,UAAU;AACV,YAAY,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AAC3B,YAAY,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;AAC7B,YAAY,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;AAC9B,YAAY,YAAY,EAAE,IAAI,CAAC,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O,OAAO,KAAK,OAAO,CAAC;AAC3D,QAAQ,MAAM;AACd,QAAQ,QAAQ;AAChB,QAAQ,SAAS,EAAE,OAAO;AAC1B,QAAQ,YAAY;AACpB,QAAQ,cAAc;AACtB,QAAQ,aAAa;AACrB,QAAQ,aAAa;AACrB,KAAK,CAAC,CAAC;AACP;AACA,IAAI,OAAO,gBAAgB,CAAC,cAAc,EAAE,mBAAmB,CAAC,CAAC;AACjE,CAAC,CAAC;;AC5BU,MAAC,0CAA0C,GAAG,CAAC,aAAa,KAAK;AAC7E,IAAI,OAAO;AACX,QAAQ,WAAW,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE;AAC9C,YAAY,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,aAAa,KAAK;AACpE,gBAAgB,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,gBAAgB,IAAI;AACpB,oBAAoB,OAAO,OAAO,CAAC;AACnC,wBAAwB,GAAG,aAAa;AACxC,wBAAwB,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,GAAG,aAAa,CAAC,YAAY;AACjG,qBAAqB,CAAC,CAAC;AACvB,iBAAiB;AACjB,wBAAwB;AACxB,oBAAoB,IAAI,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE;AAClD,wBAAwB,OAAO,CAAC,KAAK,EAAE,CAAC;AACxC,qBAAqB;AACrB,iBAAiB;AACjB,aAAa,CAAC,CAAC;AACf,YAAY,cAAc,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;AAClD,SAAS;AACT,KAAK,CAAC;AACN;;;;"}
@@ -1,15 +0,0 @@
1
- import { SubscriptionArgs } from 'graphql';
2
- import { Plugin } from '@envelop/types';
3
- import { PromiseOrValue } from 'graphql/jsutils/PromiseOrValue';
4
- export declare type ContextFactoryOptions = {
5
- /** The arguments with which the subscription was set up. */
6
- args: SubscriptionArgs;
7
- };
8
- export declare type ContextFactoryHook<TContextValue> = {
9
- /** Context that will be used for the "ExecuteSubscriptionEvent" phase. */
10
- contextValue: TContextValue;
11
- /** Optional callback that is invoked once the "ExecuteSubscriptionEvent" phase has ended. Useful for cleanup, such as tearing down database connections. */
12
- onEnd?: () => void;
13
- };
14
- export declare type ContextFactoryType<TContextValue = unknown> = (options: ContextFactoryOptions) => PromiseOrValue<ContextFactoryHook<TContextValue> | void>;
15
- export declare const useContextValuePerExecuteSubscriptionEvent: <TContextValue = unknown>(createContext: ContextFactoryType<TContextValue>) => Plugin;