graphql-apollo-client 1.0.3 → 1.0.5

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.
Files changed (3) hide show
  1. package/example.js +10 -10
  2. package/index.js +24 -36
  3. package/package.json +7 -3
package/example.js CHANGED
@@ -1,16 +1,14 @@
1
1
  const { configureClient, gql } = require('./index');
2
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";
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
6
 
7
7
  const client = configureClient({
8
8
  httpEndpoint: GRAPHQL_ENDPOINT,
9
9
  wsEndpoint: GRAPHQL_ENDPOINT_WS,
10
- bearerToken: TOKEN
11
- })
12
-
13
-
10
+ bearerToken: TOKEN,
11
+ });
14
12
 
15
13
  // Test subscription
16
14
  client
@@ -23,11 +21,13 @@ client
23
21
  }
24
22
  }
25
23
  `,
26
- variables: {}
24
+ variables: {},
27
25
  })
28
26
  .subscribe({
29
27
  next(data) {
30
28
  console.log(data);
29
+ },
30
+ error(err) {
31
+ console.log(err)
31
32
  }
32
- });
33
-
33
+ })
package/index.js CHANGED
@@ -1,17 +1,16 @@
1
- const { InMemoryCache } = require("apollo-cache-inmemory");
2
- const ApolloClient = require("apollo-client").default;
3
- const { WebSocketLink } = require("apollo-link-ws");
4
- const gql = require("graphql-tag");
5
- const WebSocket = require("ws");
6
- const ApolloLink = require("apollo-link");
7
- const { createHttpLink } = require("apollo-link-http");
8
- const { getMainDefinition } = require("apollo-utilities");
9
- const fetch = (...args) =>
10
- import("node-fetch").then(({ default: fetch }) => fetch(...args));
1
+ const { InMemoryCache } = require('apollo-cache-inmemory');
2
+ const ApolloClient = require('apollo-client').default;
3
+ const { WebSocketLink } = require('apollo-link-ws');
4
+ const gql = require('graphql-tag');
5
+ const WebSocket = require('ws');
6
+ const ApolloLink = require('apollo-link');
7
+ const { createHttpLink } = require('apollo-link-http');
8
+ const { getMainDefinition } = require('apollo-utilities');
11
9
 
10
+ require('isomorphic-fetch');
12
11
  /**
13
- *
14
- * @param {{ httpEndpoint: string, wsEndpoint: string, bearerToken: string }} params
12
+ *
13
+ * @param {{ httpEndpoint: string, wsEndpoint: string, bearerToken: string }} params
15
14
  * @returns { ApolloClient }
16
15
  */
17
16
 
@@ -22,55 +21,49 @@ const configureClient = ({ httpEndpoint, wsEndpoint, bearerToken }) => {
22
21
  reconnect: true,
23
22
  connectionParams: async () => {
24
23
  return {
25
- Authorization: bearerToken
24
+ Authorization: bearerToken,
26
25
  };
27
- }
26
+ },
28
27
  },
29
- webSocketImpl: WebSocket
28
+ webSocketImpl: WebSocket,
30
29
  });
31
30
 
32
31
  const httpLink = createHttpLink({
33
32
  uri: httpEndpoint,
34
- fetch: fetch,
35
33
  headers: {
36
- Authorization: bearerToken
37
- }
34
+ Authorization: bearerToken,
35
+ },
38
36
  });
39
37
 
40
38
  const splitLink = ApolloLink.split(
41
39
  ({ query }) => {
42
40
  const definition = getMainDefinition(query);
43
41
 
44
- return (
45
- definition.kind === "OperationDefinition" &&
46
- definition.operation === "subscription"
47
- );
42
+ return definition.kind === 'OperationDefinition' && definition.operation === 'subscription';
48
43
  },
49
44
  wsLink,
50
45
  httpLink
51
46
  );
52
47
  const apolloClient = new ApolloClient({
53
48
  cache: new InMemoryCache(),
54
- link: splitLink
49
+ link: splitLink,
55
50
  });
56
51
 
57
- return apolloClient
58
- }
59
-
60
-
52
+ return apolloClient;
53
+ };
61
54
 
62
55
  /**
63
56
  * Example
64
57
  * const GRAPHQL_ENDPOINT = "https://api.ecomon.no";
65
58
  * const GRAPHQL_ENDPOINT_WS = "wss://api.ecomon.no";
66
59
  * const TOKEN = "Bearer intermediary-api-key_858bef2f-5b67-49b2-b7e0-c07a093f98be";
67
- *
60
+ *
68
61
  * const client = configureClient({
69
62
  * httpEndpoint: GRAPHQL_ENDPOINT,
70
63
  * wsEndpoint: GRAPHQL_ENDPOINT_WS,
71
64
  * bearerToken: TOKEN
72
65
  * })
73
- *
66
+ *
74
67
  * // Test subscription
75
68
  * client
76
69
  * .subscribe({
@@ -89,12 +82,7 @@ const configureClient = ({ httpEndpoint, wsEndpoint, bearerToken }) => {
89
82
  * console.log(data);
90
83
  * }
91
84
  * });
92
- *
85
+ *
93
86
  */
94
87
 
95
-
96
-
97
-
98
-
99
-
100
- module.exports = { configureClient, gql }
88
+ module.exports = { configureClient, gql };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "graphql-apollo-client",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
- "repository":"https://github.com/mxshahan/graphql-apollo-client.git",
6
+ "repository": "https://github.com/mxshahan/graphql-apollo-client.git",
7
7
  "dependencies": {
8
8
  "apollo-cache-inmemory": "1.6.6",
9
9
  "apollo-client": "2.6.10",
@@ -24,6 +24,10 @@
24
24
  "start": "node index.js",
25
25
  "dev": "nodemon example.js"
26
26
  },
27
- "keywords": [" nodejs", "graphql", " javascript"],
27
+ "keywords": [
28
+ " nodejs",
29
+ "graphql",
30
+ " javascript"
31
+ ],
28
32
  "description": ""
29
33
  }