當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript apollo-link.execute函數代碼示例

本文整理匯總了TypeScript中apollo-link.execute函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript execute函數的具體用法?TypeScript execute怎麽用?TypeScript execute使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了execute函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

  it('errors on an incorrect number of results for a batch', done => {
    const link = new BatchHttpLink({
      uri: 'batch',
      batchInterval: 0,
      batchMax: 3,
    });

    let errors = 0;
    const next = data => {
      done.fail('next should not have been called');
    };

    const complete = () => {
      done.fail('complete should not have been called');
    };

    const error = error => {
      errors++;

      if (errors === 3) {
        done();
      }
    };

    execute(link, { query: sampleQuery }).subscribe(next, error, complete);
    execute(link, { query: sampleQuery }).subscribe(next, error, complete);
    execute(link, { query: sampleQuery }).subscribe(next, error, complete);
  });
開發者ID:SET001,項目名稱:apollo-link,代碼行數:28,代碼來源:batchHttpLink.ts

示例2: it

  it(`does not affect different queries`, () => {
    const document: DocumentNode = gql`
      query test1($x: String) {
        test(x: $x)
      }
    `;
    const variables1 = { x: 'Hello World' };
    const variables2 = { x: 'Goodbye 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(() => {
        called += 1;
        return null;
      }),
    ]);

    execute(deduper, request1);
    execute(deduper, request2);
    expect(called).toBe(2);
  });
開發者ID:SET001,項目名稱:apollo-link,代碼行數:34,代碼來源:dedupLink.ts

示例3: it

  it('should call next with multiple results for subscription', done => {
    const results = [
      { data: { data: 'result1' } },
      { data: { data: 'result2' } },
    ];
    const client: any = {};
    client.__proto__ = SubscriptionClient.prototype;
    client.request = jest.fn(() => {
      const copy = [...results];
      return new Observable<ExecutionResult>(observer => {
        observer.next(copy[0]);
        observer.next(copy[1]);
      });
    });

    const link = new WebSocketLink(client);

    execute(link, { query: subscription }).subscribe(data => {
      expect(client.request).toHaveBeenCalledTimes(1);
      expect(data).toEqual(results.shift());
      if (results.length === 0) {
        done();
      }
    });
  });
開發者ID:SET001,項目名稱:apollo-link,代碼行數:25,代碼來源:webSocketLink.ts

示例4: it

  it("throws for GET if the extensions can't be stringified", done => {
    const link = createHttpLink({
      uri: 'http://data/',
      useGETForQueries: true,
      includeExtensions: true,
    });

    let b;
    const a = { b };
    b = { a };
    a.b = b;
    const extensions = {
      a,
      b,
    };
    execute(link, { query: sampleQuery, extensions }).subscribe(
      result => {
        done.fail('next should have been thrown from the link');
      },
      makeCallback(done, e => {
        expect(e.message).toMatch(/Extensions map is not serializable/);
        expect(e.parseError.message).toMatch(
          /Converting circular structure to JSON/,
        );
      }),
    );
  });
開發者ID:SET001,項目名稱:apollo-link,代碼行數:27,代碼來源:httpLink.ts

示例5: it

  it('captures errors within links', done => {
    const query = gql`
      query Foo {
        foo {
          bar
        }
      }
    `;

    let called;
    const errorLink = onError(({ operation, networkError }) => {
      expect(networkError.message).toBe('app is crashing');
      expect(operation.operationName).toBe('Foo');
      called = true;
    });

    const mockLink = new ApolloLink(operation => {
      return new Observable(obs => {
        throw new Error('app is crashing');
      });
    });

    const link = errorLink.concat(mockLink);

    execute(link, { query }).subscribe({
      error: e => {
        expect(e.message).toBe('app is crashing');
        expect(called).toBe(true);
        done();
      },
    });
  });
開發者ID:SET001,項目名稱:apollo-link,代碼行數:32,代碼來源:index.ts

示例6: it

it('passes a query on to the next link', done => {
  const nextLink = new ApolloLink(operation => {
    try {
      expect(operation.getContext()).toMatchSnapshot();
      expect(print(operation.query)).toEqual(
        print(gql`
          query Mixed {
            bar {
              foo
            }
          }
        `),
      );
    } catch (error) {
      done.fail(error);
    }
    return Observable.of({ data: { bar: { foo: true } } });
  });

  const client = withClientState({ resolvers });

  execute(client.concat(nextLink), { query: mixedQuery }).subscribe(
    () => done(),
    done.fail,
  );
});
開發者ID:petermichuncc,項目名稱:scanner,代碼行數:26,代碼來源:index.ts

示例7: execute

 [1, 2, 3, 4].forEach(x => {
   execute(link, {
     query,
   }).subscribe({
     next: d => {
       try {
         expect(d).toEqual(data);
       } catch (e) {
         done.fail(e);
       }
     },
     error: done.fail,
     complete: () => {
       count++;
       if (count === 4) {
         try {
           expect(batchHandler.mock.calls.length).toBe(2);
           done();
         } catch (e) {
           done.fail(e);
         }
       }
     },
   });
 });
開發者ID:SET001,項目名稱:apollo-link,代碼行數:25,代碼來源:batchLink.ts

