How to use 'apollo setcontext' in JavaScript

Every line of 'apollo setcontext' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
56private contextLink() {
57 return setContext((_req, previousContext) => {
58 let currentUser = '{}';
59
60 // tslint:disable: no-unsafe-any
61 if (Object.keys(previousContext).length) {
62 const user = previousContext.graphqlContext.req.user;
63 if (user) {
64 currentUser = JSON.stringify(user);
65 }
66 }
67 // tslint:enable: no-unsafe-any
68
69 return {
70 headers: {
71 currentUser,
72 },
73 };
74 });
75}
18export function useApolloClient() {
19 return useContext(ApolloContext);
20}

Related snippets