How to use the apollo-link.createOperation 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-batch / src / __tests__ / batchLink.ts View on Github external
new Observable(observer => {
          observer.next([{ data }, { data: data2 }, { data }]);
          setTimeout(observer.complete.bind(observer));
        }),
    });
    const query = gql`
      query {
        author {
          firstName
          lastName
        }
      }
    `;
    const operation: Operation = createOperation({}, { query });
    const operation2: Operation = createOperation({}, { query });
    const operation3: Operation = createOperation({}, { query });

    batcher.enqueueRequest({ operation }).subscribe({});
    batcher.enqueueRequest({ operation: operation2 }).subscribe({});
    try {
      expect(batcher.queuedRequests.get('').length).toBe(2);
    } catch (e) {
      done.fail(e);
    }

    setTimeout(() => {
      // The batch shouldn't be fired yet, so we can add one more request.
      batcher.enqueueRequest({ operation: operation3 }).subscribe({});
      try {
        expect(batcher.queuedRequests.get('').length).toBe(3);
      } catch (e) {
        done.fail(e);
github apollographql / apollo-link / packages / apollo-link-batch / src / __tests__ / batchLink.ts View on Github external
batchHandler: () =>
        new Observable(observer => {
          observer.next([{ data }, { data: data2 }, { data }]);
          setTimeout(observer.complete.bind(observer));
        }),
    });
    const query = gql`
      query {
        author {
          firstName
          lastName
        }
      }
    `;
    const operation: Operation = createOperation({}, { query });
    const operation2: Operation = createOperation({}, { query });
    const operation3: Operation = createOperation({}, { query });

    batcher.enqueueRequest({ operation }).subscribe({});
    batcher.enqueueRequest({ operation: operation2 }).subscribe({});
    try {
      expect(batcher.queuedRequests.get('').length).toBe(2);
    } catch (e) {
      done.fail(e);
    }

    setTimeout(() => {
      // The batch shouldn't be fired yet, so we can add one more request.
      batcher.enqueueRequest({ operation: operation3 }).subscribe({});
      try {
        expect(batcher.queuedRequests.get('').length).toBe(3);
      } catch (e) {
github apollographql / apollo-link / packages / apollo-link-http-common / src / __tests__ / index.ts View on Github external
it('the fallbackConfig is used if no other configs are specified', () => {
      const defaultHeaders = {
        accept: '*/*',
        'content-type': 'application/json',
      };

      const defaultOptions = {
        method: 'POST',
      };

      const extensions = { yo: 'what up' };
      const { options, body } = selectHttpOptionsAndBody(
        createOperation({}, { query, extensions }),
        fallbackHttpConfig,
      );

      expect(body).toHaveProperty('query');
      expect(body).not.toHaveProperty('extensions');

      expect(options.headers).toEqual(defaultHeaders);
      expect(options.method).toEqual(defaultOptions.method);
    });
github apollographql / apollo-link / packages / apollo-link-http-common / src / __tests__ / index.ts View on Github external
it('returns the result of a UriFunction', () => {
      const uri = '/somewhere';
      const operation = createOperation({}, { query });
      expect(selectURI(operation, () => uri)).toEqual(uri);
    });
  });
github apollographql / apollo-link / packages / apollo-link-http-common / src / __tests__ / index.ts View on Github external
it('returns the result of a UriFunction', () => {
      const uri = '/somewhere';
      const operation = createOperation({}, { query });
      expect(selectURI(operation, () => uri)).toEqual(uri);
    });
  });
github apollographql / apollo-link / packages / apollo-link-batch / src / __tests__ / batchLink.ts View on Github external
it('should be able to consume from a queue containing multiple queries', done => {
      const request2: Operation = createOperation(
        {},
        {
          query,
        },
      );

      const BH = createMockBatchHandler(
        {
          request: { query },
          result: { data },
        },
        {
          request: { query },
          result: { data },
        },
      );
github apollographql / apollo-link / packages / apollo-link-http-common / src / __tests__ / index.ts View on Github external
it('the fallbackConfig is used if no other configs are specified', () => {
      const defaultHeaders = {
        accept: '*/*',
        'content-type': 'application/json',
      };

      const defaultOptions = {
        method: 'POST',
      };

      const extensions = { yo: 'what up' };
      const { options, body } = selectHttpOptionsAndBody(
        createOperation({}, { query, extensions }),
        fallbackHttpConfig,
      );

      expect(body).toHaveProperty('query');
      expect(body).not.toHaveProperty('extensions');

      expect(options.headers).toEqual(defaultHeaders);
      expect(options.method).toEqual(defaultOptions.method);
    });
github apollographql / apollo-link / packages / apollo-link-batch / src / __tests__ / batchLink.ts View on Github external
return forward[0](operation[0]).map(d => [d]);
      });

      const link = ApolloLink.from([
        new BatchLink({
          batchInterval,
          batchMax: 0,
          batchHandler,
        }),
        () => Observable.of(42),
      ]);

      execute(
        link,
        createOperation(
          {},
          {
            query,
          },
        ),
      ).subscribe({
        next: data => {
          try {
            expect(data).toBe(42);
          } catch (e) {
            done.fail(e);
          }
        },
        complete: () => {
          mock(batchHandler.mock.calls.length);
        },
github apollographql / apollo-link / packages / apollo-link-batch / src / __tests__ / batchLink.ts View on Github external
batchHandler: () => {
        return null;
      },
    });

    const query = gql`
      query {
        author {
          firstName
          lastName
        }
      }
    `;

    const request: BatchableRequest = {
      operation: createOperation({}, { query }),
    };

    expect(batcher.queuedRequests.get('')).toBeUndefined();
    batcher.enqueueRequest(request).subscribe({});
    expect(batcher.queuedRequests.get('').length).toBe(1);
    batcher.enqueueRequest(request).subscribe({});
    expect(batcher.queuedRequests.get('').length).toBe(2);
  });