Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Added graphql-ws #301

Merged
merged 6 commits into from
Jul 8, 2022
Merged

✨ Added graphql-ws #301

merged 6 commits into from
Jul 8, 2022

Conversation

GauBen
Copy link
Contributor

@GauBen GauBen commented Jun 7, 2022

Working to fix #288

  • Added graphql-ws
  • Preserve the current behavior (named legacy, because non-standard)
  • Implement open and off, if they still make sense
  • Write the documentation
  • Add graphql-ws as an optional peer dependency

@GauBen
Copy link
Contributor Author

GauBen commented Jun 15, 2022

Ping @aexol, there are a few merge conflicts now, are you working on this? Can I be of any help?

@LMaxence
Copy link

LMaxence commented Jun 20, 2022

Hello @aexol, could you update us on the status of this please ? There are no reviews, no feedbacks, and it is hard for us to know if we can expect this feature that we really really really need merged at some point or if we have to fork the project on our side.

@aexol
Copy link
Collaborator

aexol commented Jun 20, 2022

Sorry I thought it is not completed. Why not make a plugin instead of forcing graphql-ws to the main code?

@GauBen
Copy link
Contributor Author

GauBen commented Jun 21, 2022

It looks like Zeus support subscriptions out of the box but that's not the case because the implementation of apiSubscription is non standard. This PR is more of a fix to add the standard implementation to the core, as a non-default feature flag to keep the current behavior, rather a new feature. This PR will make Zeus compatible with Apollo and Yoga subscriptions that both follow this standard.

I haven't written the documentation yet because I wanted to make sure that you were okay with changes to the core. If you agree on this design, I'll complete the todo list.

Also, I chose to implement it as a non-breaking change; both the current implementation and graphql-ws currently coexist in generated.ts: https://github.com/graphql-editor/graphql-zeus/pull/301/files#diff-96a2264dfde03a31fbad8f2aac04c691dd6a7291919fbcbf258ba30782f394daR664

Then, you may or may not make graphql-ws the default in the next major version.

@aexol
Copy link
Collaborator

aexol commented Jun 21, 2022

If it won't break I am ok go ahead and finish it. It looks like you are implementing ts with strings. You don't have to do it anymore. Just use pure ts files and produce-lib script

@GauBen
Copy link
Contributor Author

GauBen commented Jun 21, 2022

If it won't break I am ok go ahead and finish it.

Great news! I'll try to have it ready by the end of the week.

you are implementing ts with strings

Not really, I did it the same way as you:

  • Created a TS file in src/TreeToTS/functions/apiSubscription/graphql-ws.ts
  • Added a bit of magic to src/CLI/libBuilder.ts to handle the new files

@GauBen GauBen force-pushed the feat/graphql-ws branch 2 times, most recently from 58ec55d to 68cc80a Compare June 27, 2022 11:55
@GauBen
Copy link
Contributor Author

GauBen commented Jun 27, 2022

Ready for review!

I feel like a lot of things are wrong:

The type SubscriptionToGraphQL is not correctly implemented

In the current implementation, this is the open function:

return {
    // ...
	open: (e: () => void) => {
		ws.onopen = e;
	}
}

link

And this is the signature:

export type SubscriptionToGraphQL<Z, T, SCLR extends ScalarDefinition> = {
  // ...
  open: () => void;
};

link

I committed documentation artifacts

Is this ok?

There is no way to properly cleanup

I implemented the cleanup function with a Proxy over ws.close, but it feels dirty. Graphql-ws offers a proper way to unsubscribe and clean up:

https://github.com/enisdenjo/graphql-ws/blob/77682cd3d9bac748b5b24e2f8cf88e1d98c7a448/src/client.ts#L434-L442

We should abstract the underlying transport

There are two competing standards, graphql-ws and graphql-sse, who share the exact same interface. We might be interested in moving from concrete APIs (ws, open...) to more abstract ones (transport, cleanup...), in order to make Zeus implementation-agnostic.

@aexol
Copy link
Collaborator

aexol commented Jul 1, 2022

Thanks @GauBen I'll try to review next days

@GauBen
Copy link
Contributor Author

GauBen commented Jul 4, 2022

Thank you! I'll sort the merge conflicts out soon.

package.json Outdated Show resolved Hide resolved
src/TreeToTS/index.ts Outdated Show resolved Hide resolved
src/TreeToTS/index.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@aexol aexol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice! Please fix those small errors and suggestions, so we can merge and release next version 🚀

@GauBen
Copy link
Contributor Author

GauBen commented Jul 7, 2022

Thanks for the review! You'll find all the changes in 6be6e47 .

@aexol aexol merged commit 4764601 into graphql-editor:master Jul 8, 2022
@GauBen
Copy link
Contributor Author

GauBen commented Jul 8, 2022

🎉

@aexol
Copy link
Collaborator

aexol commented Jul 8, 2022

Please test 5.1.7 when ready :)

@aexol
Copy link
Collaborator

aexol commented Jul 8, 2022

Thank you!

@GauBen
Copy link
Contributor Author

GauBen commented Jul 11, 2022

Everything works on my side! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Does Zues support the GraphQL over WebSocket Protocol?
3 participants