Moved from GitHub dgraph/4832
Posted by marvin-hansen:
Task: Building a GraphQL data schema that integrates into a large master schema.
What you wanted to do
I wanted to auto-propagate schema changes from DGraph into the master schema. I guess that’s called hot-reloading, but it’s not supported.
What you actually did
When the schema got an update, I use a bash script to upload it into DGraph. There is some snafu with duplicate fields after type-changes, so every once in a while, I drop-all the dev DB to clear the accumulated dead fields. I think there is an open issue already. However, once the schema has been updated in DGraph, the client needs to reload the updated schema manually because changes do not propagate further.
Why that wasn’t great, with examples
Manually reloading a data schema is not the end of the world, but after having reloaded the data schema several dozen times, I was kinda questioning the purpose of this…
The not-so-great part comes from preventing auto-schema merging of disjoint sub-schemas, which increasingly becomes a necessity when your master schema consists of an ever-growing number of sources.
Specifically, the master-schema I use does the auto-merging but also serves as a gatekeeper in the sense of preventing merging conflicting changes into the master schema. Because of that gatekeeper function, it is technically safe to auto-merge from any source that pushes changes downstream.
Obviously, I was wondering if there is a better way to auto-reload the GraphQL schema in DGraph?
What would be a great solution?
After a bit of online search, it turned out, yes, there is a much better way when using server-side event streams which pushes an updated GraphQL schema down to the client, and with that, manually schema updating is gone. The feature is currently supported in Altair and Postgraphile and it would be extremely useful to add it to DGraph to support way faster schema driven development.
A flag to enable/disable hot reloading would be useful to move from development to production.
Any external references to support your case
A better GraphQL developer experience with ‘X-GraphQL-Event-Stream’
Server side events example code (TS): https://github.com/graphile/postgraphile/blob/ede614c5eeb11556dea6f079b98e4f53e5a92439/src/postgraphile/http/setupServerSentEvents.ts
Client side http header: