Response not successful: Received status code 500
I am trying to migrate to apollo-server version 2, which has playground inbuilt. Got into an issue, which might be playground specific. I am using the following code to send user information inside jwt token to the context.
const server = new ApolloServer({
typeDefs: gql`${typeDefs}`,
resolvers,
context: ({ req, res }) => {
const username = validateJWT(req.headers)
return { username }
}
})
validateJWT is a function which throws error if jwt is invalid. If the jwt is empty, it returns null and if jwt is valid it returns a username.
This is working fine when jwt is empty or valid. But when jwt is invalid, it throws an error which is visible momentarily in playground and then the playground switches to:
{
"error": "Response not successful: Received status code 500"
}
and the server cannot be reached.
I hit this issue when run apollo service:push command
> apollo service:push
✔ Loading Apollo Project
✖ Uploading service to Engine
→ Response not successful: Received status code 500
ServerError: Response not successful: Received status code 500
at Object.exports.throwServerError (~/workspace/github.com/mrdulin/apollo-graphql-tutorial/node_modules/apollo-link-http-common/lib/index.js:23:17)
at ~/workspace/github.com/mrdulin/apollo-graphql-tutorial/node_modules/apollo-link-http-common/lib/index.js:48:21
at <anonymous>
Hi!
Also here. Problem with context. Without context all works great. Fix it already!
const server = new ApolloServer({
schema,
context: async ({payload}) => ({
user: await validateToken(payload.token)
}),
})
In my particular case when a token wasn't present I was returning on the context function an empty context with dataSources already created. Removing that property from the "empty context" worked (ofc, as that's initialized by Apollo).
@wtfiscrq could you elaborate with an example please. I am using ApolloServer v4