@kubun/with-apollo 0.4.0 → 0.5.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 CHANGED
@@ -5,4 +5,3 @@ export type LinkParams = {
5
5
  graphID: string;
6
6
  };
7
7
  export declare function createLink(params: LinkParams): ApolloLink;
8
- //# sourceMappingURL=index.d.ts.map
package/lib/index.js CHANGED
@@ -1,42 +1 @@
1
- import { ApolloLink, Observable } from '@apollo/client';
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 e,Observable as r}from"@apollo/client";import{getMainDefinition as t,print as i}from"@apollo/client/utilities";function n(e){return new r(r=>{e.then(e=>{r.next(e),r.complete()},e=>{r.error(e)})})}function o(e){return new r(r=>{r.error(e)})}export function createLink(r){let{client:a,graphID:u}=r;return new e(e=>{let r=t(e.query);if("OperationDefinition"!==r.kind)return o(Error(`Invalid definition: ${r.kind}, expected OperationDefinition`));switch(r.operation){case"query":return n(a.queryGraph({id:u,text:i(e.query),variables:e.variables}));case"mutation":return n(a.mutateGraph({id:u,text:i(e.query),variables:e.variables}));default:return o(Error(`Unsupported operation: ${r.operation}`))}})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/with-apollo",
3
- "version": "0.4.0",
3
+ "version": "0.5.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.0.12",
18
+ "@apollo/client": "^4.1.3",
19
19
  "graphql": "^16.12.0"
20
20
  },
21
21
  "devDependencies": {
22
- "@kubun/client": "^0.4.0"
22
+ "@kubun/client": "^0.5.0"
23
23
  },
24
24
  "scripts": {
25
25
  "build:clean": "del lib",
@@ -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"}