当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ApolloLink.empty方法代码示例

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


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

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

示例2: ApolloClient

    done => {
      const aliasedQuery = gql`
        query Test {
          fie: foo @client {
            bar
          }
        }
      `;

      const client = new ApolloClient({
        cache: new InMemoryCache(),
        link: ApolloLink.empty(),
        resolvers: {
          Query: {
            foo: () => ({ bar: true, __typename: 'Foo' }),
            fie: () => {
              done.fail(
                "Called the resolver using the alias' name, instead of " +
                  'the correct resolver name.',
              );
            },
          },
        },
      });

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

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

示例4: it

  it('should let you write to the cache with a mutation', () => {
    const query = gql`
      {
        field @client
      }
    `;

    const mutation = gql`
      mutation start {
        start @client
      }
    `;

    const client = new ApolloClient({
      cache: new InMemoryCache(),
      link: ApolloLink.empty(),
      resolvers: {
        Mutation: {
          start(_data, _args, { cache }) {
            cache.writeData({ data: { field: 1 } });
            return { start: true };
          },
        },
      },
    });

    return client
      .mutate({ mutation })
      .then(() => client.query({ query }))
      .then(({ data }) => {
        expect({ ...data }).toMatchObject({ field: 1 });
      });
  });
开发者ID:apollostack,项目名称:apollo-client,代码行数:33,代码来源:resolvers.ts

示例5: it

  it('should cache data for future lookups', () => {
    const query = gql`
      {
        field @client
      }
    `;

    let count = 0;
    const client = new ApolloClient({
      cache: new InMemoryCache(),
      link: ApolloLink.empty(),
      resolvers: {
        Query: {
          field: () => {
            count += 1;
            return 1;
          },
        },
      },
    });

    return client
      .query({ query })
      .then(({ data }) => {
        expect({ ...data }).toMatchObject({ field: 1 });
        expect(count).toBe(1);
      })
      .then(() =>
        client.query({ query }).then(({ data }) => {
          expect({ ...data }).toMatchObject({ field: 1 });
          expect(count).toBe(1);
        }),
      );
  });
开发者ID:apollostack,项目名称:apollo-client,代码行数:34,代码来源:general.ts


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