DEV Community

Discussion on: Getting Started with Apollo Federation and Gateway

Collapse
 
kieronjmckenna profile image
kieronjmckenna

Easy solution to the development problem I referenced is to use wait-on in index.js before building the gateway rather than in the command line.

This way when nodemon restarts the gateway server it waits for the other services on every restart, not just the first time we run the command.

Thought I'd mention this for anyone who ran into the same problem.

Thread Thread
 
01sdante profile image
dante

Hi, can you give an example on how you solved this? I'm facing the same issue but can't make it work.

Thread Thread
 
ryanmercadante profile image
Ryan Mercadante
import waitOn from 'wait-on'
import app from './config/app'
import server from './config/apollo'

const port = process.env.PORT

const options = {
  resources: ['tcp:4001'],
}

waitOn(options)
  .then(() => {
    server.applyMiddleware({ app })
    app.listen({ port }, () => {
      console.log(
        `Server ready at http://localhost:${port}${server.graphqlPath}`
      )
    })
  })
  .catch((err) => {
    console.error('ERR:', err)
  })
Enter fullscreen mode Exit fullscreen mode

Give this a try!