• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript apollo-link.execute函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript apollo-link.fromError函数代码示例发布时间:2022-05-25
下一篇:
TypeScript apollo-link.createOperation函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap