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