@envelop/execute-subscription-event 0.2.0 → 0.2.2-alpha-63e92f8.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 +5 -65
- package/index.mjs +1 -61
- package/package.json +4 -2
package/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { SubscriptionArgs } from 'graphql';
|
|
2
|
-
import { Plugin, PromiseOrValue } from '@envelop/
|
|
3
|
-
import { DefaultContext } from '@envelop/core';
|
|
2
|
+
import { Plugin, PromiseOrValue, DefaultContext } from '@envelop/core';
|
|
4
3
|
export declare type ContextFactoryOptions = {
|
|
5
4
|
/** The arguments with which the subscription was set up. */
|
|
6
5
|
args: SubscriptionArgs;
|
package/index.js
CHANGED
|
@@ -3,76 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const graphql = require('graphql');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns true if the provided object implements the AsyncIterator protocol via
|
|
9
|
-
* implementing a `Symbol.asyncIterator` method.
|
|
10
|
-
*
|
|
11
|
-
* Source: https://github.com/graphql/graphql-js/blob/main/src/jsutils/isAsyncIterable.ts
|
|
12
|
-
*/
|
|
13
|
-
function isAsyncIterable(maybeAsyncIterable) {
|
|
14
|
-
return (maybeAsyncIterable != null &&
|
|
15
|
-
typeof maybeAsyncIterable === 'object' &&
|
|
16
|
-
typeof maybeAsyncIterable[Symbol.asyncIterator] === 'function');
|
|
17
|
-
}
|
|
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 = {}));
|
|
26
|
-
function getSubscribeArgs(args) {
|
|
27
|
-
return args.length === 1
|
|
28
|
-
? args[0]
|
|
29
|
-
: {
|
|
30
|
-
schema: args[0],
|
|
31
|
-
document: args[1],
|
|
32
|
-
rootValue: args[2],
|
|
33
|
-
contextValue: args[3],
|
|
34
|
-
variableValues: args[4],
|
|
35
|
-
operationName: args[5],
|
|
36
|
-
fieldResolver: args[6],
|
|
37
|
-
subscribeFieldResolver: args[7],
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Utility function for making a subscribe function that handles polymorphic arguments.
|
|
42
|
-
*/
|
|
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
|
-
}
|
|
49
|
-
function getExecuteArgs(args) {
|
|
50
|
-
return args.length === 1
|
|
51
|
-
? args[0]
|
|
52
|
-
: {
|
|
53
|
-
schema: args[0],
|
|
54
|
-
document: args[1],
|
|
55
|
-
rootValue: args[2],
|
|
56
|
-
contextValue: args[3],
|
|
57
|
-
variableValues: args[4],
|
|
58
|
-
operationName: args[5],
|
|
59
|
-
fieldResolver: args[6],
|
|
60
|
-
typeResolver: args[7],
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Utility function for making a execute function that handles polymorphic arguments.
|
|
65
|
-
*/
|
|
66
|
-
const makeExecute = (executeFn) => ((...polyArgs) => executeFn(getExecuteArgs(polyArgs)));
|
|
6
|
+
const core = require('@envelop/core');
|
|
67
7
|
|
|
68
8
|
/**
|
|
69
9
|
* This is a almost identical port from graphql-js subscribe.
|
|
70
10
|
* The only difference is that a custom `execute` function can be injected for customizing the behavior.
|
|
71
11
|
*/
|
|
72
|
-
const subscribe = (execute) => makeSubscribe(async (args) => {
|
|
12
|
+
const subscribe = (execute) => core.makeSubscribe(async (args) => {
|
|
73
13
|
const { schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver } = args;
|
|
74
14
|
const resultOrStream = await graphql.createSourceEventStream(schema, document, rootValue, contextValue, variableValues !== null && variableValues !== void 0 ? variableValues : undefined, operationName, subscribeFieldResolver);
|
|
75
|
-
if (!isAsyncIterable(resultOrStream)) {
|
|
15
|
+
if (!core.isAsyncIterable(resultOrStream)) {
|
|
76
16
|
return resultOrStream;
|
|
77
17
|
}
|
|
78
18
|
// For each payload yielded from a subscription, map it over the normal
|
|
@@ -91,13 +31,13 @@ const subscribe = (execute) => makeSubscribe(async (args) => {
|
|
|
91
31
|
fieldResolver,
|
|
92
32
|
});
|
|
93
33
|
// Map every source value to a ExecutionResult value as described above.
|
|
94
|
-
return mapAsyncIterator(resultOrStream, mapSourceToResponse);
|
|
34
|
+
return core.mapAsyncIterator(resultOrStream, mapSourceToResponse);
|
|
95
35
|
});
|
|
96
36
|
|
|
97
37
|
const useExtendContextValuePerExecuteSubscriptionEvent = (createContext) => {
|
|
98
38
|
return {
|
|
99
39
|
onSubscribe({ args, setSubscribeFn }) {
|
|
100
|
-
const executeNew = makeExecute(async (executionArgs) => {
|
|
40
|
+
const executeNew = core.makeExecute(async (executionArgs) => {
|
|
101
41
|
var _a;
|
|
102
42
|
const context = await createContext({ args });
|
|
103
43
|
try {
|
package/index.mjs
CHANGED
|
@@ -1,65 +1,5 @@
|
|
|
1
1
|
import { createSourceEventStream, execute } from 'graphql';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns true if the provided object implements the AsyncIterator protocol via
|
|
5
|
-
* implementing a `Symbol.asyncIterator` method.
|
|
6
|
-
*
|
|
7
|
-
* Source: https://github.com/graphql/graphql-js/blob/main/src/jsutils/isAsyncIterable.ts
|
|
8
|
-
*/
|
|
9
|
-
function isAsyncIterable(maybeAsyncIterable) {
|
|
10
|
-
return (maybeAsyncIterable != null &&
|
|
11
|
-
typeof maybeAsyncIterable === 'object' &&
|
|
12
|
-
typeof maybeAsyncIterable[Symbol.asyncIterator] === 'function');
|
|
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 = {}));
|
|
22
|
-
function getSubscribeArgs(args) {
|
|
23
|
-
return args.length === 1
|
|
24
|
-
? args[0]
|
|
25
|
-
: {
|
|
26
|
-
schema: args[0],
|
|
27
|
-
document: args[1],
|
|
28
|
-
rootValue: args[2],
|
|
29
|
-
contextValue: args[3],
|
|
30
|
-
variableValues: args[4],
|
|
31
|
-
operationName: args[5],
|
|
32
|
-
fieldResolver: args[6],
|
|
33
|
-
subscribeFieldResolver: args[7],
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Utility function for making a subscribe function that handles polymorphic arguments.
|
|
38
|
-
*/
|
|
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
|
-
}
|
|
45
|
-
function getExecuteArgs(args) {
|
|
46
|
-
return args.length === 1
|
|
47
|
-
? args[0]
|
|
48
|
-
: {
|
|
49
|
-
schema: args[0],
|
|
50
|
-
document: args[1],
|
|
51
|
-
rootValue: args[2],
|
|
52
|
-
contextValue: args[3],
|
|
53
|
-
variableValues: args[4],
|
|
54
|
-
operationName: args[5],
|
|
55
|
-
fieldResolver: args[6],
|
|
56
|
-
typeResolver: args[7],
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Utility function for making a execute function that handles polymorphic arguments.
|
|
61
|
-
*/
|
|
62
|
-
const makeExecute = (executeFn) => ((...polyArgs) => executeFn(getExecuteArgs(polyArgs)));
|
|
2
|
+
import { makeSubscribe, isAsyncIterable, mapAsyncIterator, makeExecute } from '@envelop/core';
|
|
63
3
|
|
|
64
4
|
/**
|
|
65
5
|
* This is a almost identical port from graphql-js subscribe.
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/execute-subscription-event",
|
|
3
|
-
"version": "0.2.0",
|
|
3
|
+
"version": "0.2.2-alpha-63e92f8.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
+
"@envelop/core": "1.6.6-alpha-63e92f8.0",
|
|
6
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
7
8
|
},
|
|
8
9
|
"repository": {
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
"./*": {
|
|
27
28
|
"require": "./*.js",
|
|
28
29
|
"import": "./*.mjs"
|
|
29
|
-
}
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
30
32
|
}
|
|
31
33
|
}
|