next-with-apollo: CTX undefined
Trying to use your example with apollo-boost while setting an authorization header, but contect ctx always seems to be undefined?
How do I require context while still using your HOC?
// apollo.js
import withApollo from 'next-with-apollo';
import ApolloClient from 'apollo-boost';
import getConfig from 'next/config';
import { getCookieJwt } from './auth';
const { publicRuntimeConfig } = getConfig();
export default withApollo(
({ ctx, headers }) => {
return new ApolloClient({
uri: `${publicRuntimeConfig.SERVER_URL}/api`,
request: async operation => {
const token = await getCookieJwt(ctx); //ctx is undefined
operation.setContext({
headers: {
authorization: token ? `Bearer ${token}` : ''
}
});
}
});
},
);
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (6 by maintainers)
Honestly, I feel like something more explicit would be better than inferring whether browser or not like this.