示例8: it

  it('calls unsubscribe on the appropriate downstream observable', async () => {
    const retry = new RetryLink({
      delay: { initial: 1 },
      attempts: { max: 2 },
    });
    const data = { data: { hello: 'world' } };
    const unsubscribeStub = jest.fn();

    const firstTry = fromError(standardError);
    // Hold the test hostage until we're hit
    let secondTry;
    const untilSecondTry = new Promise(resolve => {
      secondTry = {
        subscribe(observer) {
          resolve(); // Release hold on test.

          Promise.resolve().then(() => {
            observer.next(data);
            observer.complete();
          });
          return { unsubscribe: unsubscribeStub };
        },
      };
    });

    const stub = jest.fn();
    stub.mockReturnValueOnce(firstTry);
    stub.mockReturnValueOnce(secondTry);
    const link = ApolloLink.from([retry, stub]);

    const subscription = execute(link, { query }).subscribe({});
    await untilSecondTry;
    subscription.unsubscribe();
    expect(unsubscribeStub).toHaveBeenCalledTimes(1);
  });
開發者ID:SET001,項目名稱:apollo-link,代碼行數:35,代碼來源:retryLink.ts

示例9: it

  it('passes forward on', done => {
    const link = ApolloLink.from([
      new BatchLink({
        batchInterval: 0,
        batchMax: 1,
        batchHandler: (operation, forward) => {
          try {
            expect(forward.length).toBe(1);
            expect(operation.length).toBe(1);
          } catch (e) {
            done.fail(e);
          }
          return forward[0](operation[0]).map(result => [result]);
        },
      }),
      new ApolloLink(operation => {
        terminatingCheck(done, () => {
          expect(operation.query).toEqual(query);
        })();
        return null;
      }),
    ]);

    execute(
      link,
      createOperation(
        {},
        {
          query,
        },
      ),
    ).subscribe(result => done.fail());
  });
開發者ID:SET001,項目名稱:apollo-link,代碼行數:33,代碼來源:batchLink.ts

示例10: it

  it('should poll request', done => {
    let count = 0;
    let subscription;
    const spy = jest.fn();
    const checkResults = () => {
      const calls = spy.mock.calls;
      calls.map((call, i) => expect(call[0].data.count).toEqual(i));
      expect(calls.length).toEqual(5);
      done();
    };

    const poll = new PollingLink(() => 1).concat(() => {
      if (count >= 5) {
        subscription.unsubscribe();
        checkResults();
      }
      return Observable.of({
        data: {
          count: count++,
        },
      });
    });

    subscription = execute(poll, { query }).subscribe({
      next: spy,
      error: error => {
        throw error;
      },
      complete: () => {
        throw new Error();
      },
    });
  });
開發者ID:SET001,項目名稱:apollo-link,代碼行數:33,代碼來源:pollingLink.ts

示例11: it

  it('concatenates schema strings if typeDefs are passed in as an array', done => {
    const anotherSchema = `
      type Foo {
        foo: String!
        bar: String
      }
    `;

    const nextLink = new ApolloLink(operation => {
      const { schemas } = operation.getContext();
      expect(schemas).toMatchSnapshot();
      return Observable.of({
        data: { foo: { bar: true, __typename: 'Bar' } },
      });
    });

    const client = withClientState({
      resolvers,
      defaults,
      typeDefs: [typeDefs, anotherSchema],
    });

    execute(client.concat(nextLink), {
      query: remoteQuery,
    }).subscribe(() => done(), done.fail);
  });
開發者ID:petermichuncc,項目名稱:scanner,代碼行數:26,代碼來源:initialization.ts

示例12: it

it('respects aliases for *nested fields* on the @client-tagged node', done => {
  const aliasedQuery = gql`
    query Test {
      fie: foo @client {
        fum: bar
      }
      baz: bar {
        foo
      }
    }
  `;
  const clientLink = withClientState({
    resolvers: {
      Query: {
        foo: () => ({ bar: true }),
        fie: () => {
          done.fail(
            "Called the resolver using the alias' name, instead of the correct resolver name.",
          );
        },
      },
    },
  });
  const sample = new ApolloLink(() =>
    Observable.of({ data: { baz: { foo: true } } }),
  );
  execute(clientLink.concat(sample), {
    query: aliasedQuery,
  }).subscribe(({ data }) => {
    expect(data).toEqual({ fie: { fum: true }, baz: { foo: true } });
    done();
  }, done.fail);
});
開發者ID:petermichuncc,項目名稱:scanner,代碼行數:33,代碼來源:aliases.ts

示例13: execute

 complete: () => {
   execute(deduper, request2).subscribe({
     complete: () => {
       expect(called).toBe(2);
       done();
     },
   });
 },
開發者ID:SET001,項目名稱:apollo-link,代碼行數:8,代碼來源:dedupLink.ts

示例14: execute

      [1, 2].forEach(x => {
        execute(link, {
          query,
          variables: { endpoint: 'rofl' },
        }).subscribe({
          next: next(roflData),
          error: done.fail,
          complete,
        });

        execute(link, {
          query,
          variables: { endpoint: 'lawl' },
        }).subscribe({
          next: next(lawlData),
          error: done.fail,
          complete,
        });
      });
開發者ID:SET001,項目名稱:apollo-link,代碼行數:19,代碼來源:batchHttpLink.ts

示例15: execute

  execute(client, { query }).subscribe(({ data }) => {
    expect(data).toEqual({ foo: { bar: 1 } });

    // twice
    execute(client, { query }).subscribe(({ data }) => {
      expect(data).toEqual({ foo: { bar: 1 } });
      expect(resolversSpy).toHaveBeenCalledTimes(2);
      done();
    }, done.fail);
  }, done.fail);
開發者ID:petermichuncc,項目名稱:scanner,代碼行數:10,代碼來源:index.ts


注:本文中的apollo-link.execute函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。