How to use the apollo-link.getOperationName 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-dedup / src / __tests__ / dedupLink.ts View on Github external
test(x: $x)
      }
    `;
    const variables1 = { x: 'Hello World' };
    const variables2 = { x: 'Hello World' };

    const request1: GraphQLRequest = {
      query: document,
      variables: variables1,
      operationName: getOperationName(document),
    };

    const request2: GraphQLRequest = {
      query: document,
      variables: variables2,
      operationName: getOperationName(document),
    };

    let called = 0;
    const deduper = ApolloLink.from([
      new DedupLink(),
      new ApolloLink(() => {
        return new Observable(observer => {
          called += 1;
          setTimeout(observer.complete.bind(observer));
        });
      }),
    ]);

    execute(deduper, request1).subscribe({});
    execute(deduper, request2).subscribe({});
    expect(called).toBe(1);