@kubun/with-apollo 0.2.0 → 0.3.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/lib/index.d.ts.map +1 -1
- package/lib/index.js +14 -10
- package/package.json +4 -4
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,MAAM,gBAAgB,CAAA;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAsBhD,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,WAAW,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAgCzD"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApolloLink, Observable } from '@apollo/client';
|
|
2
|
-
import {
|
|
3
|
-
function
|
|
2
|
+
import { getMainDefinition, print } from '@apollo/client/utilities';
|
|
3
|
+
function toObservable(promise) {
|
|
4
4
|
return new Observable((observer)=>{
|
|
5
5
|
promise.then((result)=>{
|
|
6
6
|
observer.next(result);
|
|
@@ -10,29 +10,33 @@ function toObversable(promise) {
|
|
|
10
10
|
});
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
+
function observableWithError(error) {
|
|
14
|
+
return new Observable((subscriber)=>{
|
|
15
|
+
subscriber.error(error);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
13
18
|
export function createLink(params) {
|
|
14
19
|
const { client, graphID } = params;
|
|
15
20
|
return new ApolloLink((operation)=>{
|
|
16
|
-
const
|
|
17
|
-
const definition = getMainDefinition(query);
|
|
21
|
+
const definition = getMainDefinition(operation.query);
|
|
18
22
|
if (definition.kind !== 'OperationDefinition') {
|
|
19
|
-
return
|
|
23
|
+
return observableWithError(new Error(`Invalid definition: ${definition.kind}, expected OperationDefinition`));
|
|
20
24
|
}
|
|
21
25
|
switch(definition.operation){
|
|
22
26
|
case 'query':
|
|
23
|
-
return
|
|
27
|
+
return toObservable(client.queryGraph({
|
|
24
28
|
id: graphID,
|
|
25
|
-
text: print(query),
|
|
29
|
+
text: print(operation.query),
|
|
26
30
|
variables: operation.variables
|
|
27
31
|
}));
|
|
28
32
|
case 'mutation':
|
|
29
|
-
return
|
|
33
|
+
return toObservable(client.mutateGraph({
|
|
30
34
|
id: graphID,
|
|
31
|
-
text: print(query),
|
|
35
|
+
text: print(operation.query),
|
|
32
36
|
variables: operation.variables
|
|
33
37
|
}));
|
|
34
38
|
default:
|
|
35
|
-
|
|
39
|
+
return observableWithError(new Error(`Unsupported operation: ${definition.operation}`));
|
|
36
40
|
}
|
|
37
41
|
});
|
|
38
42
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/with-apollo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"license": "see LICENSE.md",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"type": "module",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
],
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@apollo/client": "^
|
|
19
|
-
"graphql": "^16.
|
|
18
|
+
"@apollo/client": "^4.0.3",
|
|
19
|
+
"graphql": "^16.11.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@kubun/client": "^0.
|
|
22
|
+
"@kubun/client": "^0.3.7"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build:clean": "del lib",
|