@envelop/execute-subscription-event 0.0.5 → 0.1.0-alpha-ed2d5ef.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/index.d.ts +1 -2
- package/index.js +19 -5
- package/index.mjs +19 -3
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { SubscriptionArgs } from 'graphql';
|
|
2
|
-
import { Plugin } from '@envelop/types';
|
|
2
|
+
import { Plugin, PromiseOrValue } from '@envelop/types';
|
|
3
3
|
import { DefaultContext } from '@envelop/core';
|
|
4
|
-
import { PromiseOrValue } from 'graphql/jsutils/PromiseOrValue';
|
|
5
4
|
export declare type ContextFactoryOptions = {
|
|
6
5
|
/** The arguments with which the subscription was set up. */
|
|
7
6
|
args: SubscriptionArgs;
|
package/index.js
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
5
|
const graphql = require('graphql');
|
|
8
|
-
const mapAsyncIterator = _interopDefault(require('graphql/subscription/mapAsyncIterator.js'));
|
|
9
6
|
|
|
10
7
|
/**
|
|
11
8
|
* Returns true if the provided object implements the AsyncIterator protocol via
|
|
@@ -14,9 +11,18 @@ const mapAsyncIterator = _interopDefault(require('graphql/subscription/mapAsyncI
|
|
|
14
11
|
* Source: https://github.com/graphql/graphql-js/blob/main/src/jsutils/isAsyncIterable.ts
|
|
15
12
|
*/
|
|
16
13
|
function isAsyncIterable(maybeAsyncIterable) {
|
|
17
|
-
return
|
|
14
|
+
return (maybeAsyncIterable != null &&
|
|
15
|
+
typeof maybeAsyncIterable === 'object' &&
|
|
16
|
+
typeof maybeAsyncIterable[Symbol.asyncIterator] === 'function');
|
|
18
17
|
}
|
|
19
18
|
|
|
19
|
+
/**
|
|
20
|
+
* This enum is used only internally in order to create nominal type for the disabled plugin
|
|
21
|
+
*/
|
|
22
|
+
var EnableIfBranded;
|
|
23
|
+
(function (EnableIfBranded) {
|
|
24
|
+
EnableIfBranded[EnableIfBranded["DisabledPlugin"] = 0] = "DisabledPlugin";
|
|
25
|
+
})(EnableIfBranded || (EnableIfBranded = {}));
|
|
20
26
|
function getSubscribeArgs(args) {
|
|
21
27
|
return args.length === 1
|
|
22
28
|
? args[0]
|
|
@@ -35,6 +41,11 @@ function getSubscribeArgs(args) {
|
|
|
35
41
|
* Utility function for making a subscribe function that handles polymorphic arguments.
|
|
36
42
|
*/
|
|
37
43
|
const makeSubscribe = (subscribeFn) => ((...polyArgs) => subscribeFn(getSubscribeArgs(polyArgs)));
|
|
44
|
+
async function* mapAsyncIterator(asyncIterable, map) {
|
|
45
|
+
for await (const value of asyncIterable) {
|
|
46
|
+
yield map(value);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
38
49
|
function getExecuteArgs(args) {
|
|
39
50
|
return args.length === 1
|
|
40
51
|
? args[0]
|
|
@@ -70,7 +81,7 @@ const subscribe = (execute) => makeSubscribe(async (args) => {
|
|
|
70
81
|
// the GraphQL specification. The `execute` function provides the
|
|
71
82
|
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
72
83
|
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
73
|
-
const mapSourceToResponse =
|
|
84
|
+
const mapSourceToResponse = (payload) => execute({
|
|
74
85
|
schema,
|
|
75
86
|
document,
|
|
76
87
|
rootValue: payload,
|
|
@@ -92,6 +103,9 @@ const useExtendContextValuePerExecuteSubscriptionEvent = (createContext) => {
|
|
|
92
103
|
try {
|
|
93
104
|
return await graphql.execute({
|
|
94
105
|
...executionArgs,
|
|
106
|
+
// GraphQL.js 16 changed the type of contextValue to unknown
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
108
|
+
// @ts-ignore
|
|
95
109
|
contextValue: { ...executionArgs.contextValue, ...context === null || context === void 0 ? void 0 : context.contextPartial },
|
|
96
110
|
});
|
|
97
111
|
}
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createSourceEventStream, execute } from 'graphql';
|
|
2
|
-
import mapAsyncIterator from 'graphql/subscription/mapAsyncIterator.js';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Returns true if the provided object implements the AsyncIterator protocol via
|
|
@@ -8,9 +7,18 @@ import mapAsyncIterator from 'graphql/subscription/mapAsyncIterator.js';
|
|
|
8
7
|
* Source: https://github.com/graphql/graphql-js/blob/main/src/jsutils/isAsyncIterable.ts
|
|
9
8
|
*/
|
|
10
9
|
function isAsyncIterable(maybeAsyncIterable) {
|
|
11
|
-
return
|
|
10
|
+
return (maybeAsyncIterable != null &&
|
|
11
|
+
typeof maybeAsyncIterable === 'object' &&
|
|
12
|
+
typeof maybeAsyncIterable[Symbol.asyncIterator] === 'function');
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* This enum is used only internally in order to create nominal type for the disabled plugin
|
|
17
|
+
*/
|
|
18
|
+
var EnableIfBranded;
|
|
19
|
+
(function (EnableIfBranded) {
|
|
20
|
+
EnableIfBranded[EnableIfBranded["DisabledPlugin"] = 0] = "DisabledPlugin";
|
|
21
|
+
})(EnableIfBranded || (EnableIfBranded = {}));
|
|
14
22
|
function getSubscribeArgs(args) {
|
|
15
23
|
return args.length === 1
|
|
16
24
|
? args[0]
|
|
@@ -29,6 +37,11 @@ function getSubscribeArgs(args) {
|
|
|
29
37
|
* Utility function for making a subscribe function that handles polymorphic arguments.
|
|
30
38
|
*/
|
|
31
39
|
const makeSubscribe = (subscribeFn) => ((...polyArgs) => subscribeFn(getSubscribeArgs(polyArgs)));
|
|
40
|
+
async function* mapAsyncIterator(asyncIterable, map) {
|
|
41
|
+
for await (const value of asyncIterable) {
|
|
42
|
+
yield map(value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
32
45
|
function getExecuteArgs(args) {
|
|
33
46
|
return args.length === 1
|
|
34
47
|
? args[0]
|
|
@@ -64,7 +77,7 @@ const subscribe = (execute) => makeSubscribe(async (args) => {
|
|
|
64
77
|
// the GraphQL specification. The `execute` function provides the
|
|
65
78
|
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
|
66
79
|
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
|
67
|
-
const mapSourceToResponse =
|
|
80
|
+
const mapSourceToResponse = (payload) => execute({
|
|
68
81
|
schema,
|
|
69
82
|
document,
|
|
70
83
|
rootValue: payload,
|
|
@@ -86,6 +99,9 @@ const useExtendContextValuePerExecuteSubscriptionEvent = (createContext) => {
|
|
|
86
99
|
try {
|
|
87
100
|
return await execute({
|
|
88
101
|
...executionArgs,
|
|
102
|
+
// GraphQL.js 16 changed the type of contextValue to unknown
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
104
|
+
// @ts-ignore
|
|
89
105
|
contextValue: { ...executionArgs.contextValue, ...context === null || context === void 0 ? void 0 : context.contextPartial },
|
|
90
106
|
});
|
|
91
107
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/execute-subscription-event",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.1.0-alpha-ed2d5ef.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"graphql": "^14.0.0 || ^15.0.0"
|
|
6
|
+
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
7
7
|
},
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/dotansimha/envelop.git",
|
|
11
|
-
"directory": "packages/plugins/
|
|
11
|
+
"directory": "packages/plugins/execute-subscription-event"
|
|
12
12
|
},
|
|
13
13
|
"author": "Laurin Quast <laurinquast@googlemail.com>",
|
|
14
14
|
"license": "MIT",
|