graphql-editor / graphql-zeus

GraphQL client and GraphQL code generator with GraphQL autocomplete library generation ⚡⚡⚡ for browser,nodejs and react native ( apollo compatible )
https://graphqleditor.com/docs/tools/zeus/index/
MIT License
1.94k stars 105 forks source link

Fix zeus generated file when using graphql-ws subscriptions and Node #390

Open gthau opened 8 months ago

gthau commented 8 months ago

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):

  1. We must import the Headers type from @types/node-fetch as the type definition is not compatible with the one from TS lib DOM (Headers in the browser).
  2. for Node, according the graphql-ws recipes (https://the-guild.dev/graphql/ws/recipes), the webSocketImpl param must be passed to the createClient function, 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.

aexol commented 7 months ago

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

gthau commented 7 months ago

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.

gthau commented 6 months ago

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.