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

Support Websockets #17

Closed
sean-clayton opened this issue Jan 30, 2018 · 8 comments
Closed

Support Websockets #17

sean-clayton opened this issue Jan 30, 2018 · 8 comments

Comments

@sean-clayton
Copy link

sean-clayton commented Jan 30, 2018

A tiny brief history: https://twitter.com/seanybingbong/status/958359534615056394

Currently I'm able to do all of my GraphQL transactions via websockets with Apollo Link like so:

const client = new ApolloClient({
  link: WebsocketLink(), // 
  cache: new InMemoryCache(),
});

I already need a websocket connection for my app so I thought I could use it to do all my GraphQL transactions since GraphQL doesn't care about transport. My app hardly has any Apollo-specific, so I thought I'd give urql a shot, but I'd still like to keep using websockets since the timing benefits over HTTP are nice (though, somewhat unnoticeable).

Maybe doing something like url: "wss://path.to/socket" in urql would trigger the use of websockets?

@kenwheeler kenwheeler added enhancement help wanted ⛏️ Extra attention is needed labels Feb 2, 2018
@kitten
Copy link
Member

kitten commented May 26, 2018

There's no de-facto standard for GraphQL over Websockets, not even for subscriptions. That being said, in v0.3+ we do support subscriptions:

Unfortunately the docs aren't quite ready yet, but v0.3 is available as a prerelease.

And if you'd like to implement some kind of custom transport layer, in v0.3 we now have "exchanges" which are kind of like Apollo's links. We even have an experimental package that allows you to use apollo-links with urql: http://github.com/kitten/urql-exchange-apollo

There's also no docs for that yet either (sorry) but here's an example snippet: https://twitter.com/_philpl/status/996325272009011200

So all in all v0.3 supports these custom usages 👍 Hope that works for you. Please let us know

@kitten kitten closed this as completed May 26, 2018
@kitten kitten removed the help wanted ⛏️ Extra attention is needed label May 26, 2018
@mjadczak
Copy link

@kitten Not opening a new issue since the answer might be "write your own exchange", but I've noticed that the subscriptionExchange can only be used for subscriptions. (At least the current version of) subscription-transport-ws allows for transporting all three of queries, mutations, and subscriptions over the WS connection, and this makes a lot of sense if you're already standing up the connection to service subscriptions.

Would supporting this be difficult? I see that currently the subscriptionExchange filters out anything which is not a subscription, but presumably simply removing this filtering would not be enough. Another thing which is a slight issue is that the top-level Client expects a url as one of its options (but I guess this is an issue with any exchange which does not actually fetch from this "main" URL).

@kitten
Copy link
Member

kitten commented Jun 25, 2019

@mjadczak It wouldn't be hard to make this happen per se, but it relies a lot on how the server and subscription-transport-ws handle subscriptions specifically. The subscriptionExchange however is built not to specifically rely on subscription-transport-ws and is only for subscriptions not for websockets in general.

That being said this would definitely be a candidate for a new exchange package, i.e. @urql/ws-exchange or something of that kind 👍

@mjadczak
Copy link

The subscriptionExchange however is built not to specifically rely on subscription-transport-ws

export interface SubscriptionExchangeOpts {
  // This has been modelled to work with subscription-transport-ws
  // See: https://github.com/apollographql/subscriptions-transport-ws#requestoptions--observableexecutionresult-returns-observable-to-execute-the-operation
  forwardSubscription: SubscriptionForwarder;
}

😛

I get it though. Sounds like a candidate for a "help wanted" issue then? Could you reopen this one, or shall I file a new one?

@kitten
Copy link
Member

kitten commented Jun 25, 2019

@mjadczak we don't plan to add all exchanges to this main repository and instead want more of them to be build separately. So feel free to get started on one and reach out to me directly if you need any help 👍

In the future we might convert this repo to a mono repo to accommodate for more packages though, although we'd prefer not to do this just yet 🙂

@AlaaZorkane
Copy link

Any updates on this? Would be really cool if we can send other forms of queries (Mutations etc...) via websocket

@kitten
Copy link
Member

kitten commented Jun 22, 2021

@AlaaZorkane Three year old issues aren't really insightful. you may want to check this though ✌️🤗https://formidable.com/open-source/urql/docs/advanced/subscriptions/

@AlaaZorkane
Copy link

Thanks! I actually always have that page open I don't know how I missed that part lol, appreciate the fast response 🙌

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

5 participants