@kubun/with-apollo 0.3.0 → 0.4.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgC,MAAM,gBAAgB,CAAA;AAEzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAgBhD,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,CAuBzD"}
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 { checkDocument, getMainDefinition, print } from '@apollo/client/utilities';
3
- function toObversable(promise) {
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 query = checkDocument(operation.query);
17
- const definition = getMainDefinition(query);
21
+ const definition = getMainDefinition(operation.query);
18
22
  if (definition.kind !== 'OperationDefinition') {
19
- return null;
23
+ return observableWithError(new Error(`Invalid definition: ${definition.kind}, expected OperationDefinition`));
20
24
  }
21
25
  switch(definition.operation){
22
26
  case 'query':
23
- return toObversable(client.queryGraph({
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 toObversable(client.mutateGraph({
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
- throw new Error(`Unsupported operation: ${definition.operation}`);
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.0",
3
+ "version": "0.4.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": "^3.13.6",
19
- "graphql": "^16.9.0"
18
+ "@apollo/client": "^4.0.12",
19
+ "graphql": "^16.12.0"
20
20
  },
21
21
  "devDependencies": {
22
- "@kubun/client": "^0.3.0"
22
+ "@kubun/client": "^0.4.0"
23
23
  },
24
24
  "scripts": {
25
25
  "build:clean": "del lib",
@@ -28,7 +28,7 @@
28
28
  "build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
29
29
  "build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
30
30
  "test:types": "tsc --noEmit",
31
- "test:unit": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js",
31
+ "test:unit": "vitest run",
32
32
  "test": "pnpm run test:types && pnpm run test:unit"
33
33
  }
34
34
  }