mercurius-js / mercurius-gateway

Mercurius federation support plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Polling does not replace the schema even if the given subgraph endpoint can already serve requests

SiNONiMiTY opened this issue · comments

Hi Mercurius Team,

Given this gateway definition

// Used as a dummy by the gateway
const initialSchema = 'type Query { id: ID }'

server.register( MercuriusGateway, {
    gateway: {
        services: [
            {
                name: 'user',
                url: 'http://127.0.0.1:4001/graphql',
                schema: initialSchema,
            },
        ],
        pollingInterval: Number( process.env.POLL_INTERVAL ) || 10000,
    },
} )

Scenario

  • User GraphQL endpoint is still down, but I want to start the gateway and let it poll the endpoint until it becomes online

The scenario I am expecting when I start the gateway service is

  • Get the schema from the defined URL, if it fails, use the defined SCHEMA option
  • Next poll operation, URL is now online, we can get the schema from it

But what happens is that, it is just comparing to itself every poll operation, thus returning null and no update happens, even if the user endpoint is already up.

if (this._serviceSDLs === _serviceSDLs) {

Is this the intended behavior? I was under the impression that the schema option is a fallback to let the gateway start even if the services are offline.

Reading the code, it seems this is the intentional behavior. Looks like the gateway.service parameter can accept a function, will try this route to implement the logic that I expect.