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