Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apollo Gateway Error: Expected undefined to be a GraphQL schema. #3480

Closed
rtdt99 opened this issue Nov 7, 2019 · 6 comments
Closed

Apollo Gateway Error: Expected undefined to be a GraphQL schema. #3480

rtdt99 opened this issue Nov 7, 2019 · 6 comments
Assignees

Comments

@rtdt99
Copy link

rtdt99 commented Nov 7, 2019

Platform: NodeJS
Versions:
"@apollo/gateway": "0.10.7",
"apollo-server-express": "2.9.6",
"graphql": "14.5.8"

What is the issue ?
When there are no federated services running and if we try to start the apollo gateway it throws unhandled promise rejection error and is repeatedly flooding the console out with error messages.

Issue Reference :
Encountered error when loading app at http://localhost:5000/graphql: request to http://localhost:5000/graphql failed, reason: connect ECONNREFUSED 127.0.0.1:5000
(node:19144) UnhandledPromiseRejectionWarning: Error: Expected undefined to be a GraphQL schema.
at assertSchema (C:\Users\gateway-app\dist\server.js:346559:11)
at validateSchema (C:\Users\gateway-app\dist\server.js:346874:64)
at assertValidSchema (C:\Users\gateway-app\dist\server.js:346897:16)
at assertValidExecutionArguments (C:\Users\gateway-app\dist\server.js:337948:76)
at executeImpl (C:\gateway-app\dist\server.js:337898:3)
at Module.execute (C:\Users\gateway-app\dist\server.js:337876:63)
at Object.generateSchemaHash (C:\Users\gateway-app\dist\server.js:307665:32)
at ApolloServer.generateSchemaDerivedData (C:\Users\gateway-app\dist\server.js:306390:41)
at ApolloServerBase.schemaDerivedData._schema.then.schema (C:\Users\gateway-app\dist\server.js:306317:66)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:19144) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting
a promise which was not handled with .catch(). (rejection id: 4)
(node:19144) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Repeated Flooding of error messages of this type -
Error: Expected undefined to be a GraphQL schema.
at assertSchema (C:\Users\gateway-app\dist\server.js:346559:11)
at validateSchema (C:\Users\gateway-app\dist\server.js:346874:64)
at assertValidSchema (C:\Users\gateway-app\dist\server.js:346897:16)
at assertValidExecutionArguments (C:\Users\gateway-app\dist\server.js:337948:76)
at executeImpl (C:\Users\gateway-app\dist\server.js:337898:3)
at Module.execute (C:\Users\gateway-app\dist\server.js:337876:63)
at Object.generateSchemaHash (C:\Users\gateway-app\dist\server.js:307665:32)
at ApolloServer.generateSchemaDerivedData (C:\Users\gateway-app\dist\server.js:306390:41)
at ApolloServerBase.schemaDerivedData._schema.then.schema (C:\Users\gateway-app\dist\server.js:306317:66)
at process._tickCallback (internal/process/next_tick.js:68:7)

Firstly, I'm unable to handle the "Unhandled promise rejection" in this scenario when none of the federated services are up and running as wrapping the entire block within try/catch still throws the promise rejection error.

Secondly, why do we see the aforementioned error messages being printed repeatedly for every tick ? Does the gateway continue to fetch schema repeatedly from each federated service in the service list if the service is down ?

Is there a graceful way to recover the gateway if none of the federated services are available at the time the gateway starts ?

@yuzhenmi
Copy link

yuzhenmi commented Nov 11, 2019

I'm also having the same issue. I've tried setting the parameter experimental_pollInterval.
While this made the logs print:

apollo-gateway: Gateway config has changed, updating schema

upon the federated service becoming available, the gateway still continues to throw Expected undefined to be a GraphQL schema. for each incoming request until it is restarted. I'm guessing this is a misconfiguration somewhere? I haven't used federation in production yet but I can't imagine this behaviour being tolerated for a production environment.

@rtdt99
Copy link
Author

rtdt99 commented Nov 12, 2019

@yuzhenmi : Agree. And on a side note, experimental_polling is not recommended for production environment. And there is no off-the-shelf solution for 'HotReload' of schema at the gateway level unless you go with Apollo Graph Manager which provides schema registry that has some builtin webhooks that trigger hot reload of schema.

@cinfantino
Copy link

cinfantino commented Nov 14, 2019

I'm having the exact same issue. Cannot figure out how to handle the error, but this makes it difficult to deploy to production. If the gateway comes up before any of the federated services come up this error pops up and I need to restart the gateway.

Is this expected behavior? That the gateway will never be able to start unless all the federated services are healthy?

@brafdlog
Copy link

We have this error and we are using managed apollo federation (the graph manager)

@yuzhenmi
Copy link

@rvtarig7 Interesting mention of webhooks. I guess one can implement similar webhooks as a custom temporary solution until this is addressed. I imagine it won't be that difficult to do this over HTTP, key-value store or some form of a messaging system.

@abernix
Copy link
Member

abernix commented Mar 23, 2020

Thanks for opening this originally. This should be fixed by a30bee7 in #3811, along with d8c682b from that same PR.

This should be available to try on the next tags of apollo-server-express and @apollo/gateway right now and will be promoted to the official release soon. Please try it today by running:

npm install apollo-server-express@next @apollo/gateway@next

Please report back if this doesn't resolve your problem!

@abernix abernix closed this as completed Mar 23, 2020
@abernix abernix added this to the Release 2.12.0 milestone Mar 23, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants