graphql-apollo-client 1.0.1 → 1.0.2

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 CHANGED
@@ -14,47 +14,53 @@ yarn add graphql-apollo-client
14
14
 
15
15
  ### Example
16
16
 
17
+
17
18
  ```js
18
- import configureClient from 'graphql-apollo-client';
19
+ import { configureClient } from 'graphql-apollo-client';
19
20
 
20
21
  const client = configureClient({
21
- httpEndpoint,
22
- wsEndpoint,
23
- bearerToken
22
+ httpEndpoint: '<HTTP_GRAPHQL_URL>',
23
+ wsEndpoint: '<WS_GRAPHQL_URL>',
24
+ bearerToken: 'Bearer <TOKEN>'
24
25
  })
25
26
  `
26
27
  ```
27
28
 
28
29
  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
+ Note: To define query you need import `gql` from `graphql-apollo-client`
30
31
 
31
32
  ```js
32
- import { gql } from 'graphql-tag';
33
+ import { gql } from 'graphql-apollo-client';
34
+
35
+
36
+ const query = gql`
37
+ query Books {
38
+ books {
39
+ title
40
+ author
41
+ }
42
+ }
43
+ `
44
+
45
+ const subscription = gql`
46
+ subscription {
47
+ realtimeMeasurement(deviceId: "pM8SEyRQ") {
48
+ activePowerImport
49
+ time
50
+ }
51
+ }
52
+ `
33
53
 
34
54
  client
35
55
  .query({
36
- query: gql`
37
- query Books {
38
- books {
39
- title
40
- author
41
- }
42
- }
43
- `,
56
+ query: query,
44
57
  variables: {},
45
58
  })
46
59
  .then(console.log)
47
60
 
48
61
  client
49
62
  .subscribe({
50
- query: gql`
51
- subscription {
52
- realtimeMeasurement(deviceId: "pM8SEyRQ") {
53
- activePowerImport
54
- time
55
- }
56
- }
57
- `,
63
+ query: subscription,
58
64
  variables: {}
59
65
  })
60
66
  .subscribe({
package/example.js ADDED
@@ -0,0 +1,33 @@
1
+ const { configureClient, gql } = require('./index');
2
+
3
+ const GRAPHQL_ENDPOINT = "https://api.ecomon.no";
4
+ const GRAPHQL_ENDPOINT_WS = "wss://api.ecomon.no";
5
+ const TOKEN = "Bearer intermediary-api-key_858bef2f-5b67-49b2-b7e0-c07a093f98be";
6
+
7
+ const client = configureClient({
8
+ httpEndpoint: GRAPHQL_ENDPOINT,
9
+ wsEndpoint: GRAPHQL_ENDPOINT_WS,
10
+ bearerToken: TOKEN
11
+ })
12
+
13
+
14
+
15
+ // Test subscription
16
+ client
17
+ .subscribe({
18
+ query: gql`
19
+ subscription {
20
+ realtimeMeasurement(deviceId: "pM8SEyRQ") {
21
+ activePowerImport
22
+ time
23
+ }
24
+ }
25
+ `,
26
+ variables: {}
27
+ })
28
+ .subscribe({
29
+ next(data) {
30
+ console.log(data);
31
+ }
32
+ });
33
+
package/index.js CHANGED
@@ -97,4 +97,4 @@ const configureClient = ({ httpEndpoint, wsEndpoint, bearerToken }) => {
97
97
 
98
98
 
99
99
 
100
- module.exports = configureClient
100
+ module.exports = { configureClient, gql }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-apollo-client",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -21,8 +21,8 @@
21
21
  },
22
22
  "scripts": {
23
23
  "start": "node index.js",
24
- "dev": "nodemon index.js"
24
+ "dev": "nodemon example.js"
25
25
  },
26
26
  "keywords": [],
27
27
  "description": ""
28
- }
28
+ }