Peter
Peter

Reputation: 2394

apollo-server returning GET query missing when playground is disabled

When I emulate production (aka, playground is disabled) and I go to my root, http://localhost:9000/ I receive the following response:

400 Bad Request

GET query missing

Is there a way to prevent this or a workaround to render other page?

I'm new with apollo. I'm using just apollo-server (no express). I will appreciate any help.

Upvotes: 2

Views: 8387

Answers (3)

Sean
Sean

Reputation: 1193

With the default configuration for apollo-server-xxx, you need to send a POST request to the /graphql endpoint, with the request body a graphql string.

I had the same problem because I sent a GET request instead of POST.

Upvotes: 7

Muhammad Raheel
Muhammad Raheel

Reputation: 818

Use playground: true:

const server = new ApolloServer({
    introspection: true,
    playground: true,
    typeDefs,
    resolvers,
})

Upvotes: 6

Daniel Rearden
Daniel Rearden

Reputation: 84687

apollo-server is used exclusively to expose a GraphQL API. As a convenience it exposes a GraphQL Playground instance at whatever path you configure (/graphql by default) in development. However, Apollo Server itself is not meant to be used for serving other content. If you need this functionality, use something like apollo-server-express, apollo-server,hapi, apollo-server-koa, etc. to integrate ApolloServer with a web application framework like Express and then use that framework to serve whatever additional content you want.

Upvotes: 3

Related Questions