本文整理汇总了TypeScript中apollo-client.ApolloClient.subscribe方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ApolloClient.subscribe方法的具体用法?TypeScript ApolloClient.subscribe怎么用?TypeScript ApolloClient.subscribe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apollo-client.ApolloClient
的用法示例。
在下文中一共展示了ApolloClient.subscribe方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('supports subscriptions', done => {
const query = gql`
subscription {
field
}
`;
const link = new ApolloLink(() =>
Observable.of({ data: { field: 1 } }, { data: { field: 2 } }),
);
const local = withClientState();
const client = new ApolloClient({
cache: new InMemoryCache(),
link: local.concat(link),
});
let counter = 0;
expect.assertions(2);
return client.subscribe({ query }).forEach(item => {
expect(item).toMatchObject({ data: { field: ++counter } });
if (counter === 2) {
done();
}
});
});
示例2: createStore
const composeEnhancers =
(window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
export const store = createStore(reducer, {}, composeEnhancers(autoRehydrate()))
persistStore(store, {
whitelist: ['mainScreen'],
})
// Subscribe to all status updates, Apollo will automatically update the store using the id.
client
.subscribe({
query: gql`
subscription deviceUpdated {
deviceUpdated {
id
name
config
}
}
`,
})
.subscribe({})
client
.subscribe({
query: gql`
subscription deviceStatusUpdated {
deviceStatusUpdated {
id
value
}
}
示例3:
fieldName: Object.keys(alternativeQueries)[0],
id,
action: "insert",
};
});
},
executeQuery: ({ query, variables }) => {
return client.query({
query,
variables,
});
}
}),
link,
]),
});
client
.subscribe<{ data: CommentAdded; }>({
query: gql`
subscription CommentAdded {
commentAdded {
id
text
}
}
`,
}).subscribe(v => {
console.log("client.subscribe", v.data);
});