@graphql-tools/links
Version:
A set of utils for faster development of GraphQL tools
25 lines (24 loc) • 1.04 kB
JavaScript
var _a;
import * as apolloImport from '@apollo/client';
import { observableToAsyncIterable, getOperationASTFromRequest, } from '@graphql-tools/utils';
const apollo = (_a = apolloImport === null || apolloImport === void 0 ? void 0 : apolloImport.default) !== null && _a !== void 0 ? _a : apolloImport;
export 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 = getOperationASTFromRequest(request);
if (operationAst.operation === 'subscription') {
return observableToAsyncIterable(observable);
}
return apollo.toPromise(observable);
};
}