Apollo server responding with 503 error after deploying to Heroku

Viewed 1607

So my Apollo graphql server was working perfectly in development. I just deployed my project to Heroku, and now I receive a 503 error when making any queries.

I am able to get into the graphiql sandbox, but those responses come back as:

SyntaxError: Unexpected token < in JSON at position 0

I am using express for my server, and here is what the code looks like:

app.use(cors());

app.use(

  '/graphql',

  graphqlHTTP({

    schema: pgSchema,

    graphiql: true

  })

);

app.use(express.static('../public'));

app.get('*', (req, res) => {

  res.sendFile(path.resolve(__dirname, '../public', 'index.html'));

});

Here is where I connect my Apollo client in the React project:

const client = new ApolloClient({
  uri: '/graphql'
});

function App() {
  return (
    <ApolloProvider client={client}>
      <Router>
        <Route exact path='/' component={Login} />
        <Route exact path='/home' component={Home} />
      </Router>
    </ApolloProvider>
  );
}

Here are my heroku logs from graphql:

2020-03-31T16:41:23.780542+00:00 heroku[router]: at=info method=POST path="/graphql" host=damp-ravine-76294.herokuapp.com request_id=a9e695db-63eb-476a-950f-a5d6561ff85f fwd="76.116.11.127" dyno=web.1 connect=1ms service=21ms status=200 bytes=21933 protocol=https
2020-03-31T16:45:50.392011+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/graphql" host=damp-ravine-76294.herokuapp.com request_id=650a1d7d-7f9e-4c66-8a5d-000fc60ed29a fwd="76.116.11.127" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 protocol=https

Please let me know if you have any ideas. Thanks!

1 Answers

From the docs:

Web requests processed by Heroku are directed to your dynos via a number of Heroku routers. These requests are intended to be served by your application quickly. Best practice is to get the response time of your web application to be under 500ms, this will free up the application for more requests and deliver a high quality user experience to your visitors. Occasionally a web request may hang or take an excessive amount of time to process by your application. When this happens the router will terminate the request if it takes longer than 30 seconds to complete.

In other words, if your application takes longer than 30 seconds to send back the first byte of the response, Heroku will terminate the request with the error you're seeing. There doesn't appear to be any way to increase this timeout.

Related