DEV Community

Discussion on: Getting Started with Apollo Federation and Gateway

Collapse
 
kieronjmckenna profile image
kieronjmckenna • Edited

Hi Mandi,

I've been using this set-up for a few weeks now, does your gateway application crash when nodemon restarts one of your services?

Apollo throws this error "This data graph is missing a valid configuration. Couldn't load service definitions for "accounts" at localhost:4001: request to localhost:4001/ failed, reason: connect ECONNREFUSED 127.0.0.1:4001" when ever nodemon restarts one of my servers.

I'm not confused as to why this is happening as obviously the gateway server is dependant on the services. Have you encountered this and if so do you have a work around?

Collapse
 
mandiwise profile image
Mandi Wise

Automatic reloading of the gateway can be an issue, even with wait-on in place. You may want to look at some experimental features of Apollo Gateway (github.com/apollographql/federatio...) to help facilitate this, or look into managed federation instead.

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!