本文整理汇总了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();
});
});
示例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' }));
});
示例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' }));
},