forked from absinthe-graphql/absinthe-socket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readmeTemplate.ejs
91 lines (66 loc) · 2.16 KB
/
readmeTemplate.ejs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# <%= name %>
> <%= description %>
<!-- START doctoc -->
<!-- END doctoc -->
## Installation
### Using [npm](https://docs.npmjs.com/cli/npm)
```
$ npm install --save <%= name %>
```
### Using [yarn](https://yarnpkg.com)
```
$ yarn add <%= name %>
```
## Examples
1. Create AbsintheSocketLink (`absinthe-socket-link.js`)
```javascript
// @flow
import * as AbsintheSocket from "@absinthe/socket";
import {createAbsintheSocketLink} from "@absinthe/socket-apollo-link";
import {Socket as PhoenixSocket} from "phoenix";
export default createAbsintheSocketLink(AbsintheSocket.create(
new PhoenixSocket("ws://localhost:4000/socket")
));
```
2. Send all the operations using AbsintheSocketLink
```javascript
// @flow
import ApolloClient from "apollo-client";
import {InMemoryCache} from "apollo-cache-inmemory";
// see example 1
import absintheSocketLink from "./absinthe-socket-link";
const client = new ApolloClient({
link: absintheSocketLink,
cache: new InMemoryCache()
});
```
3. Subscribe using AbsintheSocketLink and send queries and mutations using HttpLink
```javascript
// @flow
import ApolloClient from "apollo-client";
import {createHttpLink} from "apollo-link-http";
import {hasSubscription} from "@jumpn/utils-graphql";
import {InMemoryCache} from "apollo-cache-inmemory";
import {split} from "apollo-link";
// see example 1
import absintheSocketLink from "./absinthe-socket-link";
const link = split(
operation => hasSubscription(operation.query),
absintheSocketLink,
createHttpLink({uri: "/graphql"})
);
const client = new ApolloClient({
link,
cache: new InMemoryCache()
});
```
## API
## References
- [Absinthe Phoenix Socket](https://github.com/absinthe-graphql/absinthe-socket/tree/master/packages/socket)
- **Apollo Link**
- [Apollo Client](http://apollo-link-docs.netlify.com/docs/link/#apollo-client)
- [Terminating Links](http://apollo-link-docs.netlify.com/docs/link/overview.html#terminating)
- [Directional Composition](http://apollo-link-docs.netlify.com/docs/link/composition.html#directional)
- [Http Link](http://apollo-link-docs.netlify.com/docs/link/links/http.html)
## License
[<%= license %>](LICENSE.txt) :copyright: Jumpn Limited.