2

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.

Peter
  • 2,004
  • 2
  • 24
  • 57

3 Answers3

7

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.

Sean
  • 1,055
  • 11
  • 10
  • yep, this was the problem. Was using GET instead of post. I don't like how ppl are using new built-in graphQL queryer for postman because a lot of front end like Unity still don't have libraries and I might have to still send JSONs. – darren z May 26 '21 at 16:20
6

Use playground: true:

const server = new ApolloServer({
    introspection: true,
    playground: true,
    typeDefs,
    resolvers,
})
fcdt
  • 2,371
  • 5
  • 14
  • 26
Muhammad Raheel
  • 617
  • 1
  • 6
  • 15
3

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.

Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183
  • Thanks! I also saw other posts where you answered :) I understand, however, is there a way to render other text in production and avoid retrieving a `bad request`. I don't want to add `express` just to show other message or just a white screen but not error (2**). Again, thanks. – Peter Oct 29 '19 at 16:21
  • Nope, there's not any configuration option like that. Either the route exists or it doesn't. If it doesn't exist and someone tries to access it, they'll get the standard Express missing route message just like if they tried to access any other non-existent route on your server. ApolloServer uses Express under the hood. – Daniel Rearden Oct 29 '19 at 17:04