How to support HMR with Pothos
I couldn't find any examples of this, so testing the waters a bit. We have a pretty huge module graph, to the point that process starts/restarts take a long time. So I started looking into using chokidar to purge modules from the import cache, it was working pretty well but I hit a wall with Pothos.
It seems the builder pattern is a little at odds with what I'm trying to achieve, because if a module with some gql types in is re-executed, Pothos will error.
I can't see a current workaround, but I'm wondering how viable it is to somehow support putting the builder into a mode which allows redefinition of types in a robust way.
Yeah, this is definitely not easy with the builder pattern. I don't know how your invalidation works, but the pattern used here: https://github.com/hayes/svelekit-graphql-test/blob/main/src/graphql/builder.ts. would be a good place to start.
Basically, if you dynamically import the file that generates the schema into the builder class (this creates a circular dependency).
The effect if this is that, the file that build the schema generally needs to import every file that makes up the schema, so it will become invalidated when anything in the schema changes. Normally the file that creates the builder would not be invalidated, but if it has a dynamic import of the build schema, it should also be invalidated, which should end up re-building the entire schema on every change. Obviously this isn't perfect, but its the best option I have come up with for this sort of builder pattern
Interesting, I'll give that a try