@graphitation/supermassive 0.4.3 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintcache +1 -1
- package/CHANGELOG.json +61 -1
- package/CHANGELOG.md +34 -2
- package/lib/benchmarks/swapi-schema/resolvers.d.ts.map +1 -1
- package/lib/benchmarks/swapi-schema/resolvers.js +56 -0
- package/lib/benchmarks/swapi-schema/resolvers.mjs +41 -0
- package/lib/executeWithoutSchema.d.ts +6 -5
- package/lib/executeWithoutSchema.d.ts.map +1 -1
- package/lib/executeWithoutSchema.js +5 -1
- package/lib/executeWithoutSchema.mjs +5 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.mjs +5 -1
- package/lib/subscribeWithSchema.d.ts +3 -0
- package/lib/subscribeWithSchema.d.ts.map +1 -0
- package/lib/subscribeWithSchema.js +78 -0
- package/lib/subscribeWithSchema.mjs +64 -0
- package/lib/subscribeWithoutSchema.d.ts +57 -0
- package/lib/subscribeWithoutSchema.d.ts.map +1 -0
- package/lib/subscribeWithoutSchema.js +155 -0
- package/lib/subscribeWithoutSchema.mjs +144 -0
- package/lib/types.d.ts +7 -2
- package/lib/types.d.ts.map +1 -1
- package/lib/utilities/mapAsyncIterator.d.ts +7 -0
- package/lib/utilities/mapAsyncIterator.d.ts.map +1 -0
- package/lib/utilities/mapAsyncIterator.js +71 -0
- package/lib/utilities/mapAsyncIterator.mjs +66 -0
- package/package.json +5 -4
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
10
|
+
var __objSpread = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
25
|
+
};
|
|
26
|
+
var __reExport = (target, module2, desc) => {
|
|
27
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(module2))
|
|
29
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
30
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
31
|
+
}
|
|
32
|
+
return target;
|
|
33
|
+
};
|
|
34
|
+
var __toModule = (module2) => {
|
|
35
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
36
|
+
};
|
|
37
|
+
__markAsModule(exports);
|
|
38
|
+
__export(exports, {
|
|
39
|
+
subscribeWithSchema: () => subscribeWithSchema
|
|
40
|
+
});
|
|
41
|
+
var import_schema = __toModule(require("@graphql-tools/schema"));
|
|
42
|
+
var import_graphql = __toModule(require("graphql"));
|
|
43
|
+
var import_index = __toModule(require("./index"));
|
|
44
|
+
function subscribeWithSchema({
|
|
45
|
+
typeDefs,
|
|
46
|
+
resolvers,
|
|
47
|
+
document: rawDocument,
|
|
48
|
+
rootValue,
|
|
49
|
+
contextValue,
|
|
50
|
+
variableValues,
|
|
51
|
+
operationName,
|
|
52
|
+
fieldResolver,
|
|
53
|
+
typeResolver
|
|
54
|
+
}) {
|
|
55
|
+
const schema = (0, import_schema.makeExecutableSchema)({typeDefs, resolvers});
|
|
56
|
+
let extractedResolvers = {};
|
|
57
|
+
const getTypeByName = (name) => {
|
|
58
|
+
const type = import_index.specifiedScalars[name] || extractedResolvers[name];
|
|
59
|
+
if ((0, import_graphql.isInputType)(type)) {
|
|
60
|
+
return type;
|
|
61
|
+
} else {
|
|
62
|
+
throw new Error("Invalid type");
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
extractedResolvers = (0, import_index.extractImplicitTypes)(typeDefs, getTypeByName);
|
|
66
|
+
const fullResolvers = __objSpread(__objSpread({}, extractedResolvers), resolvers);
|
|
67
|
+
const document = (0, import_index.addTypesToRequestDocument)(schema, rawDocument);
|
|
68
|
+
return (0, import_index.subscribeWithoutSchema)({
|
|
69
|
+
document,
|
|
70
|
+
resolvers: fullResolvers,
|
|
71
|
+
rootValue,
|
|
72
|
+
contextValue,
|
|
73
|
+
variableValues,
|
|
74
|
+
operationName,
|
|
75
|
+
fieldResolver,
|
|
76
|
+
typeResolver
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
6
|
+
var __objSpread = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/subscribeWithSchema.ts
|
|
19
|
+
import {makeExecutableSchema} from "@graphql-tools/schema";
|
|
20
|
+
import {isInputType} from "graphql";
|
|
21
|
+
import {
|
|
22
|
+
addTypesToRequestDocument,
|
|
23
|
+
subscribeWithoutSchema,
|
|
24
|
+
extractImplicitTypes,
|
|
25
|
+
specifiedScalars
|
|
26
|
+
} from "./index.mjs";
|
|
27
|
+
function subscribeWithSchema({
|
|
28
|
+
typeDefs,
|
|
29
|
+
resolvers,
|
|
30
|
+
document: rawDocument,
|
|
31
|
+
rootValue,
|
|
32
|
+
contextValue,
|
|
33
|
+
variableValues,
|
|
34
|
+
operationName,
|
|
35
|
+
fieldResolver,
|
|
36
|
+
typeResolver
|
|
37
|
+
}) {
|
|
38
|
+
const schema = makeExecutableSchema({typeDefs, resolvers});
|
|
39
|
+
let extractedResolvers = {};
|
|
40
|
+
const getTypeByName = (name) => {
|
|
41
|
+
const type = specifiedScalars[name] || extractedResolvers[name];
|
|
42
|
+
if (isInputType(type)) {
|
|
43
|
+
return type;
|
|
44
|
+
} else {
|
|
45
|
+
throw new Error("Invalid type");
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
extractedResolvers = extractImplicitTypes(typeDefs, getTypeByName);
|
|
49
|
+
const fullResolvers = __objSpread(__objSpread({}, extractedResolvers), resolvers);
|
|
50
|
+
const document = addTypesToRequestDocument(schema, rawDocument);
|
|
51
|
+
return subscribeWithoutSchema({
|
|
52
|
+
document,
|
|
53
|
+
resolvers: fullResolvers,
|
|
54
|
+
rootValue,
|
|
55
|
+
contextValue,
|
|
56
|
+
variableValues,
|
|
57
|
+
operationName,
|
|
58
|
+
fieldResolver,
|
|
59
|
+
typeResolver
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
subscribeWithSchema
|
|
64
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Maybe } from "./jsutils/Maybe";
|
|
2
|
+
import { DocumentNode } from "./ast/TypedAST";
|
|
3
|
+
import { FunctionFieldResolver, ExecutionWithoutSchemaArgs, Resolvers, ExecutionResult } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* Implements the "Subscribe" algorithm described in the GraphQL specification.
|
|
6
|
+
*
|
|
7
|
+
* Returns a Promise which resolves to either an AsyncIterator (if successful)
|
|
8
|
+
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
9
|
+
* other arguments to this function are invalid, or if the resolved event stream
|
|
10
|
+
* is not an async iterable.
|
|
11
|
+
*
|
|
12
|
+
* If the client-provided arguments to this function do not result in a
|
|
13
|
+
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
14
|
+
* descriptive errors and no data will be returned.
|
|
15
|
+
*
|
|
16
|
+
* If the source stream could not be created due to faulty subscription
|
|
17
|
+
* resolver logic or underlying systems, the promise will resolve to a single
|
|
18
|
+
* ExecutionResult containing `errors` and no `data`.
|
|
19
|
+
*
|
|
20
|
+
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
|
21
|
+
* yields a stream of ExecutionResults representing the response stream.
|
|
22
|
+
*
|
|
23
|
+
* Accepts either an object with named arguments, or individual arguments.
|
|
24
|
+
*/
|
|
25
|
+
export declare function subscribeWithoutSchema(args: ExecutionWithoutSchemaArgs): Promise<AsyncGenerator<ExecutionResult, void, void> | ExecutionResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Implements the "CreateSourceEventStream" algorithm described in the
|
|
28
|
+
* GraphQL specification, resolving the subscription source event stream.
|
|
29
|
+
*
|
|
30
|
+
* Returns a Promise which resolves to either an AsyncIterable (if successful)
|
|
31
|
+
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
|
32
|
+
* other arguments to this function are invalid, or if the resolved event stream
|
|
33
|
+
* is not an async iterable.
|
|
34
|
+
*
|
|
35
|
+
* If the client-provided arguments to this function do not result in a
|
|
36
|
+
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
|
37
|
+
* descriptive errors and no data will be returned.
|
|
38
|
+
*
|
|
39
|
+
* If the the source stream could not be created due to faulty subscription
|
|
40
|
+
* resolver logic or underlying systems, the promise will resolve to a single
|
|
41
|
+
* ExecutionResult containing `errors` and no `data`.
|
|
42
|
+
*
|
|
43
|
+
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
|
44
|
+
* event stream returned by the resolver.
|
|
45
|
+
*
|
|
46
|
+
* A Source Event Stream represents a sequence of events, each of which triggers
|
|
47
|
+
* a GraphQL execution for that event.
|
|
48
|
+
*
|
|
49
|
+
* This may be useful when hosting the stateful subscription service in a
|
|
50
|
+
* different process or machine than the stateless GraphQL execution engine,
|
|
51
|
+
* or otherwise separating these two steps. For more on this, see the
|
|
52
|
+
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
|
53
|
+
*/
|
|
54
|
+
export declare function createSourceEventStream(resolvers: Resolvers, document: DocumentNode, rootValue?: unknown, contextValue?: unknown, variableValues?: Maybe<{
|
|
55
|
+
readonly [variable: string]: unknown;
|
|
56
|
+
}>, operationName?: Maybe<string>, fieldResolver?: Maybe<FunctionFieldResolver<any, any>>): Promise<AsyncIterable<unknown> | ExecutionResult>;
|
|
57
|
+
//# sourceMappingURL=subscribeWithoutSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribeWithoutSchema.d.ts","sourceRoot":"","sources":["../src/subscribeWithoutSchema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAQ7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAgB9C,OAAO,EAEL,qBAAqB,EACrB,0BAA0B,EAE1B,SAAS,EACT,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,0BAA0B,GAC/B,OAAO,CAAC,cAAc,CAAC,eAAe,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,eAAe,CAAC,CA6CxE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,uBAAuB,CAC3C,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,YAAY,EACtB,SAAS,CAAC,EAAE,OAAO,EACnB,YAAY,CAAC,EAAE,OAAO,EACtB,cAAc,CAAC,EAAE,KAAK,CAAC;IAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC,EAChE,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EAC7B,aAAa,CAAC,EAAE,KAAK,CAAC,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GACrD,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,CAyCnD"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
var __async = (__this, __arguments, generator) => {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
var fulfilled = (value) => {
|
|
26
|
+
try {
|
|
27
|
+
step(generator.next(value));
|
|
28
|
+
} catch (e) {
|
|
29
|
+
reject(e);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var rejected = (value) => {
|
|
33
|
+
try {
|
|
34
|
+
step(generator.throw(value));
|
|
35
|
+
} catch (e) {
|
|
36
|
+
reject(e);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
40
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
__markAsModule(exports);
|
|
44
|
+
__export(exports, {
|
|
45
|
+
createSourceEventStream: () => createSourceEventStream,
|
|
46
|
+
subscribeWithoutSchema: () => subscribeWithoutSchema
|
|
47
|
+
});
|
|
48
|
+
var import_inspect = __toModule(require("./jsutils/inspect"));
|
|
49
|
+
var import_isAsyncIterable = __toModule(require("./jsutils/isAsyncIterable"));
|
|
50
|
+
var import_Path = __toModule(require("./jsutils/Path"));
|
|
51
|
+
var import_graphql = __toModule(require("graphql"));
|
|
52
|
+
var import_executeWithoutSchema = __toModule(require("./executeWithoutSchema"));
|
|
53
|
+
var import_collectFields = __toModule(require("./collectFields"));
|
|
54
|
+
var import_values = __toModule(require("./values"));
|
|
55
|
+
var import_typeNameFromAST = __toModule(require("./utilities/typeNameFromAST"));
|
|
56
|
+
var import_mapAsyncIterator = __toModule(require("./utilities/mapAsyncIterator"));
|
|
57
|
+
function subscribeWithoutSchema(args) {
|
|
58
|
+
return __async(this, null, function* () {
|
|
59
|
+
const {
|
|
60
|
+
resolvers,
|
|
61
|
+
document,
|
|
62
|
+
rootValue,
|
|
63
|
+
contextValue,
|
|
64
|
+
variableValues,
|
|
65
|
+
operationName,
|
|
66
|
+
fieldResolver,
|
|
67
|
+
subscribeFieldResolver
|
|
68
|
+
} = args;
|
|
69
|
+
const resultOrStream = yield createSourceEventStream(resolvers, document, rootValue, contextValue, variableValues, operationName, subscribeFieldResolver);
|
|
70
|
+
if (!(0, import_isAsyncIterable.isAsyncIterable)(resultOrStream)) {
|
|
71
|
+
return resultOrStream;
|
|
72
|
+
}
|
|
73
|
+
const mapSourceToResponse = (payload) => (0, import_executeWithoutSchema.executeWithoutSchema)({
|
|
74
|
+
resolvers,
|
|
75
|
+
document,
|
|
76
|
+
rootValue: payload,
|
|
77
|
+
contextValue,
|
|
78
|
+
variableValues,
|
|
79
|
+
operationName,
|
|
80
|
+
fieldResolver
|
|
81
|
+
});
|
|
82
|
+
return (0, import_mapAsyncIterator.mapAsyncIterator)(resultOrStream, mapSourceToResponse);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function createSourceEventStream(resolvers, document, rootValue, contextValue, variableValues, operationName, fieldResolver) {
|
|
86
|
+
return __async(this, null, function* () {
|
|
87
|
+
(0, import_executeWithoutSchema.assertValidExecutionArguments)(document, variableValues);
|
|
88
|
+
try {
|
|
89
|
+
const exeContext = (0, import_executeWithoutSchema.buildExecutionContext)(resolvers, document, rootValue, contextValue, variableValues, operationName, fieldResolver);
|
|
90
|
+
if (!("resolvers" in exeContext)) {
|
|
91
|
+
return {errors: exeContext};
|
|
92
|
+
}
|
|
93
|
+
const eventStream = yield executeSubscription(exeContext);
|
|
94
|
+
if (!(0, import_isAsyncIterable.isAsyncIterable)(eventStream)) {
|
|
95
|
+
throw new Error(`Subscription field must return Async Iterable. Received: ${(0, import_inspect.inspect)(eventStream)}.`);
|
|
96
|
+
}
|
|
97
|
+
return eventStream;
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (error instanceof import_graphql.GraphQLError) {
|
|
100
|
+
return {errors: [error]};
|
|
101
|
+
}
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function executeSubscription(exeContext) {
|
|
107
|
+
return __async(this, null, function* () {
|
|
108
|
+
const {
|
|
109
|
+
resolvers,
|
|
110
|
+
fragments,
|
|
111
|
+
operation,
|
|
112
|
+
variableValues,
|
|
113
|
+
rootValue
|
|
114
|
+
} = exeContext;
|
|
115
|
+
const typeName = (0, import_executeWithoutSchema.getOperationRootTypeName)(operation);
|
|
116
|
+
const fields = (0, import_collectFields.collectFields)(resolvers, fragments, variableValues, typeName, operation.selectionSet, new Map(), new Set());
|
|
117
|
+
const [responseName, fieldNodes] = [...fields.entries()][0];
|
|
118
|
+
const fieldName = fieldNodes[0].name.value;
|
|
119
|
+
let resolveFn;
|
|
120
|
+
let returnTypeName;
|
|
121
|
+
let returnTypeNode;
|
|
122
|
+
if (fieldName === "__typename" && !resolveFn) {
|
|
123
|
+
resolveFn = () => typeName;
|
|
124
|
+
returnTypeName = "String";
|
|
125
|
+
returnTypeNode = {
|
|
126
|
+
kind: import_graphql.Kind.NAMED_TYPE,
|
|
127
|
+
name: {
|
|
128
|
+
kind: import_graphql.Kind.NAME,
|
|
129
|
+
value: "String"
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
} else {
|
|
133
|
+
returnTypeNode = fieldNodes[0].__type;
|
|
134
|
+
returnTypeName = (0, import_typeNameFromAST.typeNameFromAST)(returnTypeNode);
|
|
135
|
+
const typeResolvers = exeContext.resolvers[typeName];
|
|
136
|
+
resolveFn = (typeResolvers == null ? void 0 : typeResolvers[fieldName]).subscribe;
|
|
137
|
+
}
|
|
138
|
+
if (!resolveFn) {
|
|
139
|
+
resolveFn = exeContext.fieldResolver;
|
|
140
|
+
}
|
|
141
|
+
const path = (0, import_Path.addPath)(void 0, responseName, typeName);
|
|
142
|
+
const info = (0, import_executeWithoutSchema.buildResolveInfo)(exeContext, fieldName, fieldNodes, typeName, returnTypeName, returnTypeNode, path);
|
|
143
|
+
try {
|
|
144
|
+
const args = (0, import_values.getArgumentValues)(resolvers, fieldNodes[0], variableValues);
|
|
145
|
+
const contextValue = exeContext.contextValue;
|
|
146
|
+
const eventStream = yield resolveFn(rootValue, args, contextValue, info);
|
|
147
|
+
if (eventStream instanceof Error) {
|
|
148
|
+
throw eventStream;
|
|
149
|
+
}
|
|
150
|
+
return eventStream;
|
|
151
|
+
} catch (error) {
|
|
152
|
+
throw (0, import_graphql.locatedError)(error, fieldNodes, (0, import_Path.pathToArray)(path));
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/subscribeWithoutSchema.ts
|
|
23
|
+
import {inspect} from "./jsutils/inspect.mjs";
|
|
24
|
+
import {isAsyncIterable} from "./jsutils/isAsyncIterable.mjs";
|
|
25
|
+
import {addPath, pathToArray} from "./jsutils/Path.mjs";
|
|
26
|
+
import {
|
|
27
|
+
GraphQLError,
|
|
28
|
+
locatedError,
|
|
29
|
+
Kind
|
|
30
|
+
} from "graphql";
|
|
31
|
+
import {
|
|
32
|
+
assertValidExecutionArguments,
|
|
33
|
+
buildExecutionContext,
|
|
34
|
+
buildResolveInfo,
|
|
35
|
+
executeWithoutSchema,
|
|
36
|
+
getOperationRootTypeName
|
|
37
|
+
} from "./executeWithoutSchema.mjs";
|
|
38
|
+
import {collectFields} from "./collectFields.mjs";
|
|
39
|
+
import {getArgumentValues} from "./values.mjs";
|
|
40
|
+
import {typeNameFromAST} from "./utilities/typeNameFromAST.mjs";
|
|
41
|
+
import {mapAsyncIterator} from "./utilities/mapAsyncIterator.mjs";
|
|
42
|
+
function subscribeWithoutSchema(args) {
|
|
43
|
+
return __async(this, null, function* () {
|
|
44
|
+
const {
|
|
45
|
+
resolvers,
|
|
46
|
+
document,
|
|
47
|
+
rootValue,
|
|
48
|
+
contextValue,
|
|
49
|
+
variableValues,
|
|
50
|
+
operationName,
|
|
51
|
+
fieldResolver,
|
|
52
|
+
subscribeFieldResolver
|
|
53
|
+
} = args;
|
|
54
|
+
const resultOrStream = yield createSourceEventStream(resolvers, document, rootValue, contextValue, variableValues, operationName, subscribeFieldResolver);
|
|
55
|
+
if (!isAsyncIterable(resultOrStream)) {
|
|
56
|
+
return resultOrStream;
|
|
57
|
+
}
|
|
58
|
+
const mapSourceToResponse = (payload) => executeWithoutSchema({
|
|
59
|
+
resolvers,
|
|
60
|
+
document,
|
|
61
|
+
rootValue: payload,
|
|
62
|
+
contextValue,
|
|
63
|
+
variableValues,
|
|
64
|
+
operationName,
|
|
65
|
+
fieldResolver
|
|
66
|
+
});
|
|
67
|
+
return mapAsyncIterator(resultOrStream, mapSourceToResponse);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function createSourceEventStream(resolvers, document, rootValue, contextValue, variableValues, operationName, fieldResolver) {
|
|
71
|
+
return __async(this, null, function* () {
|
|
72
|
+
assertValidExecutionArguments(document, variableValues);
|
|
73
|
+
try {
|
|
74
|
+
const exeContext = buildExecutionContext(resolvers, document, rootValue, contextValue, variableValues, operationName, fieldResolver);
|
|
75
|
+
if (!("resolvers" in exeContext)) {
|
|
76
|
+
return {errors: exeContext};
|
|
77
|
+
}
|
|
78
|
+
const eventStream = yield executeSubscription(exeContext);
|
|
79
|
+
if (!isAsyncIterable(eventStream)) {
|
|
80
|
+
throw new Error(`Subscription field must return Async Iterable. Received: ${inspect(eventStream)}.`);
|
|
81
|
+
}
|
|
82
|
+
return eventStream;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof GraphQLError) {
|
|
85
|
+
return {errors: [error]};
|
|
86
|
+
}
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function executeSubscription(exeContext) {
|
|
92
|
+
return __async(this, null, function* () {
|
|
93
|
+
const {
|
|
94
|
+
resolvers,
|
|
95
|
+
fragments,
|
|
96
|
+
operation,
|
|
97
|
+
variableValues,
|
|
98
|
+
rootValue
|
|
99
|
+
} = exeContext;
|
|
100
|
+
const typeName = getOperationRootTypeName(operation);
|
|
101
|
+
const fields = collectFields(resolvers, fragments, variableValues, typeName, operation.selectionSet, new Map(), new Set());
|
|
102
|
+
const [responseName, fieldNodes] = [...fields.entries()][0];
|
|
103
|
+
const fieldName = fieldNodes[0].name.value;
|
|
104
|
+
let resolveFn;
|
|
105
|
+
let returnTypeName;
|
|
106
|
+
let returnTypeNode;
|
|
107
|
+
if (fieldName === "__typename" && !resolveFn) {
|
|
108
|
+
resolveFn = () => typeName;
|
|
109
|
+
returnTypeName = "String";
|
|
110
|
+
returnTypeNode = {
|
|
111
|
+
kind: Kind.NAMED_TYPE,
|
|
112
|
+
name: {
|
|
113
|
+
kind: Kind.NAME,
|
|
114
|
+
value: "String"
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
} else {
|
|
118
|
+
returnTypeNode = fieldNodes[0].__type;
|
|
119
|
+
returnTypeName = typeNameFromAST(returnTypeNode);
|
|
120
|
+
const typeResolvers = exeContext.resolvers[typeName];
|
|
121
|
+
resolveFn = (typeResolvers == null ? void 0 : typeResolvers[fieldName]).subscribe;
|
|
122
|
+
}
|
|
123
|
+
if (!resolveFn) {
|
|
124
|
+
resolveFn = exeContext.fieldResolver;
|
|
125
|
+
}
|
|
126
|
+
const path = addPath(void 0, responseName, typeName);
|
|
127
|
+
const info = buildResolveInfo(exeContext, fieldName, fieldNodes, typeName, returnTypeName, returnTypeNode, path);
|
|
128
|
+
try {
|
|
129
|
+
const args = getArgumentValues(resolvers, fieldNodes[0], variableValues);
|
|
130
|
+
const contextValue = exeContext.contextValue;
|
|
131
|
+
const eventStream = yield resolveFn(rootValue, args, contextValue, info);
|
|
132
|
+
if (eventStream instanceof Error) {
|
|
133
|
+
throw eventStream;
|
|
134
|
+
}
|
|
135
|
+
return eventStream;
|
|
136
|
+
} catch (error) {
|
|
137
|
+
throw locatedError(error, fieldNodes, pathToArray(path));
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
createSourceEventStream,
|
|
143
|
+
subscribeWithoutSchema
|
|
144
|
+
};
|
package/lib/types.d.ts
CHANGED
|
@@ -6,7 +6,11 @@ import { ObjMap } from "./jsutils/ObjMap";
|
|
|
6
6
|
import { Path } from "./jsutils/Path";
|
|
7
7
|
export declare type ScalarTypeResolver = GraphQLScalarType;
|
|
8
8
|
export declare type EnumTypeResolver = GraphQLEnumType;
|
|
9
|
-
export declare type
|
|
9
|
+
export declare type FunctionFieldResolver<TSource, TContext, TArgs = Record<string, any>, TReturn = any> = (source: TSource, args: TArgs, context: TContext, info: ResolveInfo) => TReturn;
|
|
10
|
+
export declare type FieldResolver<TSource, TContext, TArgs = Record<string, any>, TReturn = any> = FunctionFieldResolver<TSource, TContext, TArgs, TReturn> | {
|
|
11
|
+
subscribe?: FunctionFieldResolver<TSource, TContext, TArgs, TReturn>;
|
|
12
|
+
resolve?: FunctionFieldResolver<TSource, TContext, TArgs, TReturn>;
|
|
13
|
+
};
|
|
10
14
|
export declare type TypeResolver<TSource, TContext> = (value: TSource, context: TContext, info: ResolveInfo) => PromiseOrValue<Maybe<string>>;
|
|
11
15
|
export declare type ObjectTypeResolver<TSource = any, TContext = any, TArgs = any> = {
|
|
12
16
|
[key: string]: FieldResolver<TSource, TContext, TArgs>;
|
|
@@ -61,8 +65,9 @@ export interface CommonExecutionArgs {
|
|
|
61
65
|
[variable: string]: unknown;
|
|
62
66
|
}>;
|
|
63
67
|
operationName?: Maybe<string>;
|
|
64
|
-
fieldResolver?: Maybe<
|
|
68
|
+
fieldResolver?: Maybe<FunctionFieldResolver<any, any>>;
|
|
65
69
|
typeResolver?: Maybe<TypeResolver<any, any>>;
|
|
70
|
+
subscribeFieldResolver?: Maybe<FunctionFieldResolver<any, any>>;
|
|
66
71
|
}
|
|
67
72
|
export declare type ExecutionWithoutSchemaArgs = CommonExecutionArgs & {
|
|
68
73
|
document: DocumentNode;
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EAEjB,YAAY,IAAI,mBAAmB,EACpC,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,cAAc,EA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B;IAClC,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,KAAK,CAAC;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC,CAAC;IACxD,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,aAAa,CAAC,EAAE,KAAK,CAAC,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IACvD,YAAY,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC7C,sBAAsB,CAAC,EAAE,KAAK,CAAC,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;CACjE;AACD,oBAAY,0BAA0B,GAAG,mBAAmB,GAAG;IAC7D,QAAQ,EAAE,YAAY,CAAC;CACxB,CAAC;AAEF,oBAAY,uBAAuB,GAAG,mBAAmB,GAAG;IAC1D,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,QAAQ,EAAE,mBAAmB,CAAC;CAC/B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PromiseOrValue } from "../jsutils/PromiseOrValue";
|
|
2
|
+
/**
|
|
3
|
+
* Given an AsyncIterable and a callback function, return an AsyncIterator
|
|
4
|
+
* which produces values mapped via calling the callback function.
|
|
5
|
+
*/
|
|
6
|
+
export declare function mapAsyncIterator<T, U, R = undefined>(iterable: AsyncGenerator<T, R, void> | AsyncIterable<T>, callback: (value: T) => PromiseOrValue<U>): AsyncGenerator<U, R, void>;
|
|
7
|
+
//# sourceMappingURL=mapAsyncIterator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapAsyncIterator.d.ts","sourceRoot":"","sources":["../../src/utilities/mapAsyncIterator.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,EAClD,QAAQ,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,EACvD,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,GACxC,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CA4C5B"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
6
|
+
};
|
|
7
|
+
var __async = (__this, __arguments, generator) => {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
var fulfilled = (value) => {
|
|
10
|
+
try {
|
|
11
|
+
step(generator.next(value));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
reject(e);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var rejected = (value) => {
|
|
17
|
+
try {
|
|
18
|
+
step(generator.throw(value));
|
|
19
|
+
} catch (e) {
|
|
20
|
+
reject(e);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
24
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
__markAsModule(exports);
|
|
28
|
+
__export(exports, {
|
|
29
|
+
mapAsyncIterator: () => mapAsyncIterator
|
|
30
|
+
});
|
|
31
|
+
function mapAsyncIterator(iterable, callback) {
|
|
32
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
33
|
+
function mapResult(result) {
|
|
34
|
+
return __async(this, null, function* () {
|
|
35
|
+
if (result.done) {
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
return {value: yield callback(result.value), done: false};
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (typeof iterator.return === "function") {
|
|
42
|
+
try {
|
|
43
|
+
yield iterator.return();
|
|
44
|
+
} catch (_e) {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
next() {
|
|
53
|
+
return __async(this, null, function* () {
|
|
54
|
+
return mapResult(yield iterator.next());
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
return() {
|
|
58
|
+
return __async(this, null, function* () {
|
|
59
|
+
return typeof iterator.return === "function" ? mapResult(yield iterator.return()) : {value: void 0, done: true};
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
throw(error) {
|
|
63
|
+
return __async(this, null, function* () {
|
|
64
|
+
return typeof iterator.throw === "function" ? mapResult(yield iterator.throw(error)) : Promise.reject(error);
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
[Symbol.asyncIterator]() {
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|