Initial Save
This commit is contained in:
6
node_modules/graphql/subscription/asyncIteratorReject.d.ts
generated
vendored
Normal file
6
node_modules/graphql/subscription/asyncIteratorReject.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Given an error, returns an AsyncIterable which will fail with that error.
|
||||
*
|
||||
* Similar to Promise.reject(error)
|
||||
*/
|
||||
export default function asyncIteratorReject(error: Error): AsyncIterator<void>;
|
||||
45
node_modules/graphql/subscription/asyncIteratorReject.js
generated
vendored
Normal file
45
node_modules/graphql/subscription/asyncIteratorReject.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = asyncIteratorReject;
|
||||
|
||||
var _iterall = require("iterall");
|
||||
|
||||
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; }
|
||||
|
||||
/**
|
||||
* Given an error, returns an AsyncIterable which will fail with that error.
|
||||
*
|
||||
* Similar to Promise.reject(error)
|
||||
*/
|
||||
function asyncIteratorReject(error) {
|
||||
var isComplete = false;
|
||||
/* TODO: Flow doesn't support symbols as keys:
|
||||
https://github.com/facebook/flow/issues/3258 */
|
||||
|
||||
return _defineProperty({
|
||||
next: function next() {
|
||||
var result = isComplete ? Promise.resolve({
|
||||
value: undefined,
|
||||
done: true
|
||||
}) : Promise.reject(error);
|
||||
isComplete = true;
|
||||
return result;
|
||||
},
|
||||
return: function _return() {
|
||||
isComplete = true;
|
||||
return Promise.resolve({
|
||||
value: undefined,
|
||||
done: true
|
||||
});
|
||||
},
|
||||
throw: function _throw() {
|
||||
isComplete = true;
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}, _iterall.$$asyncIterator, function () {
|
||||
return this;
|
||||
});
|
||||
}
|
||||
34
node_modules/graphql/subscription/asyncIteratorReject.js.flow
generated
vendored
Normal file
34
node_modules/graphql/subscription/asyncIteratorReject.js.flow
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
// @flow strict
|
||||
|
||||
import { $$asyncIterator } from 'iterall';
|
||||
|
||||
/**
|
||||
* Given an error, returns an AsyncIterable which will fail with that error.
|
||||
*
|
||||
* Similar to Promise.reject(error)
|
||||
*/
|
||||
export default function asyncIteratorReject(error: Error): AsyncIterator<void> {
|
||||
let isComplete = false;
|
||||
/* TODO: Flow doesn't support symbols as keys:
|
||||
https://github.com/facebook/flow/issues/3258 */
|
||||
return ({
|
||||
next() {
|
||||
const result = isComplete
|
||||
? Promise.resolve({ value: undefined, done: true })
|
||||
: Promise.reject(error);
|
||||
isComplete = true;
|
||||
return result;
|
||||
},
|
||||
return() {
|
||||
isComplete = true;
|
||||
return Promise.resolve({ value: undefined, done: true });
|
||||
},
|
||||
throw() {
|
||||
isComplete = true;
|
||||
return Promise.reject(error);
|
||||
},
|
||||
[$$asyncIterator]() {
|
||||
return this;
|
||||
},
|
||||
}: any);
|
||||
}
|
||||
38
node_modules/graphql/subscription/asyncIteratorReject.mjs
generated
vendored
Normal file
38
node_modules/graphql/subscription/asyncIteratorReject.mjs
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
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; }
|
||||
|
||||
import { $$asyncIterator } from 'iterall';
|
||||
/**
|
||||
* Given an error, returns an AsyncIterable which will fail with that error.
|
||||
*
|
||||
* Similar to Promise.reject(error)
|
||||
*/
|
||||
|
||||
export default function asyncIteratorReject(error) {
|
||||
var isComplete = false;
|
||||
/* TODO: Flow doesn't support symbols as keys:
|
||||
https://github.com/facebook/flow/issues/3258 */
|
||||
|
||||
return _defineProperty({
|
||||
next: function next() {
|
||||
var result = isComplete ? Promise.resolve({
|
||||
value: undefined,
|
||||
done: true
|
||||
}) : Promise.reject(error);
|
||||
isComplete = true;
|
||||
return result;
|
||||
},
|
||||
return: function _return() {
|
||||
isComplete = true;
|
||||
return Promise.resolve({
|
||||
value: undefined,
|
||||
done: true
|
||||
});
|
||||
},
|
||||
throw: function _throw() {
|
||||
isComplete = true;
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}, $$asyncIterator, function () {
|
||||
return this;
|
||||
});
|
||||
}
|
||||
5
node_modules/graphql/subscription/index.d.ts
generated
vendored
Normal file
5
node_modules/graphql/subscription/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export {
|
||||
subscribe,
|
||||
createSourceEventStream,
|
||||
SubscriptionArgs,
|
||||
} from './subscribe';
|
||||
19
node_modules/graphql/subscription/index.js
generated
vendored
Normal file
19
node_modules/graphql/subscription/index.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "subscribe", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _subscribe.subscribe;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "createSourceEventStream", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _subscribe.createSourceEventStream;
|
||||
}
|
||||
});
|
||||
|
||||
var _subscribe = require("./subscribe");
|
||||
4
node_modules/graphql/subscription/index.js.flow
generated
vendored
Normal file
4
node_modules/graphql/subscription/index.js.flow
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
// @flow strict
|
||||
|
||||
export { subscribe, createSourceEventStream } from './subscribe';
|
||||
export type { SubscriptionArgs } from './subscribe';
|
||||
1
node_modules/graphql/subscription/index.mjs
generated
vendored
Normal file
1
node_modules/graphql/subscription/index.mjs
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export { subscribe, createSourceEventStream } from './subscribe';
|
||||
11
node_modules/graphql/subscription/mapAsyncIterator.d.ts
generated
vendored
Normal file
11
node_modules/graphql/subscription/mapAsyncIterator.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { PromiseOrValue } from '../jsutils/PromiseOrValue';
|
||||
|
||||
/**
|
||||
* Given an AsyncIterable and a callback function, return an AsyncIterator
|
||||
* which produces values mapped via calling the callback function.
|
||||
*/
|
||||
export default function mapAsyncIterator<T, U>(
|
||||
iterable: AsyncIterable<T>,
|
||||
callback: (arg: T) => PromiseOrValue<U>,
|
||||
rejectCallback?: (arg: any) => PromiseOrValue<U>,
|
||||
): any; // TS_SPECIFIC: es2018.asyncgenerator requires typescript@3.6
|
||||
85
node_modules/graphql/subscription/mapAsyncIterator.js
generated
vendored
Normal file
85
node_modules/graphql/subscription/mapAsyncIterator.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = mapAsyncIterator;
|
||||
|
||||
var _iterall = require("iterall");
|
||||
|
||||
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; }
|
||||
|
||||
/**
|
||||
* Given an AsyncIterable and a callback function, return an AsyncIterator
|
||||
* which produces values mapped via calling the callback function.
|
||||
*/
|
||||
function mapAsyncIterator(iterable, callback, rejectCallback) {
|
||||
var iterator = (0, _iterall.getAsyncIterator)(iterable);
|
||||
var $return;
|
||||
var abruptClose; // $FlowFixMe(>=0.68.0)
|
||||
|
||||
if (typeof iterator.return === 'function') {
|
||||
$return = iterator.return;
|
||||
|
||||
abruptClose = function abruptClose(error) {
|
||||
var rethrow = function rethrow() {
|
||||
return Promise.reject(error);
|
||||
};
|
||||
|
||||
return $return.call(iterator).then(rethrow, rethrow);
|
||||
};
|
||||
}
|
||||
|
||||
function mapResult(result) {
|
||||
return result.done ? result : asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);
|
||||
}
|
||||
|
||||
var mapReject;
|
||||
|
||||
if (rejectCallback) {
|
||||
// Capture rejectCallback to ensure it cannot be null.
|
||||
var reject = rejectCallback;
|
||||
|
||||
mapReject = function mapReject(error) {
|
||||
return asyncMapValue(error, reject).then(iteratorResult, abruptClose);
|
||||
};
|
||||
}
|
||||
/* TODO: Flow doesn't support symbols as keys:
|
||||
https://github.com/facebook/flow/issues/3258 */
|
||||
|
||||
|
||||
return _defineProperty({
|
||||
next: function next() {
|
||||
return iterator.next().then(mapResult, mapReject);
|
||||
},
|
||||
return: function _return() {
|
||||
return $return ? $return.call(iterator).then(mapResult, mapReject) : Promise.resolve({
|
||||
value: undefined,
|
||||
done: true
|
||||
});
|
||||
},
|
||||
throw: function _throw(error) {
|
||||
// $FlowFixMe(>=0.68.0)
|
||||
if (typeof iterator.throw === 'function') {
|
||||
return iterator.throw(error).then(mapResult, mapReject);
|
||||
}
|
||||
|
||||
return Promise.reject(error).catch(abruptClose);
|
||||
}
|
||||
}, _iterall.$$asyncIterator, function () {
|
||||
return this;
|
||||
});
|
||||
}
|
||||
|
||||
function asyncMapValue(value, callback) {
|
||||
return new Promise(function (resolve) {
|
||||
return resolve(callback(value));
|
||||
});
|
||||
}
|
||||
|
||||
function iteratorResult(value) {
|
||||
return {
|
||||
value: value,
|
||||
done: false
|
||||
};
|
||||
}
|
||||
75
node_modules/graphql/subscription/mapAsyncIterator.js.flow
generated
vendored
Normal file
75
node_modules/graphql/subscription/mapAsyncIterator.js.flow
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
// @flow strict
|
||||
|
||||
import { $$asyncIterator, getAsyncIterator } from 'iterall';
|
||||
|
||||
import { type PromiseOrValue } from '../jsutils/PromiseOrValue';
|
||||
|
||||
/**
|
||||
* Given an AsyncIterable and a callback function, return an AsyncIterator
|
||||
* which produces values mapped via calling the callback function.
|
||||
*/
|
||||
export default function mapAsyncIterator<T, U>(
|
||||
iterable: AsyncIterable<T>,
|
||||
callback: T => PromiseOrValue<U>,
|
||||
rejectCallback?: any => PromiseOrValue<U>,
|
||||
): AsyncGenerator<U, void, void> {
|
||||
const iterator = getAsyncIterator(iterable);
|
||||
let $return;
|
||||
let abruptClose;
|
||||
// $FlowFixMe(>=0.68.0)
|
||||
if (typeof iterator.return === 'function') {
|
||||
$return = iterator.return;
|
||||
abruptClose = error => {
|
||||
const rethrow = () => Promise.reject(error);
|
||||
return $return.call(iterator).then(rethrow, rethrow);
|
||||
};
|
||||
}
|
||||
|
||||
function mapResult(result) {
|
||||
return result.done
|
||||
? result
|
||||
: asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);
|
||||
}
|
||||
|
||||
let mapReject;
|
||||
if (rejectCallback) {
|
||||
// Capture rejectCallback to ensure it cannot be null.
|
||||
const reject = rejectCallback;
|
||||
mapReject = error =>
|
||||
asyncMapValue(error, reject).then(iteratorResult, abruptClose);
|
||||
}
|
||||
|
||||
/* TODO: Flow doesn't support symbols as keys:
|
||||
https://github.com/facebook/flow/issues/3258 */
|
||||
return ({
|
||||
next() {
|
||||
return iterator.next().then(mapResult, mapReject);
|
||||
},
|
||||
return() {
|
||||
return $return
|
||||
? $return.call(iterator).then(mapResult, mapReject)
|
||||
: Promise.resolve({ value: undefined, done: true });
|
||||
},
|
||||
throw(error) {
|
||||
// $FlowFixMe(>=0.68.0)
|
||||
if (typeof iterator.throw === 'function') {
|
||||
return iterator.throw(error).then(mapResult, mapReject);
|
||||
}
|
||||
return Promise.reject(error).catch(abruptClose);
|
||||
},
|
||||
[$$asyncIterator]() {
|
||||
return this;
|
||||
},
|
||||
}: any);
|
||||
}
|
||||
|
||||
function asyncMapValue<T, U>(
|
||||
value: T,
|
||||
callback: T => PromiseOrValue<U>,
|
||||
): Promise<U> {
|
||||
return new Promise(resolve => resolve(callback(value)));
|
||||
}
|
||||
|
||||
function iteratorResult<T>(value: T): IteratorResult<T, void> {
|
||||
return { value, done: false };
|
||||
}
|
||||
78
node_modules/graphql/subscription/mapAsyncIterator.mjs
generated
vendored
Normal file
78
node_modules/graphql/subscription/mapAsyncIterator.mjs
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
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; }
|
||||
|
||||
import { $$asyncIterator, getAsyncIterator } from 'iterall';
|
||||
|
||||
/**
|
||||
* Given an AsyncIterable and a callback function, return an AsyncIterator
|
||||
* which produces values mapped via calling the callback function.
|
||||
*/
|
||||
export default function mapAsyncIterator(iterable, callback, rejectCallback) {
|
||||
var iterator = getAsyncIterator(iterable);
|
||||
var $return;
|
||||
var abruptClose; // $FlowFixMe(>=0.68.0)
|
||||
|
||||
if (typeof iterator.return === 'function') {
|
||||
$return = iterator.return;
|
||||
|
||||
abruptClose = function abruptClose(error) {
|
||||
var rethrow = function rethrow() {
|
||||
return Promise.reject(error);
|
||||
};
|
||||
|
||||
return $return.call(iterator).then(rethrow, rethrow);
|
||||
};
|
||||
}
|
||||
|
||||
function mapResult(result) {
|
||||
return result.done ? result : asyncMapValue(result.value, callback).then(iteratorResult, abruptClose);
|
||||
}
|
||||
|
||||
var mapReject;
|
||||
|
||||
if (rejectCallback) {
|
||||
// Capture rejectCallback to ensure it cannot be null.
|
||||
var reject = rejectCallback;
|
||||
|
||||
mapReject = function mapReject(error) {
|
||||
return asyncMapValue(error, reject).then(iteratorResult, abruptClose);
|
||||
};
|
||||
}
|
||||
/* TODO: Flow doesn't support symbols as keys:
|
||||
https://github.com/facebook/flow/issues/3258 */
|
||||
|
||||
|
||||
return _defineProperty({
|
||||
next: function next() {
|
||||
return iterator.next().then(mapResult, mapReject);
|
||||
},
|
||||
return: function _return() {
|
||||
return $return ? $return.call(iterator).then(mapResult, mapReject) : Promise.resolve({
|
||||
value: undefined,
|
||||
done: true
|
||||
});
|
||||
},
|
||||
throw: function _throw(error) {
|
||||
// $FlowFixMe(>=0.68.0)
|
||||
if (typeof iterator.throw === 'function') {
|
||||
return iterator.throw(error).then(mapResult, mapReject);
|
||||
}
|
||||
|
||||
return Promise.reject(error).catch(abruptClose);
|
||||
}
|
||||
}, $$asyncIterator, function () {
|
||||
return this;
|
||||
});
|
||||
}
|
||||
|
||||
function asyncMapValue(value, callback) {
|
||||
return new Promise(function (resolve) {
|
||||
return resolve(callback(value));
|
||||
});
|
||||
}
|
||||
|
||||
function iteratorResult(value) {
|
||||
return {
|
||||
value: value,
|
||||
done: false
|
||||
};
|
||||
}
|
||||
86
node_modules/graphql/subscription/subscribe.d.ts
generated
vendored
Normal file
86
node_modules/graphql/subscription/subscribe.d.ts
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
import Maybe from '../tsutils/Maybe';
|
||||
import { DocumentNode } from '../language/ast';
|
||||
import {
|
||||
ExecutionResult,
|
||||
ExecutionResultDataDefault,
|
||||
} from '../execution/execute';
|
||||
import { GraphQLSchema } from '../type/schema';
|
||||
import { GraphQLFieldResolver } from '../type/definition';
|
||||
|
||||
export interface SubscriptionArgs {
|
||||
schema: GraphQLSchema;
|
||||
document: DocumentNode;
|
||||
rootValue?: any;
|
||||
contextValue?: any;
|
||||
variableValues?: Maybe<Record<string, any>>;
|
||||
operationName?: Maybe<string>;
|
||||
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
|
||||
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the "Subscribe" algorithm described in the GraphQL specification.
|
||||
*
|
||||
* Returns a Promise which resolves to either an AsyncIterator (if successful)
|
||||
* or an ExecutionResult (client error). The promise will be rejected if a
|
||||
* server error occurs.
|
||||
*
|
||||
* If the client-provided arguments to this function do not result in a
|
||||
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
||||
* descriptive errors and no data will be returned.
|
||||
*
|
||||
* If the the source stream could not be created due to faulty subscription
|
||||
* resolver logic or underlying systems, the promise will resolve to a single
|
||||
* ExecutionResult containing `errors` and no `data`.
|
||||
*
|
||||
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
||||
* yields a stream of ExecutionResults representing the response stream.
|
||||
*
|
||||
* Accepts either an object with named arguments, or individual arguments.
|
||||
*/
|
||||
export function subscribe<TData = ExecutionResultDataDefault>(
|
||||
args: SubscriptionArgs,
|
||||
): Promise<
|
||||
AsyncIterableIterator<ExecutionResult<TData>> | ExecutionResult<TData>
|
||||
>;
|
||||
|
||||
export function subscribe<TData = ExecutionResultDataDefault>(
|
||||
schema: GraphQLSchema,
|
||||
document: DocumentNode,
|
||||
rootValue?: any,
|
||||
contextValue?: any,
|
||||
variableValues?: Maybe<{ [key: string]: any }>,
|
||||
operationName?: Maybe<string>,
|
||||
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
|
||||
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
|
||||
): Promise<
|
||||
AsyncIterableIterator<ExecutionResult<TData>> | ExecutionResult<TData>
|
||||
>;
|
||||
|
||||
/**
|
||||
* Implements the "CreateSourceEventStream" algorithm described in the
|
||||
* GraphQL specification, resolving the subscription source event stream.
|
||||
*
|
||||
* Returns a Promise<AsyncIterable>.
|
||||
*
|
||||
* If the client-provided invalid arguments, the source stream could not be
|
||||
* created, or the resolver did not return an AsyncIterable, this function will
|
||||
* will throw an error, which should be caught and handled by the caller.
|
||||
*
|
||||
* A Source Event Stream represents a sequence of events, each of which triggers
|
||||
* a GraphQL execution for that event.
|
||||
*
|
||||
* This may be useful when hosting the stateful subscription service in a
|
||||
* different process or machine than the stateless GraphQL execution engine,
|
||||
* or otherwise separating these two steps. For more on this, see the
|
||||
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
||||
*/
|
||||
export function createSourceEventStream<TData = ExecutionResultDataDefault>(
|
||||
schema: GraphQLSchema,
|
||||
document: DocumentNode,
|
||||
rootValue?: any,
|
||||
contextValue?: any,
|
||||
variableValues?: { [key: string]: any },
|
||||
operationName?: Maybe<string>,
|
||||
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
|
||||
): Promise<AsyncIterable<any> | ExecutionResult<TData>>;
|
||||
179
node_modules/graphql/subscription/subscribe.js
generated
vendored
Normal file
179
node_modules/graphql/subscription/subscribe.js
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.subscribe = subscribe;
|
||||
exports.createSourceEventStream = createSourceEventStream;
|
||||
|
||||
var _iterall = require("iterall");
|
||||
|
||||
var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
||||
|
||||
var _Path = require("../jsutils/Path");
|
||||
|
||||
var _GraphQLError = require("../error/GraphQLError");
|
||||
|
||||
var _locatedError = require("../error/locatedError");
|
||||
|
||||
var _execute = require("../execution/execute");
|
||||
|
||||
var _getOperationRootType = require("../utilities/getOperationRootType");
|
||||
|
||||
var _mapAsyncIterator = _interopRequireDefault(require("./mapAsyncIterator"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function subscribe(argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) {
|
||||
/* eslint-enable no-redeclare */
|
||||
// Extract arguments from object args if provided.
|
||||
return arguments.length === 1 ? subscribeImpl(argsOrSchema) : subscribeImpl({
|
||||
schema: argsOrSchema,
|
||||
document: document,
|
||||
rootValue: rootValue,
|
||||
contextValue: contextValue,
|
||||
variableValues: variableValues,
|
||||
operationName: operationName,
|
||||
fieldResolver: fieldResolver,
|
||||
subscribeFieldResolver: subscribeFieldResolver
|
||||
});
|
||||
}
|
||||
/**
|
||||
* This function checks if the error is a GraphQLError. If it is, report it as
|
||||
* an ExecutionResult, containing only errors and no data. Otherwise treat the
|
||||
* error as a system-class error and re-throw it.
|
||||
*/
|
||||
|
||||
|
||||
function reportGraphQLError(error) {
|
||||
if (error instanceof _GraphQLError.GraphQLError) {
|
||||
return {
|
||||
errors: [error]
|
||||
};
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
function subscribeImpl(args) {
|
||||
var schema = args.schema,
|
||||
document = args.document,
|
||||
rootValue = args.rootValue,
|
||||
contextValue = args.contextValue,
|
||||
variableValues = args.variableValues,
|
||||
operationName = args.operationName,
|
||||
fieldResolver = args.fieldResolver,
|
||||
subscribeFieldResolver = args.subscribeFieldResolver;
|
||||
var sourcePromise = createSourceEventStream(schema, document, rootValue, contextValue, variableValues, operationName, subscribeFieldResolver); // For each payload yielded from a subscription, map it over the normal
|
||||
// GraphQL `execute` function, with `payload` as the rootValue.
|
||||
// This implements the "MapSourceToResponseEvent" algorithm described in
|
||||
// the GraphQL specification. The `execute` function provides the
|
||||
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
||||
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
||||
|
||||
var mapSourceToResponse = function mapSourceToResponse(payload) {
|
||||
return (0, _execute.execute)(schema, document, payload, contextValue, variableValues, operationName, fieldResolver);
|
||||
}; // Resolve the Source Stream, then map every source value to a
|
||||
// ExecutionResult value as described above.
|
||||
|
||||
|
||||
return sourcePromise.then(function (resultOrStream) {
|
||||
return (// Note: Flow can't refine isAsyncIterable, so explicit casts are used.
|
||||
(0, _iterall.isAsyncIterable)(resultOrStream) ? (0, _mapAsyncIterator.default)(resultOrStream, mapSourceToResponse, reportGraphQLError) : resultOrStream
|
||||
);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Implements the "CreateSourceEventStream" algorithm described in the
|
||||
* GraphQL specification, resolving the subscription source event stream.
|
||||
*
|
||||
* Returns a Promise which resolves to either an AsyncIterable (if successful)
|
||||
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
||||
* other arguments to this function are invalid, or if the resolved event stream
|
||||
* is not an async iterable.
|
||||
*
|
||||
* If the client-provided arguments to this function do not result in a
|
||||
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
||||
* descriptive errors and no data will be returned.
|
||||
*
|
||||
* If the the source stream could not be created due to faulty subscription
|
||||
* resolver logic or underlying systems, the promise will resolve to a single
|
||||
* ExecutionResult containing `errors` and no `data`.
|
||||
*
|
||||
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
||||
* event stream returned by the resolver.
|
||||
*
|
||||
* A Source Event Stream represents a sequence of events, each of which triggers
|
||||
* a GraphQL execution for that event.
|
||||
*
|
||||
* This may be useful when hosting the stateful subscription service in a
|
||||
* different process or machine than the stateless GraphQL execution engine,
|
||||
* or otherwise separating these two steps. For more on this, see the
|
||||
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
||||
*/
|
||||
|
||||
|
||||
function createSourceEventStream(schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver) {
|
||||
// If arguments are missing or incorrectly typed, this is an internal
|
||||
// developer mistake which should throw an early error.
|
||||
(0, _execute.assertValidExecutionArguments)(schema, document, variableValues);
|
||||
|
||||
try {
|
||||
// If a valid context cannot be created due to incorrect arguments,
|
||||
// this will throw an error.
|
||||
var exeContext = (0, _execute.buildExecutionContext)(schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver); // Return early errors if execution context failed.
|
||||
|
||||
if (Array.isArray(exeContext)) {
|
||||
return Promise.resolve({
|
||||
errors: exeContext
|
||||
});
|
||||
}
|
||||
|
||||
var type = (0, _getOperationRootType.getOperationRootType)(schema, exeContext.operation);
|
||||
var fields = (0, _execute.collectFields)(exeContext, type, exeContext.operation.selectionSet, Object.create(null), Object.create(null));
|
||||
var responseNames = Object.keys(fields);
|
||||
var responseName = responseNames[0];
|
||||
var fieldNodes = fields[responseName];
|
||||
var fieldNode = fieldNodes[0];
|
||||
var fieldName = fieldNode.name.value;
|
||||
var fieldDef = (0, _execute.getFieldDef)(schema, type, fieldName);
|
||||
|
||||
if (!fieldDef) {
|
||||
throw new _GraphQLError.GraphQLError("The subscription field \"".concat(fieldName, "\" is not defined."), fieldNodes);
|
||||
} // Call the `subscribe()` resolver or the default resolver to produce an
|
||||
// AsyncIterable yielding raw payloads.
|
||||
|
||||
|
||||
var resolveFn = fieldDef.subscribe || exeContext.fieldResolver;
|
||||
var path = (0, _Path.addPath)(undefined, responseName);
|
||||
var info = (0, _execute.buildResolveInfo)(exeContext, fieldDef, fieldNodes, type, path); // resolveFieldValueOrError implements the "ResolveFieldEventStream"
|
||||
// algorithm from GraphQL specification. It differs from
|
||||
// "ResolveFieldValue" due to providing a different `resolveFn`.
|
||||
|
||||
var result = (0, _execute.resolveFieldValueOrError)(exeContext, fieldDef, fieldNodes, resolveFn, rootValue, info); // Coerce to Promise for easier error handling and consistent return type.
|
||||
|
||||
return Promise.resolve(result).then(function (eventStream) {
|
||||
// If eventStream is an Error, rethrow a located error.
|
||||
if (eventStream instanceof Error) {
|
||||
return {
|
||||
errors: [(0, _locatedError.locatedError)(eventStream, fieldNodes, (0, _Path.pathToArray)(path))]
|
||||
};
|
||||
} // Assert field returned an event stream, otherwise yield an error.
|
||||
|
||||
|
||||
if ((0, _iterall.isAsyncIterable)(eventStream)) {
|
||||
// Note: isAsyncIterable above ensures this will be correct.
|
||||
return eventStream;
|
||||
}
|
||||
|
||||
throw new Error('Subscription field must return Async Iterable. Received: ' + (0, _inspect.default)(eventStream));
|
||||
});
|
||||
} catch (error) {
|
||||
// As with reportGraphQLError above, if the error is a GraphQLError, report
|
||||
// it as an ExecutionResult; otherwise treat it as a system-class error and
|
||||
// re-throw it.
|
||||
return error instanceof _GraphQLError.GraphQLError ? Promise.resolve({
|
||||
errors: [error]
|
||||
}) : Promise.reject(error);
|
||||
}
|
||||
}
|
||||
299
node_modules/graphql/subscription/subscribe.js.flow
generated
vendored
Normal file
299
node_modules/graphql/subscription/subscribe.js.flow
generated
vendored
Normal file
@@ -0,0 +1,299 @@
|
||||
// @flow strict
|
||||
|
||||
import { isAsyncIterable } from 'iterall';
|
||||
|
||||
import inspect from '../jsutils/inspect';
|
||||
import { addPath, pathToArray } from '../jsutils/Path';
|
||||
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
import { locatedError } from '../error/locatedError';
|
||||
|
||||
import { type DocumentNode } from '../language/ast';
|
||||
|
||||
import {
|
||||
type ExecutionResult,
|
||||
assertValidExecutionArguments,
|
||||
buildExecutionContext,
|
||||
buildResolveInfo,
|
||||
collectFields,
|
||||
execute,
|
||||
getFieldDef,
|
||||
resolveFieldValueOrError,
|
||||
} from '../execution/execute';
|
||||
|
||||
import { type GraphQLSchema } from '../type/schema';
|
||||
import { type GraphQLFieldResolver } from '../type/definition';
|
||||
|
||||
import { getOperationRootType } from '../utilities/getOperationRootType';
|
||||
|
||||
import mapAsyncIterator from './mapAsyncIterator';
|
||||
|
||||
export type SubscriptionArgs = {|
|
||||
schema: GraphQLSchema,
|
||||
document: DocumentNode,
|
||||
rootValue?: mixed,
|
||||
contextValue?: mixed,
|
||||
variableValues?: ?{ +[variable: string]: mixed, ... },
|
||||
operationName?: ?string,
|
||||
fieldResolver?: ?GraphQLFieldResolver<any, any>,
|
||||
subscribeFieldResolver?: ?GraphQLFieldResolver<any, any>,
|
||||
|};
|
||||
|
||||
/**
|
||||
* Implements the "Subscribe" algorithm described in the GraphQL specification.
|
||||
*
|
||||
* Returns a Promise which resolves to either an AsyncIterator (if successful)
|
||||
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
||||
* other arguments to this function are invalid, or if the resolved event stream
|
||||
* is not an async iterable.
|
||||
*
|
||||
* If the client-provided arguments to this function do not result in a
|
||||
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
||||
* descriptive errors and no data will be returned.
|
||||
*
|
||||
* If the source stream could not be created due to faulty subscription
|
||||
* resolver logic or underlying systems, the promise will resolve to a single
|
||||
* ExecutionResult containing `errors` and no `data`.
|
||||
*
|
||||
* If the operation succeeded, the promise resolves to an AsyncIterator, which
|
||||
* yields a stream of ExecutionResults representing the response stream.
|
||||
*
|
||||
* Accepts either an object with named arguments, or individual arguments.
|
||||
*/
|
||||
declare function subscribe(
|
||||
SubscriptionArgs,
|
||||
..._: []
|
||||
): Promise<AsyncIterator<ExecutionResult> | ExecutionResult>;
|
||||
/* eslint-disable no-redeclare */
|
||||
declare function subscribe(
|
||||
schema: GraphQLSchema,
|
||||
document: DocumentNode,
|
||||
rootValue?: mixed,
|
||||
contextValue?: mixed,
|
||||
variableValues?: ?{ +[variable: string]: mixed, ... },
|
||||
operationName?: ?string,
|
||||
fieldResolver?: ?GraphQLFieldResolver<any, any>,
|
||||
subscribeFieldResolver?: ?GraphQLFieldResolver<any, any>,
|
||||
): Promise<AsyncIterator<ExecutionResult> | ExecutionResult>;
|
||||
export function subscribe(
|
||||
argsOrSchema,
|
||||
document,
|
||||
rootValue,
|
||||
contextValue,
|
||||
variableValues,
|
||||
operationName,
|
||||
fieldResolver,
|
||||
subscribeFieldResolver,
|
||||
) {
|
||||
/* eslint-enable no-redeclare */
|
||||
// Extract arguments from object args if provided.
|
||||
return arguments.length === 1
|
||||
? subscribeImpl(argsOrSchema)
|
||||
: subscribeImpl({
|
||||
schema: argsOrSchema,
|
||||
document,
|
||||
rootValue,
|
||||
contextValue,
|
||||
variableValues,
|
||||
operationName,
|
||||
fieldResolver,
|
||||
subscribeFieldResolver,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks if the error is a GraphQLError. If it is, report it as
|
||||
* an ExecutionResult, containing only errors and no data. Otherwise treat the
|
||||
* error as a system-class error and re-throw it.
|
||||
*/
|
||||
function reportGraphQLError(error) {
|
||||
if (error instanceof GraphQLError) {
|
||||
return { errors: [error] };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
function subscribeImpl(
|
||||
args: SubscriptionArgs,
|
||||
): Promise<AsyncIterator<ExecutionResult> | ExecutionResult> {
|
||||
const {
|
||||
schema,
|
||||
document,
|
||||
rootValue,
|
||||
contextValue,
|
||||
variableValues,
|
||||
operationName,
|
||||
fieldResolver,
|
||||
subscribeFieldResolver,
|
||||
} = args;
|
||||
|
||||
const sourcePromise = createSourceEventStream(
|
||||
schema,
|
||||
document,
|
||||
rootValue,
|
||||
contextValue,
|
||||
variableValues,
|
||||
operationName,
|
||||
subscribeFieldResolver,
|
||||
);
|
||||
|
||||
// For each payload yielded from a subscription, map it over the normal
|
||||
// GraphQL `execute` function, with `payload` as the rootValue.
|
||||
// This implements the "MapSourceToResponseEvent" algorithm described in
|
||||
// the GraphQL specification. The `execute` function provides the
|
||||
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
||||
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
||||
const mapSourceToResponse = payload =>
|
||||
execute(
|
||||
schema,
|
||||
document,
|
||||
payload,
|
||||
contextValue,
|
||||
variableValues,
|
||||
operationName,
|
||||
fieldResolver,
|
||||
);
|
||||
|
||||
// Resolve the Source Stream, then map every source value to a
|
||||
// ExecutionResult value as described above.
|
||||
return sourcePromise.then(resultOrStream =>
|
||||
// Note: Flow can't refine isAsyncIterable, so explicit casts are used.
|
||||
isAsyncIterable(resultOrStream)
|
||||
? mapAsyncIterator(
|
||||
((resultOrStream: any): AsyncIterable<mixed>),
|
||||
mapSourceToResponse,
|
||||
reportGraphQLError,
|
||||
)
|
||||
: ((resultOrStream: any): ExecutionResult),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the "CreateSourceEventStream" algorithm described in the
|
||||
* GraphQL specification, resolving the subscription source event stream.
|
||||
*
|
||||
* Returns a Promise which resolves to either an AsyncIterable (if successful)
|
||||
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
||||
* other arguments to this function are invalid, or if the resolved event stream
|
||||
* is not an async iterable.
|
||||
*
|
||||
* If the client-provided arguments to this function do not result in a
|
||||
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
||||
* descriptive errors and no data will be returned.
|
||||
*
|
||||
* If the the source stream could not be created due to faulty subscription
|
||||
* resolver logic or underlying systems, the promise will resolve to a single
|
||||
* ExecutionResult containing `errors` and no `data`.
|
||||
*
|
||||
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
||||
* event stream returned by the resolver.
|
||||
*
|
||||
* A Source Event Stream represents a sequence of events, each of which triggers
|
||||
* a GraphQL execution for that event.
|
||||
*
|
||||
* This may be useful when hosting the stateful subscription service in a
|
||||
* different process or machine than the stateless GraphQL execution engine,
|
||||
* or otherwise separating these two steps. For more on this, see the
|
||||
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
||||
*/
|
||||
export function createSourceEventStream(
|
||||
schema: GraphQLSchema,
|
||||
document: DocumentNode,
|
||||
rootValue?: mixed,
|
||||
contextValue?: mixed,
|
||||
variableValues?: ?{ +[variable: string]: mixed, ... },
|
||||
operationName?: ?string,
|
||||
fieldResolver?: ?GraphQLFieldResolver<any, any>,
|
||||
): Promise<AsyncIterable<mixed> | ExecutionResult> {
|
||||
// If arguments are missing or incorrectly typed, this is an internal
|
||||
// developer mistake which should throw an early error.
|
||||
assertValidExecutionArguments(schema, document, variableValues);
|
||||
|
||||
try {
|
||||
// If a valid context cannot be created due to incorrect arguments,
|
||||
// this will throw an error.
|
||||
const exeContext = buildExecutionContext(
|
||||
schema,
|
||||
document,
|
||||
rootValue,
|
||||
contextValue,
|
||||
variableValues,
|
||||
operationName,
|
||||
fieldResolver,
|
||||
);
|
||||
|
||||
// Return early errors if execution context failed.
|
||||
if (Array.isArray(exeContext)) {
|
||||
return Promise.resolve({ errors: exeContext });
|
||||
}
|
||||
|
||||
const type = getOperationRootType(schema, exeContext.operation);
|
||||
const fields = collectFields(
|
||||
exeContext,
|
||||
type,
|
||||
exeContext.operation.selectionSet,
|
||||
Object.create(null),
|
||||
Object.create(null),
|
||||
);
|
||||
const responseNames = Object.keys(fields);
|
||||
const responseName = responseNames[0];
|
||||
const fieldNodes = fields[responseName];
|
||||
const fieldNode = fieldNodes[0];
|
||||
const fieldName = fieldNode.name.value;
|
||||
const fieldDef = getFieldDef(schema, type, fieldName);
|
||||
|
||||
if (!fieldDef) {
|
||||
throw new GraphQLError(
|
||||
`The subscription field "${fieldName}" is not defined.`,
|
||||
fieldNodes,
|
||||
);
|
||||
}
|
||||
|
||||
// Call the `subscribe()` resolver or the default resolver to produce an
|
||||
// AsyncIterable yielding raw payloads.
|
||||
const resolveFn = fieldDef.subscribe || exeContext.fieldResolver;
|
||||
|
||||
const path = addPath(undefined, responseName);
|
||||
|
||||
const info = buildResolveInfo(exeContext, fieldDef, fieldNodes, type, path);
|
||||
|
||||
// resolveFieldValueOrError implements the "ResolveFieldEventStream"
|
||||
// algorithm from GraphQL specification. It differs from
|
||||
// "ResolveFieldValue" due to providing a different `resolveFn`.
|
||||
const result = resolveFieldValueOrError(
|
||||
exeContext,
|
||||
fieldDef,
|
||||
fieldNodes,
|
||||
resolveFn,
|
||||
rootValue,
|
||||
info,
|
||||
);
|
||||
|
||||
// Coerce to Promise for easier error handling and consistent return type.
|
||||
return Promise.resolve(result).then(eventStream => {
|
||||
// If eventStream is an Error, rethrow a located error.
|
||||
if (eventStream instanceof Error) {
|
||||
return {
|
||||
errors: [locatedError(eventStream, fieldNodes, pathToArray(path))],
|
||||
};
|
||||
}
|
||||
|
||||
// Assert field returned an event stream, otherwise yield an error.
|
||||
if (isAsyncIterable(eventStream)) {
|
||||
// Note: isAsyncIterable above ensures this will be correct.
|
||||
return ((eventStream: any): AsyncIterable<mixed>);
|
||||
}
|
||||
throw new Error(
|
||||
'Subscription field must return Async Iterable. Received: ' +
|
||||
inspect(eventStream),
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
// As with reportGraphQLError above, if the error is a GraphQLError, report
|
||||
// it as an ExecutionResult; otherwise treat it as a system-class error and
|
||||
// re-throw it.
|
||||
return error instanceof GraphQLError
|
||||
? Promise.resolve({ errors: [error] })
|
||||
: Promise.reject(error);
|
||||
}
|
||||
}
|
||||
160
node_modules/graphql/subscription/subscribe.mjs
generated
vendored
Normal file
160
node_modules/graphql/subscription/subscribe.mjs
generated
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
import { isAsyncIterable } from 'iterall';
|
||||
import inspect from '../jsutils/inspect';
|
||||
import { addPath, pathToArray } from '../jsutils/Path';
|
||||
import { GraphQLError } from '../error/GraphQLError';
|
||||
import { locatedError } from '../error/locatedError';
|
||||
import { assertValidExecutionArguments, buildExecutionContext, buildResolveInfo, collectFields, execute, getFieldDef, resolveFieldValueOrError } from '../execution/execute';
|
||||
import { getOperationRootType } from '../utilities/getOperationRootType';
|
||||
import mapAsyncIterator from './mapAsyncIterator';
|
||||
export function subscribe(argsOrSchema, document, rootValue, contextValue, variableValues, operationName, fieldResolver, subscribeFieldResolver) {
|
||||
/* eslint-enable no-redeclare */
|
||||
// Extract arguments from object args if provided.
|
||||
return arguments.length === 1 ? subscribeImpl(argsOrSchema) : subscribeImpl({
|
||||
schema: argsOrSchema,
|
||||
document: document,
|
||||
rootValue: rootValue,
|
||||
contextValue: contextValue,
|
||||
variableValues: variableValues,
|
||||
operationName: operationName,
|
||||
fieldResolver: fieldResolver,
|
||||
subscribeFieldResolver: subscribeFieldResolver
|
||||
});
|
||||
}
|
||||
/**
|
||||
* This function checks if the error is a GraphQLError. If it is, report it as
|
||||
* an ExecutionResult, containing only errors and no data. Otherwise treat the
|
||||
* error as a system-class error and re-throw it.
|
||||
*/
|
||||
|
||||
function reportGraphQLError(error) {
|
||||
if (error instanceof GraphQLError) {
|
||||
return {
|
||||
errors: [error]
|
||||
};
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
function subscribeImpl(args) {
|
||||
var schema = args.schema,
|
||||
document = args.document,
|
||||
rootValue = args.rootValue,
|
||||
contextValue = args.contextValue,
|
||||
variableValues = args.variableValues,
|
||||
operationName = args.operationName,
|
||||
fieldResolver = args.fieldResolver,
|
||||
subscribeFieldResolver = args.subscribeFieldResolver;
|
||||
var sourcePromise = createSourceEventStream(schema, document, rootValue, contextValue, variableValues, operationName, subscribeFieldResolver); // For each payload yielded from a subscription, map it over the normal
|
||||
// GraphQL `execute` function, with `payload` as the rootValue.
|
||||
// This implements the "MapSourceToResponseEvent" algorithm described in
|
||||
// the GraphQL specification. The `execute` function provides the
|
||||
// "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
|
||||
// "ExecuteQuery" algorithm, for which `execute` is also used.
|
||||
|
||||
var mapSourceToResponse = function mapSourceToResponse(payload) {
|
||||
return execute(schema, document, payload, contextValue, variableValues, operationName, fieldResolver);
|
||||
}; // Resolve the Source Stream, then map every source value to a
|
||||
// ExecutionResult value as described above.
|
||||
|
||||
|
||||
return sourcePromise.then(function (resultOrStream) {
|
||||
return (// Note: Flow can't refine isAsyncIterable, so explicit casts are used.
|
||||
isAsyncIterable(resultOrStream) ? mapAsyncIterator(resultOrStream, mapSourceToResponse, reportGraphQLError) : resultOrStream
|
||||
);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Implements the "CreateSourceEventStream" algorithm described in the
|
||||
* GraphQL specification, resolving the subscription source event stream.
|
||||
*
|
||||
* Returns a Promise which resolves to either an AsyncIterable (if successful)
|
||||
* or an ExecutionResult (error). The promise will be rejected if the schema or
|
||||
* other arguments to this function are invalid, or if the resolved event stream
|
||||
* is not an async iterable.
|
||||
*
|
||||
* If the client-provided arguments to this function do not result in a
|
||||
* compliant subscription, a GraphQL Response (ExecutionResult) with
|
||||
* descriptive errors and no data will be returned.
|
||||
*
|
||||
* If the the source stream could not be created due to faulty subscription
|
||||
* resolver logic or underlying systems, the promise will resolve to a single
|
||||
* ExecutionResult containing `errors` and no `data`.
|
||||
*
|
||||
* If the operation succeeded, the promise resolves to the AsyncIterable for the
|
||||
* event stream returned by the resolver.
|
||||
*
|
||||
* A Source Event Stream represents a sequence of events, each of which triggers
|
||||
* a GraphQL execution for that event.
|
||||
*
|
||||
* This may be useful when hosting the stateful subscription service in a
|
||||
* different process or machine than the stateless GraphQL execution engine,
|
||||
* or otherwise separating these two steps. For more on this, see the
|
||||
* "Supporting Subscriptions at Scale" information in the GraphQL specification.
|
||||
*/
|
||||
|
||||
|
||||
export function createSourceEventStream(schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver) {
|
||||
// If arguments are missing or incorrectly typed, this is an internal
|
||||
// developer mistake which should throw an early error.
|
||||
assertValidExecutionArguments(schema, document, variableValues);
|
||||
|
||||
try {
|
||||
// If a valid context cannot be created due to incorrect arguments,
|
||||
// this will throw an error.
|
||||
var exeContext = buildExecutionContext(schema, document, rootValue, contextValue, variableValues, operationName, fieldResolver); // Return early errors if execution context failed.
|
||||
|
||||
if (Array.isArray(exeContext)) {
|
||||
return Promise.resolve({
|
||||
errors: exeContext
|
||||
});
|
||||
}
|
||||
|
||||
var type = getOperationRootType(schema, exeContext.operation);
|
||||
var fields = collectFields(exeContext, type, exeContext.operation.selectionSet, Object.create(null), Object.create(null));
|
||||
var responseNames = Object.keys(fields);
|
||||
var responseName = responseNames[0];
|
||||
var fieldNodes = fields[responseName];
|
||||
var fieldNode = fieldNodes[0];
|
||||
var fieldName = fieldNode.name.value;
|
||||
var fieldDef = getFieldDef(schema, type, fieldName);
|
||||
|
||||
if (!fieldDef) {
|
||||
throw new GraphQLError("The subscription field \"".concat(fieldName, "\" is not defined."), fieldNodes);
|
||||
} // Call the `subscribe()` resolver or the default resolver to produce an
|
||||
// AsyncIterable yielding raw payloads.
|
||||
|
||||
|
||||
var resolveFn = fieldDef.subscribe || exeContext.fieldResolver;
|
||||
var path = addPath(undefined, responseName);
|
||||
var info = buildResolveInfo(exeContext, fieldDef, fieldNodes, type, path); // resolveFieldValueOrError implements the "ResolveFieldEventStream"
|
||||
// algorithm from GraphQL specification. It differs from
|
||||
// "ResolveFieldValue" due to providing a different `resolveFn`.
|
||||
|
||||
var result = resolveFieldValueOrError(exeContext, fieldDef, fieldNodes, resolveFn, rootValue, info); // Coerce to Promise for easier error handling and consistent return type.
|
||||
|
||||
return Promise.resolve(result).then(function (eventStream) {
|
||||
// If eventStream is an Error, rethrow a located error.
|
||||
if (eventStream instanceof Error) {
|
||||
return {
|
||||
errors: [locatedError(eventStream, fieldNodes, pathToArray(path))]
|
||||
};
|
||||
} // Assert field returned an event stream, otherwise yield an error.
|
||||
|
||||
|
||||
if (isAsyncIterable(eventStream)) {
|
||||
// Note: isAsyncIterable above ensures this will be correct.
|
||||
return eventStream;
|
||||
}
|
||||
|
||||
throw new Error('Subscription field must return Async Iterable. Received: ' + inspect(eventStream));
|
||||
});
|
||||
} catch (error) {
|
||||
// As with reportGraphQLError above, if the error is a GraphQLError, report
|
||||
// it as an ExecutionResult; otherwise treat it as a system-class error and
|
||||
// re-throw it.
|
||||
return error instanceof GraphQLError ? Promise.resolve({
|
||||
errors: [error]
|
||||
}) : Promise.reject(error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user