graphql-yoga
graphql-yoga copied to clipboard
Hot schema reloading with grapphql subscription with WS support
I'm trying to add the "hot schema reloading", as seen here https://the-guild.dev/graphql/stitching/handbook/architecture/hot-schema-reloading, with the subscriptions support seen here in the ws section https://the-guild.dev/graphql/yoga-server/docs/features/subscriptions#graphql-over-websocket-protocol-via-graphql-ws
Basically, where fields that require a schema such as:
createYoga({
schema: createSchema({...}),
...}
or
onSubscribe: async (ctx, msg) => {
....
const args: ExecutionArgs = {
schema: envelop.schema,
...},
}
I susbtitute them with a function that can be called to reload the new schema:
createYoga({
schema: () =>loader.schema,
...}
or
onSubscribe: async (ctx, msg) => {
....
const args: ExecutionArgs = {
schema: ()=> loader.schema,
...},
}
This implementation works with queries and mutations API but it doesn't work with subscriptions:
-
yogaServer.getEnveloped({...}) return the error
No schema found for this request. Make sure you use this plugin with GraphQL Yoga.(returned from line 53 in the file use-schema.js) because the object schemaByRequest is empty - I don't know if it work as intended but I've see a weird behaviour: when I make a query or a mutation, the function onRequestParse (use-schema.js, row 34, that fill the object schemaByRequest) is called first then the function OnEnveloped(use-schema.js, row 47) ; if i make a subscription, the OnRequestParse function is never called, the item schemaByRequest stay empty and the OnEnveloped fails.
So, apparently, this function is not available (or is restricted from a bug)