@kubun/with-apollo 0.4.0 → 0.6.0
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 +0 -1
- package/lib/index.js +1 -42
- package/package.json +3 -3
- package/lib/index.d.ts.map +0 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,42 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getMainDefinition, print } from '@apollo/client/utilities';
|
|
3
|
-
function toObservable(promise) {
|
|
4
|
-
return new Observable((observer)=>{
|
|
5
|
-
promise.then((result)=>{
|
|
6
|
-
observer.next(result);
|
|
7
|
-
observer.complete();
|
|
8
|
-
}, (err)=>{
|
|
9
|
-
observer.error(err);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
function observableWithError(error) {
|
|
14
|
-
return new Observable((subscriber)=>{
|
|
15
|
-
subscriber.error(error);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
export function createLink(params) {
|
|
19
|
-
const { client, graphID } = params;
|
|
20
|
-
return new ApolloLink((operation)=>{
|
|
21
|
-
const definition = getMainDefinition(operation.query);
|
|
22
|
-
if (definition.kind !== 'OperationDefinition') {
|
|
23
|
-
return observableWithError(new Error(`Invalid definition: ${definition.kind}, expected OperationDefinition`));
|
|
24
|
-
}
|
|
25
|
-
switch(definition.operation){
|
|
26
|
-
case 'query':
|
|
27
|
-
return toObservable(client.queryGraph({
|
|
28
|
-
id: graphID,
|
|
29
|
-
text: print(operation.query),
|
|
30
|
-
variables: operation.variables
|
|
31
|
-
}));
|
|
32
|
-
case 'mutation':
|
|
33
|
-
return toObservable(client.mutateGraph({
|
|
34
|
-
id: graphID,
|
|
35
|
-
text: print(operation.query),
|
|
36
|
-
variables: operation.variables
|
|
37
|
-
}));
|
|
38
|
-
default:
|
|
39
|
-
return observableWithError(new Error(`Unsupported operation: ${definition.operation}`));
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
1
|
+
import{ApolloLink as r,Observable as e}from"@apollo/client";import{getMainDefinition as t,print as i}from"@apollo/client/utilities";function n(r){return new e(e=>{r.then(r=>{try{e.next(r),e.complete()}catch(r){e.error(r)}},r=>{e.error(r)})})}function o(r){return new e(e=>{e.error(r)})}export function createLink(e){let{client:a,graphID:u}=e;return new r(r=>{let e=t(r.query);if("OperationDefinition"!==e.kind)return o(Error(`Invalid definition: ${e.kind}, expected OperationDefinition`));switch(e.operation){case"query":return n(a.queryGraph({id:u,text:i(r.query),variables:r.variables}));case"mutation":return n(a.mutateGraph({id:u,text:i(r.query),variables:r.variables}));default:return o(Error(`Unsupported operation: ${e.operation}`))}})}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/with-apollo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
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": "^4.
|
|
18
|
+
"@apollo/client": "^4.1.4",
|
|
19
19
|
"graphql": "^16.12.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@kubun/client": "^0.
|
|
22
|
+
"@kubun/client": "^0.6.0"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build:clean": "del lib",
|
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|