Skip to content

Commit 8dfde38

Browse files
committed
Add documentation
1 parent e7eb345 commit 8dfde38

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

guides/javascript_client/urql_subscriptions.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ desc: GraphQL subscriptions with GraphQL-Ruby and urql
88
index: 4
99
---
1010

11-
GraphQL-Ruby currently supports using `urql` with the {% internal_link "Pusher implementation", "/subscriptions/pusher_implementation" %}. For example:
11+
GraphQL-Ruby currently supports using `urql` with the {% internal_link "ActionCable", "/subscriptions/action_cable_implementation" %} and {% internal_link "Pusher implementation", "/subscriptions/pusher_implementation" %}. For example:
12+
13+
## Pusher
1214

1315
```js
1416
import SubscriptionExchange from "graphql-ruby-client/subscriptions/SubscriptionExchange"
@@ -29,5 +31,30 @@ const client = new Client({
2931
});
3032
```
3133

34+
## ActionCable
35+
36+
```js
37+
import { createConsumer } from "@rails/actioncable";
38+
import createActionCableFetcher from "graphql-ruby-client/subscriptions/createActionCableFetcher";
39+
import createUrqlActionCableSubscription from "graphql-ruby-client/subscriptions/createUrqlActionCableSubscription";
40+
41+
const actionCable = createConsumer('ws://127.0.0.1:3000/cable');
42+
const forwardToActionCableExchange = createUrqlActionCableSubscription.create({ consumer: actionCable })
43+
44+
const client = new Client({
45+
url: 'http://127.0.0.1:3000/graphql',
46+
exchanges: [
47+
cacheExchange, fetchExchange, subscriptionExchange({
48+
forwardSubscription: operation => forwardToActionCableExchange(operation)
49+
})
50+
]
51+
});
52+
53+
const App = () => (
54+
<Provider value={client}>
55+
// ... your app code here
56+
</Provider>
57+
);
58+
```
3259

3360
Want to use `urql` with another subscription backend? Please {% open_an_issue "Using urql with ..." %}.

0 commit comments

Comments
 (0)