graphql-zeus
graphql-zeus copied to clipboard
Fix zeus generated file when using graphql-ws subscriptions and Node
The file generated by Zeus is missing a few things when using both the --n (target Node) and --subscriptions graphql-ws (subscriptions with graphql-ws lib instead of the legacy websocket client):
- We must import the
Headerstype from@types/node-fetchas the type definition is not compatible with the one from TS lib DOM (Headers in the browser). - for Node, according the graphql-ws recipes (https://the-guild.dev/graphql/ws/recipes), the
webSocketImplparam must be passed to thecreateClientfunction, as Node doesn't have an out-of-the-box implementation of WebSocket as the browsers do
Point 1 creates a tsc compile time error.
Point 2 creates a runtime graphql-ws error.
Open question:
What to do with the apiSubscription function? I didn't know out to distinguish between the node or the browser for this function and how we could pass it a WebSocket implementation in the case of Node and graphql-ws.
Good point. You need to regenerated generated file however before commiting this. You should not edit generated file, but edit the files that are used as an output of generation
Good point. You need to regenerated generated file however before commiting this. You should not edit generated file, but edit the files that are used as an output of generation
Ohhh, I didn't see that it's a 2-level generation. I'll have a look at the source files that the libBuilder.ts file processes and bundles to create this generated.ts file.
I'm hitting a wall here.
From what I understand, the files under packages/graphql-zeus-core/TreeToTS/functions/new are not generated but are actual source code files bundled by libBundler.ts, along with files under packages/graphql-zeus-core/TreeToTS/functions/apiSubscription, with a bit of processing to remove imports and such.
I'm not sure how to integrate the env variable that's necessary to take the proper implementation of WebSocket (native in browser or from ws package in node world).
Any more detailed instructions are welcome.