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

Multiple queries on the same socket #34

Closed
Amzd opened this issue Apr 13, 2021 · 2 comments
Closed

Multiple queries on the same socket #34

Amzd opened this issue Apr 13, 2021 · 2 comments

Comments

@Amzd
Copy link
Contributor

Amzd commented Apr 13, 2021

Right now we create a new websocket for each query which is quite performant heavy and not necessary.

You can send multiple queries on one socket. You then define the results that you get back per id.

We'll need to change the listen part quite a lot for this so I'm looking for some feedback on how we should do it.

We need a way to share a socket between listen calls

So either;

  1. Save a socket for each endpoint without the user seeing them in a static variable or something.
  2. Have the user handle the socket; so have a createWebsocket function that gives the user an opened socket that they can give to the listen function.

The listen call needs to return something that you can use to stop that single query that you started.

In the listen call I will add an id to the message (this was already commented). To stop a query from listening you need its id so we could;

  1. Just return the id and have a function to stop listening per id.
  2. Return an object that has a close function to stop listening to its query.
@Amzd
Copy link
Contributor Author

Amzd commented May 3, 2021

This and #32 are fixed in https://github.com/Amzd/swift-graphql/tree/WebSockets-rework

Some work that still has to be done:

  • Move classes out of HTTP+WebSockets.swift to their own files
  • Test serverside errors. The protocol says it returns GraphQLError[] which I assumed is an array of our GraphQLError type so I decode it as such.

@maticzav
Copy link
Owner

@Amzd could you create a PR so we can move this here as well?

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

No branches or pull requests

2 participants