Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('retries independently for concurrent requests', async () => {
const retry = new RetryLink({
delay: { initial: 1 },
attempts: { max: 5 },
});
const data = { data: { hello: 'world' } };
const stub = jest.fn(() => fromError(standardError));
const link = ApolloLink.from([retry, stub]);
const [result1, result2] = await waitFor(
execute(link, { query }),
execute(link, { query }),
);
expect(result1.error).toEqual(standardError);
expect(result2.error).toEqual(standardError);
expect(stub).toHaveBeenCalledTimes(10);
});
it('returns data from the underlying link on a successful operation', async () => {
const retry = new RetryLink();
const data = { data: { hello: 'world' } };
const stub = jest.fn(() => Observable.of(data));
const link = ApolloLink.from([retry, stub]);
const [{ values }] = await waitFor(execute(link, { query }));
expect(values).toEqual([data]);
expect(stub).toHaveBeenCalledTimes(1);
});
it('should call request on the client for a query', done => {
const result = { data: { data: 'result' } };
const client: any = {};
const observable = Observable.of(result);
client.__proto__ = SubscriptionClient.prototype;
client.request = jest.fn();
client.request.mockReturnValueOnce(observable);
const link = new WebSocketLink(client);
const obs = execute(link, { query });
expect(obs).toEqual(observable);
obs.subscribe(data => {
expect(data).toEqual(result);
expect(client.request).toHaveBeenCalledTimes(1);
done();
});
});
it('supports using a GET request', done => {
const variables = { params: 'stub' };
const extensions = { myExtension: 'foo' };
const link = createHttpLink({
uri: 'http://data/',
fetchOptions: { method: 'GET' },
includeExtensions: true,
});
execute(link, { query: sampleQuery, variables, extensions }).subscribe({
next: makeCallback(done, result => {
const [uri, options] = fetchMock.lastCall();
const { method, body } = options;
expect(body).toBeUndefined();
expect(method).toBe('GET');
expect(uri).toBe(
'http://data/?query=query%20SampleQuery%20%7B%0A%20%20stub%20%7B%0A%20%20%20%20id%0A%20%20%7D%0A%7D%0A&operationName=SampleQuery&variables=%7B%22params%22%3A%22stub%22%7D&extensions=%7B%22myExtension%22%3A%22foo%22%7D',
);
}),
error: error => done.fail(error),
});
});
request: {
payload: { mutation, variables, context },
},
} = offlineRecord;
const query = client.queryManager.transform(mutation).document;
const operation = {
query,
variables,
operationName: getOperationName(query) || void 0,
context: client.queryManager.prepareContext({
...context,
forceFetch: true,
}),
};
const options: Options = {
observable: multiplex(execute(link, operation)) as any,
};
return observableToPromise(options, (result) => result);
}
fetcher = ({ query, variables = {} }) => {
const result = execute(this.link, {
query: parse(query),
variables,
context: { noFetch: this.state.noFetch },
});
return result;
};
const fetcher = operation => {
operation.query = parse(operation.query);
return execute(link, operation);
};
return fetcher(graphQLParams);
const fetcher = ({ query, variables = {} }) => execute(
link,
{
query: parse(query),
variables,
},
);
const fetcher = (operation) => {
operation.query = parse(operation.query);
return execute(link, operation);
};