本文整理匯總了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' }));
},