@graphql-tools/links
Version:
A set of utils for faster development of GraphQL tools
30 lines (29 loc) • 1.22 kB
JavaScript
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.linkToExecutor = void 0;
const tslib_1 = require("tslib");
const apolloImport = tslib_1.__importStar(require("@apollo/client"));
const utils_1 = require("@graphql-tools/utils");
const apollo = (_a = apolloImport === null || apolloImport === void 0 ? void 0 : apolloImport.default) !== null && _a !== void 0 ? _a : apolloImport;
function linkToExecutor(link) {
return function executorFromLink(request) {
const observable = apollo.execute(link, {
query: request.document,
operationName: request.operationName,
variables: request.variables,
context: {
graphqlContext: request.context,
graphqlResolveInfo: request.info,
clientAwareness: {},
},
extensions: request.extensions,
});
const operationAst = (0, utils_1.getOperationASTFromRequest)(request);
if (operationAst.operation === 'subscription') {
return (0, utils_1.observableToAsyncIterable)(observable);
}
return apollo.toPromise(observable);
};
}
exports.linkToExecutor = linkToExecutor;
;