graphql-playground icon indicating copy to clipboard operation
graphql-playground copied to clipboard

Response not successful: Received status code 500

Open deathg0d opened this issue 7 years ago • 4 comments

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.

deathg0d avatar Jul 23 '18 17:07 deathg0d

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>

mrdulin avatar Apr 18 '19 03:04 mrdulin

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)
	}),
})

ophickedo avatar Oct 15 '19 18:10 ophickedo

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).

crqrdotcom avatar Feb 06 '21 15:02 crqrdotcom

@wtfiscrq could you elaborate with an example please. I am using ApolloServer v4

simpyparveen avatar Nov 28 '23 17:11 simpyparveen