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

TypeScript apollo-link.ApolloLink类代码示例

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

本文整理汇总了TypeScript中apollo-link.ApolloLink的典型用法代码示例。如果您正苦于以下问题:TypeScript ApolloLink类的具体用法?TypeScript ApolloLink怎么用?TypeScript ApolloLink使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ApolloLink类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: it

  it('does not update the cache on a mutation', () => {
    let called = 0;
    const inspector = new ApolloLink((operation, forward) => {
      called++;
      return forward(operation).map(result => {
        called++;
        return result;
      });
    });

    const client = new ApolloClient({
      link: inspector.concat(createMutationLink()),
      cache: new InMemoryCache({ addTypename: false }),
    });

    return client
      .query({ query })
      .then(() =>
        client.mutate({ mutation, variables, fetchPolicy: 'no-cache' }),
      )
      .then(() => {
        return client.query({ query }).then(actualResult => {
          expect(actualResult.data).toEqual(result);
        });
      });
  });
开发者ID:dotansimha,项目名称:apollo-client,代码行数:26,代码来源:fetchPolicies.ts


示例2: it

    it('will return null when an id that can’t be found is provided', () => {
      const client1 = new ApolloClient({
        link: ApolloLink.empty(),
        cache: new InMemoryCache(),
      });
      const client2 = new ApolloClient({
        link: ApolloLink.empty(),
        cache: new InMemoryCache().restore({
          bar: { __typename: 'Foo', a: 1, b: 2, c: 3 },
        }),
      });
      const client3 = new ApolloClient({
        link: ApolloLink.empty(),
        cache: new InMemoryCache().restore({
          foo: { __typename: 'Foo', a: 1, b: 2, c: 3 },
        }),
      });

      expect(
        client1.readFragment({
          id: 'foo',
          fragment: gql`
            fragment fooFragment on Foo {
              a
              b
              c
            }
          `,
        }),
      ).toBe(null);
      expect(
        client2.readFragment({
          id: 'foo',
          fragment: gql`
            fragment fooFragment on Foo {
              a
              b
              c
            }
          `,
        }),
      ).toBe(null);
      expect(
        client3.readFragment({
          id: 'foo',
          fragment: gql`
            fragment fooFragment on Foo {
              a
              b
              c
            }
          `,
        }),
      ).toEqual({ __typename: 'Foo', a: 1, b: 2, c: 3 });
    });
开发者ID:NewSpring,项目名称:apollo-client,代码行数:55,代码来源:ApolloClient.ts


示例3: 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


示例4: createApolloClient

export default function createApolloClient() {
  return new ApolloClient({
    link: ApolloLink.from([restLink, middlewareLink, httpLink]),
    cache: new InMemoryCache(),
    connectToDevTools: devMode
  });
}
开发者ID:codefordenver,项目名称:members,代码行数:7,代码来源:createApolloClient.ts


示例5: constructor

 constructor(
   private apollo: Apollo,
   private tokenService: TokenService,
   private modalService: ModalService
 ) {
   const uploadLink = createUploadLink({ uri: uri });
   const authLink = createAuthLink(tokenService);
   const errorLink = createErrorLink(modalService);
   apollo.create({
     link: ApolloLink.from([authLink, errorLink, uploadLink]),
     cache: new InMemoryCache(),
     queryDeduplication: true,
     defaultOptions: {
       mutate: {
         errorPolicy: 'all'
       },
       query: {
         errorPolicy: 'all'
       },
       watchQuery: {
         errorPolicy: 'all'
       }
     }
   });
 }
开发者ID:ngocdiep,项目名称:nd,代码行数:25,代码来源:graphql.module.ts


示例6: InMemoryCache

    () => {
      const query = gql`
        {
          fie: foo @client {
            bar
          }
        }
      `;

      const cache = new InMemoryCache();
      const client = new ApolloClient({
        cache,
        link: ApolloLink.empty(),
      });

      cache.writeData({
        data: {
          foo: {
            bar: 'yo',
            __typename: 'Foo',
          },
        },
      });

      return client.query({ query }).then(({ data }) => {
        expect({ ...data }).toMatchObject({
          fie: { bar: 'yo', __typename: 'Foo' },
        });
      });
    },
开发者ID:apollostack,项目名称:apollo-client,代码行数:30,代码来源:resolvers.ts


示例7: it

  it('throws an error when more requests than results', done => {
    const result = [{ data: {} }];
    const batchHandler = jest.fn(op => Observable.of(result));

    const link = ApolloLink.from([
      new BatchLink({
        batchInterval: 10,
        batchMax: 2,
        batchHandler,
      }),
    ]);

    [1, 2].forEach(x => {
      execute(link, {
        query,
      }).subscribe({
        next: data => {
          done.fail('next should not be called');
        },
        error: terminatingCheck(done, error => {
          expect(error).toBeDefined();
          expect(error.result).toEqual(result);
        }),
        complete: () => {
          done.fail('complete should not be called');
        },
      });
    });
  });
开发者ID:SET001,项目名称:apollo-link,代码行数:29,代码来源:batchLink.ts


示例8: it

    it('does a network request if fetchPolicy is cache-only then store is reset then fetchPolicy becomes not cache-only', done => {
      let queryManager: QueryManager;
      let observable: ObservableQuery<any>;
      const testQuery = gql`
        query {
          author {
            firstName
            lastName
          }
        }
      `;
      const data = {
        author: {
          firstName: 'John',
          lastName: 'Smith',
        },
      };

      let timesFired = 0;
      const link: ApolloLink = ApolloLink.from([
        () => {
          return new Observable(observer => {
            timesFired += 1;
            observer.next({ data });
            observer.complete();
            return;
          });
        },
      ]);
      queryManager = createQueryManager({ link });
      observable = queryManager.watchQuery({ query: testQuery });

      subscribeAndCount(done, observable, (handleCount, result) => {
        try {
          if (handleCount === 1) {
            expect(result.data).toEqual(data);
            expect(timesFired).toBe(1);

            setTimeout(() => {
              observable.setOptions({ fetchPolicy: 'cache-only' });
              queryManager.resetStore();
            }, 0);
          } else if (handleCount === 2) {
            expect(result.data).toEqual({});
            expect(timesFired).toBe(1);

            setTimeout(() => {
              observable.setOptions({ fetchPolicy: 'cache-first' });
            }, 0);
          } else if (handleCount === 3) {
            expect(result.data).toEqual(data);
            expect(timesFired).toBe(2);

            done();
          }
        } catch (e) {
          done.fail(e);
        }
      });
    });
开发者ID:dotansimha,项目名称:apollo-client,代码行数:60,代码来源:ObservableQuery.ts



注:本文中的apollo-link.ApolloLink类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript apollo-link.Observable类代码示例发布时间:2022-05-25
下一篇:
TypeScript apollo-link.split函数代码示例发布时间: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