Fix zeus generated file when using graphql-ws subscriptions and Node#390
Fix zeus generated file when using graphql-ws subscriptions and Node#390gthau wants to merge 2 commits intographql-editor:masterfrom
Conversation
Explanation: - according to graphql-ws recipes (https://the-guild.dev/graphql/ws/recipes), using `createClient` on Node requires to explicitly pass the WebSocket implementation, contrary to the browser. - when using Node, we want to import the type definition for Headers from 'node-fetch', if not the type definition from TS lib DOM is used, and it raises an Error when typechecking with tsc.
|
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. Any more detailed instructions are welcome. |
The file generated by Zeus is missing a few things when using both the
--n(target Node) and--subscriptions graphql-ws(subscriptions withgraphql-wslib instead of the legacy websocket client):Headerstype from@types/node-fetchas the type definition is not compatible with the one from TS lib DOM (Headers in the browser).webSocketImplparam must be passed to thecreateClientfunction, as Node doesn't have an out-of-the-box implementation of WebSocket as the browsers doPoint 1 creates a
tsccompile time error.Point 2 creates a runtime
graphql-wserror.Open question:
What to do with the
apiSubscriptionfunction? 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.