Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const createSubscriptionSource = (
operation: Operation
): Source => {
// This excludes the query's name as a field although subscription-transport-ws does accept it since it's optional
const observableish = forwardSubscription({
key: operation.key.toString(36),
query: print(operation.query),
variables: operation.variables,
context: { ...operation.context },
});
return make(([next, complete]) => {
let isComplete = false;
const sub = observableish.subscribe({
next: result => next(makeResult(operation, result)),
error: err => next(makeErrorResult(operation, err)),
complete: () => {
if (!isComplete) {
client.reexecuteOperation({
...operation,
operationName: 'teardown',
});
}
complete();
},
});
const createFetchSource = (operation: Operation) => {
if (
process.env.NODE_ENV !== 'production' &&
operation.operationName === 'subscription'
) {
throw new Error(
'Received a subscription operation in the httpExchange. You are probably trying to create a subscription. Have you added a subscriptionExchange?'
);
}
return make(([next, complete]) => {
const abortController =
typeof AbortController !== 'undefined'
? new AbortController()
: undefined;
const { context } = operation;
const extraOptions =
typeof context.fetchOptions === 'function'
? context.fetchOptions()
: context.fetchOptions || {};
const operationName = getOperationName(operation.query);
const body: Body = {
query: print(operation.query),