graphql-apollo-client 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -5
- package/index.js +29 -27
- package/package.json +2 -2
package/README.md
CHANGED
@@ -1,9 +1,65 @@
|
|
1
|
-
#
|
1
|
+
# graphql-apollo-client
|
2
2
|
|
3
|
+
Helpful utility that will make your development process faster. This can be used in any library. Basically nodejs based.
|
3
4
|
|
4
|
-
###
|
5
|
-
|
5
|
+
### Install Package
|
6
|
+
```bash
|
7
|
+
npm install graphql-apollo-client --save
|
8
|
+
```
|
9
|
+
or
|
10
|
+
```bash
|
11
|
+
yarn add graphql-apollo-client
|
12
|
+
```
|
6
13
|
|
7
|
-
### To run this example:
|
8
14
|
|
9
|
-
|
15
|
+
### Example
|
16
|
+
|
17
|
+
```js
|
18
|
+
import configureClient from 'graphql-apollo-client';
|
19
|
+
|
20
|
+
const client = configureClient({
|
21
|
+
httpEndpoint,
|
22
|
+
wsEndpoint,
|
23
|
+
bearerToken
|
24
|
+
})
|
25
|
+
`
|
26
|
+
```
|
27
|
+
|
28
|
+
The above code is to configure client. Now it's time to use this client
|
29
|
+
Note: To define query you need to install graphql-tag to use `gql`
|
30
|
+
|
31
|
+
```js
|
32
|
+
import { gql } from 'graphql-tag';
|
33
|
+
|
34
|
+
client
|
35
|
+
.query({
|
36
|
+
query: gql`
|
37
|
+
query Books {
|
38
|
+
books {
|
39
|
+
title
|
40
|
+
author
|
41
|
+
}
|
42
|
+
}
|
43
|
+
`,
|
44
|
+
variables: {},
|
45
|
+
})
|
46
|
+
.then(console.log)
|
47
|
+
|
48
|
+
client
|
49
|
+
.subscribe({
|
50
|
+
query: gql`
|
51
|
+
subscription {
|
52
|
+
realtimeMeasurement(deviceId: "pM8SEyRQ") {
|
53
|
+
activePowerImport
|
54
|
+
time
|
55
|
+
}
|
56
|
+
}
|
57
|
+
`,
|
58
|
+
variables: {}
|
59
|
+
})
|
60
|
+
.subscribe({
|
61
|
+
next(data) {
|
62
|
+
console.log(data);
|
63
|
+
}
|
64
|
+
});
|
65
|
+
```
|
package/index.js
CHANGED
@@ -61,36 +61,38 @@ const configureClient = ({ httpEndpoint, wsEndpoint, bearerToken }) => {
|
|
61
61
|
|
62
62
|
/**
|
63
63
|
* Example
|
64
|
+
* const GRAPHQL_ENDPOINT = "https://api.ecomon.no";
|
65
|
+
* const GRAPHQL_ENDPOINT_WS = "wss://api.ecomon.no";
|
66
|
+
* const TOKEN = "Bearer intermediary-api-key_858bef2f-5b67-49b2-b7e0-c07a093f98be";
|
67
|
+
*
|
68
|
+
* const client = configureClient({
|
69
|
+
* httpEndpoint: GRAPHQL_ENDPOINT,
|
70
|
+
* wsEndpoint: GRAPHQL_ENDPOINT_WS,
|
71
|
+
* bearerToken: TOKEN
|
72
|
+
* })
|
73
|
+
*
|
74
|
+
* // Test subscription
|
75
|
+
* client
|
76
|
+
* .subscribe({
|
77
|
+
* query: gql`
|
78
|
+
* subscription {
|
79
|
+
* realtimeMeasurement(deviceId: "pM8SEyRQ") {
|
80
|
+
* activePowerImport
|
81
|
+
* time
|
82
|
+
* }
|
83
|
+
* }
|
84
|
+
* `,
|
85
|
+
* variables: {}
|
86
|
+
* })
|
87
|
+
* .subscribe({
|
88
|
+
* next(data) {
|
89
|
+
* console.log(data);
|
90
|
+
* }
|
91
|
+
* });
|
92
|
+
*
|
64
93
|
*/
|
65
94
|
|
66
|
-
const GRAPHQL_ENDPOINT = "https://api.ecomon.no";
|
67
|
-
const GRAPHQL_ENDPOINT_WS = "wss://api.ecomon.no";
|
68
|
-
const TOKEN = "Bearer intermediary-api-key_858bef2f-5b67-49b2-b7e0-c07a093f98be";
|
69
|
-
|
70
|
-
const client = configureClient({
|
71
|
-
httpEndpoint: GRAPHQL_ENDPOINT,
|
72
|
-
wsEndpoint: GRAPHQL_ENDPOINT_WS,
|
73
|
-
bearerToken: TOKEN
|
74
|
-
})
|
75
95
|
|
76
|
-
// Test subscription
|
77
|
-
client
|
78
|
-
.subscribe({
|
79
|
-
query: gql`
|
80
|
-
subscription {
|
81
|
-
realtimeMeasurement(deviceId: "pM8SEyRQ") {
|
82
|
-
activePowerImport
|
83
|
-
time
|
84
|
-
}
|
85
|
-
}
|
86
|
-
`,
|
87
|
-
variables: {}
|
88
|
-
})
|
89
|
-
.subscribe({
|
90
|
-
next(data) {
|
91
|
-
console.log(data);
|
92
|
-
}
|
93
|
-
});
|
94
96
|
|
95
97
|
|
96
98
|
|