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


TypeScript ApolloClient.query方法代码示例

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


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

示例1: expect

 .then(() =>
   client
     .query({ query, fetchPolicy: 'network-only' })
     .then(({ data }) => {
       expect({ ...data }).toMatchObject({ field: 1 });
       expect(count).toBe(2);
     }),
开发者ID:petermichuncc,项目名称:scanner,代码行数:7,代码来源:client.ts

示例2: it

it('runs default resolvers for aliased fields tagged with @client', () => {
  expect.assertions(1);
  const query = gql`
    {
      fie: foo @client {
        bar
      }
    }
  `;

  const cache = new InMemoryCache();

  const client = new ApolloClient({
    cache,
    link: withClientState({
      cache,
      resolvers: {},
      defaults: {
        foo: {
          bar: 'yo',
          __typename: 'Foo',
        },
      },
    }),
  });

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

示例3: it

  it('writeDefaults lets you write defaults to the cache after the store is reset', done => {
    const mutation = gql`
      mutation foo {
        foo @client
      }
    `;

    const query = gql`
      {
        foo @client
      }
    `;

    const cache = new InMemoryCache();

    const stateLink = withClientState({
      defaults: {
        foo: 'bar',
      },
      resolvers: {
        Mutation: {
          foo: (_, $, { cache }) => {
            cache.writeData({ data: { foo: 'woo' } });
            return null;
          },
        },
      },
      cache,
    });

    const client = new ApolloClient({
      cache,
      link: stateLink,
    });

    client.onResetStore(stateLink.writeDefaults);

    client
      .query({ query })
      .then(({ data }) => {
        expect({ ...data }).toMatchObject({ foo: 'bar' });
      })
      .catch(done.fail);

    client
      .mutate({ mutation })
      .then(() => client.query({ query }))
      .then(({ data }) => {
        expect({ ...data }).toMatchObject({ foo: 'woo' });
      })
      //should be default after this reset call
      .then(() => client.resetStore() as Promise<null>)
      .then(() => client.query({ query }))
      .then(({ data }) => {
        expect({ ...data }).toMatchObject({ foo: 'bar' });
        done();
      })
      .catch(done.fail);
  });
开发者ID:petermichuncc,项目名称:scanner,代码行数:59,代码来源:client.ts

示例4: it

  it(`doesn't call the resolver if the data is already in the cache`, () => {
    const fooResolver = jest.fn();
    const resolvers = { Query: { foo: fooResolver } };

    const cache = new InMemoryCache();
    const client = new ApolloClient({
      cache,
      link: withClientState({ cache, resolvers, defaults }),
    });

    client
      .query({ query })
      .then(({ data }) => {
        expect(fooResolver).not.toHaveBeenCalled();
        expect(data.foo.bar).toEqual(false);
      })
      .catch(e => console.error(e));
  });
开发者ID:petermichuncc,项目名称:scanner,代码行数:18,代码来源:initialization.ts


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