forked from absinthe-graphql/absinthe-socket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadmeTemplate.ejs
104 lines (84 loc) · 3.07 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
92
93
94
95
96
97
98
99
100
101
102
103
104
# <%= name %>
> <%= description %>
<!-- START doctoc -->
<!-- END doctoc -->
## Features
- Immutable functional API
> All received and returned objects with the exception of AbsintheSocket
instances (there are plans to make this immutable too) are treated in an
immutable way. Objects have no methods and instead we provide independant
stateless functions to interact with them.
- Lazy connect / join
> If provided phoenix socket instance is not connected, then instead of
connecting at creation time, connection will be established on the next
invocation of [send](#send).
- Handle pending operations on connection lost
> Pending mutations will be aborted, queries will be resent, and subscriptions
reestablished.
- Cancellable requests
> Calling [cancel](#cancel) removes given notifier from absintheSocket instance
and sends a Cancel event to all its observers and unsubscribes in case it
holds a subscription request.
- Operations deduplication
> If an already sent request is given to [send](#send), then instead of sending
it again, the notifier associated with it will be returned.
- Observer support of recoverable errors
> Since connection lost is handled, then two events needs to exist to represent
this fact: Error (recoverable), Abort (unrecoverable).
- Multiple observers per request
> Calling [send](#send) returns a notifier which allows attaching any number of
observers that will be notified when result arrives.
- Observer interaction depending on operation type
> For the case of subscriptions, *Start* event is dispatched when the
subscription is established, while for the other types
(queries and mutations), when the request is sent.
## Installation
### Using [npm](https://docs.npmjs.com/cli/npm)
```
$ npm install --save phoenix <%= name %>
```
### Using [yarn](https://yarnpkg.com)
```
$ yarn add phoenix <%= name %>
```
## Types
```flowtype
type RequestStatus = "canceled" | "canceling" | "pending" | "sent" | "sending";
// from @jumpn/utils-graphql
type GqlRequest<Variables: void | Object = void> = {
operation: string,
variables?: Variables
};
// from @jumpn/utils-graphql
type GqlResponse<Data> = {
data?: Data,
errors?: Array<GqlError>
};
// from @jumpn/utils-graphql
type GqlOperationType = "mutation" | "query" | "subscription";
type Observer<Result, Variables: void | Object = void> = {|
onAbort?: (error: Error) => any,
onCancel?: () => any,
onError?: (error: Error) => any,
onStart?: (notifier: Notifier<Result, Variables>) => any,
onResult?: (result: Result) => any
|};
type Notifier<Result, Variables: void | Object = void> = {|
activeObservers: $ReadOnlyArray<Observer<Result, Variables>>,
canceledObservers: $ReadOnlyArray<Observer<Result, Variables>>,
isActive: boolean,
operationType: GqlOperationType,
request: GqlRequest<Variables>,
requestStatus: RequestStatus,
subscriptionId?: string
|};
type AbsintheSocket = {|
channel: Channel,
channelJoinCreated: boolean,
notifiers: Array<Notifier<any>>,
phoenixSocket: PhoenixSocket
|};
```
## API
## License
[<%= license %>](LICENSE.txt) :copyright: Jumpn Limited.