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