How to use the apollo-link.execute function in apollo-link

To help you get started, we’ve selected a few apollo-link examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apollographql / apollo-link / packages / apollo-link-retry / src / __tests__ / retryLink.ts View on Github external
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);
  });
github apollographql / apollo-link / packages / apollo-link-retry / src / __tests__ / retryLink.ts View on Github external
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);
  });
github apollographql / apollo-link / packages / apollo-link-ws / src / __tests__ / webSocketLink.ts View on Github external
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();
    });
  });
github apollographql / apollo-link / packages / apollo-link-http / src / __tests__ / httpLink.ts View on Github external
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),
      });
    });
github morrys / wora / packages / apollo-offline / src / ApolloStoreOffline.ts View on Github external
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);
}
github apollographql / apollo-client-devtools / src / devtools / components / Explorer / Explorer.js View on Github external
fetcher = ({ query, variables = {} }) => {
    const result = execute(this.link, {
      query: parse(query),
      variables,
      context: { noFetch: this.state.noFetch },
    });

    return result;
  };
github hasura / graphql-engine / console / src / components / Services / ApiExplorer / Actions.js View on Github external
const fetcher = operation => {
      operation.query = parse(operation.query);
      return execute(link, operation);
    };
    return fetcher(graphQLParams);
github AztecProtocol / AZTEC / packages / extension / src / background / services / GraphQLService / inspector / index.jsx View on Github external
const fetcher = ({ query, variables = {} }) => execute(
    link,
    {
        query: parse(query),
        variables,
    },
);
github hasura / graphql-engine / server / graphiql / src / App.js View on Github external
const fetcher = (operation) => {
          operation.query = parse(operation.query);
          return execute(link, operation);
      };