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


TypeScript InMemoryCache.writeQuery方法代码示例

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


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

示例1: it

  it('should handle resolvers that work with booleans properly', done => {
    const query = gql`
      query CartDetails {
        isInCart @client
      }
    `;

    const cache = new InMemoryCache();
    cache.writeQuery({ query, data: { isInCart: true } });

    const client = new ApolloClient({
      cache,
      resolvers: {
        Query: {
          isInCart: () => false,
        },
      },
    });

    return client
      .query({ query, fetchPolicy: 'network-only' })
      .then(({ data }: any) => {
        expect({ ...data }).toMatchObject({
          isInCart: false,
        });
        done();
      });
  });
开发者ID:apollostack,项目名称:apollo-client,代码行数:28,代码来源:resolvers.ts

示例2: it

  it('still lets you query the cache without passing in a resolver map', () => {
    const query = gql`
      {
        field @client
      }
    `;

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

    cache.writeQuery({ query, data: { field: 'yo' } });

    client
      .query({ query })
      .then(({ data }) => expect({ ...data }).toMatchObject({ field: 'yo' }));
  });
开发者ID:petermichuncc,项目名称:scanner,代码行数:19,代码来源:client.ts

示例3: InMemoryCache

    () => {
      const query = gql`
        {
          field @client
        }
      `;

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

      cache.writeQuery({ query, data: { field: 'yo' } });

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


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