apollo-angular-signal 0.0.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/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# ApolloAngularSignal
|
|
2
|
+
|
|
3
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 21.0.0.
|
|
4
|
+
|
|
5
|
+
## Code scaffolding
|
|
6
|
+
|
|
7
|
+
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
ng generate component component-name
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ng generate --help
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Building
|
|
20
|
+
|
|
21
|
+
To build the library, run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
ng build apollo-angular-signal
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
|
|
28
|
+
|
|
29
|
+
### Publishing the Library
|
|
30
|
+
|
|
31
|
+
Once the project is built, you can publish your library by following these steps:
|
|
32
|
+
|
|
33
|
+
1. Navigate to the `dist` directory:
|
|
34
|
+
```bash
|
|
35
|
+
cd dist/apollo-angular-signal
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Run the `npm publish` command to publish your library to the npm registry:
|
|
39
|
+
```bash
|
|
40
|
+
npm publish
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Running unit tests
|
|
44
|
+
|
|
45
|
+
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
ng test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Running end-to-end tests
|
|
52
|
+
|
|
53
|
+
For end-to-end (e2e) testing, run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
ng e2e
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
|
60
|
+
|
|
61
|
+
## Additional Resources
|
|
62
|
+
|
|
63
|
+
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { signal, computed, effect } from '@angular/core';
|
|
2
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
3
|
+
|
|
4
|
+
function gqlQuery(query) {
|
|
5
|
+
if (typeof query === 'function') {
|
|
6
|
+
return gqlAsync(query);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
const state = signal({
|
|
10
|
+
loading: true,
|
|
11
|
+
hasError: false,
|
|
12
|
+
}, ...(ngDevMode ? [{ debugName: "state" }] : []));
|
|
13
|
+
query.pipe(takeUntilDestroyed()).subscribe({
|
|
14
|
+
next: (res) => {
|
|
15
|
+
state.set({
|
|
16
|
+
data: res.data,
|
|
17
|
+
hasError: !!res.error,
|
|
18
|
+
error: res.error,
|
|
19
|
+
loading: 'loading' in res ? res.loading : false,
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
error: (error) => {
|
|
23
|
+
state.set({
|
|
24
|
+
loading: false,
|
|
25
|
+
hasError: true,
|
|
26
|
+
error,
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
return state;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function gqlAsync(fn) {
|
|
34
|
+
const state = signal({
|
|
35
|
+
loading: true,
|
|
36
|
+
hasError: false,
|
|
37
|
+
}, ...(ngDevMode ? [{ debugName: "state" }] : []));
|
|
38
|
+
const source$ = computed(fn, ...(ngDevMode ? [{ debugName: "source$" }] : []));
|
|
39
|
+
effect((onCleanup) => {
|
|
40
|
+
const observable = source$();
|
|
41
|
+
let sub;
|
|
42
|
+
if (observable) {
|
|
43
|
+
sub = observable.pipe(takeUntilDestroyed()).subscribe({
|
|
44
|
+
next: (res) => {
|
|
45
|
+
state.set({
|
|
46
|
+
data: res.data,
|
|
47
|
+
loading: 'loading' in res ? res.loading : false,
|
|
48
|
+
hasError: !!res.error,
|
|
49
|
+
error: res.error,
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
error: (error) => {
|
|
53
|
+
state.set({
|
|
54
|
+
loading: false,
|
|
55
|
+
hasError: true,
|
|
56
|
+
error,
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
onCleanup(() => {
|
|
62
|
+
sub?.unsubscribe();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
return state;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
* Public API Surface of apollo-angular-signal
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Generated bundle index. Do not edit.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
export { gqlQuery };
|
|
77
|
+
//# sourceMappingURL=apollo-angular-signal.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apollo-angular-signal.mjs","sources":["../../../projects/apollo-angular-signal/src/lib/apollo-angular-signal.ts","../../../projects/apollo-angular-signal/src/public-api.ts","../../../projects/apollo-angular-signal/src/apollo-angular-signal.ts"],"sourcesContent":["import { computed, effect, signal, type Signal } from '@angular/core';\nimport { ObservableQuery } from '@apollo/client';\nimport type { Apollo } from 'apollo-angular';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport type { Subscription, Observable } from 'rxjs';\n\nexport type GqlQueryResult<T> =\n | Apollo.QueryResult<T>\n | Apollo.SubscribeResult<T>\n | ObservableQuery.Result<T>;\n\nexport type ObservableResult<T> = Observable<GqlQueryResult<T>>;\n\ntype Maybe<T> = T | null | undefined;\n\ninterface LibResult<T> {\n data?: T;\n loading: boolean;\n hasError: boolean;\n error?: unknown;\n}\n\nexport function gqlQuery<T>(\n query: ObservableResult<T> | (() => Maybe<ObservableResult<T>>),\n): Signal<LibResult<T>> {\n if (typeof query === 'function') {\n return gqlAsync(query);\n } else {\n const state = signal<LibResult<T>>({\n loading: true,\n hasError: false,\n });\n\n query.pipe(takeUntilDestroyed()).subscribe({\n next: (res) => {\n state.set({\n data: res.data as T,\n hasError: !!res.error,\n error: res.error,\n loading: 'loading' in res ? res.loading : false,\n });\n },\n error: (error: unknown) => {\n state.set({\n loading: false,\n hasError: true,\n error,\n });\n },\n });\n\n return state;\n }\n}\n\nfunction gqlAsync<T>(\n fn: () => Maybe<ObservableResult<T>>,\n): Signal<LibResult<T>> {\n const state = signal<LibResult<T>>({\n loading: true,\n hasError: false,\n });\n\n const source$ = computed(fn);\n\n effect((onCleanup) => {\n const observable = source$();\n let sub: Maybe<Subscription>;\n if (observable) {\n sub = observable.pipe(takeUntilDestroyed()).subscribe({\n next: (res) => {\n state.set({\n data: res.data as T,\n loading: 'loading' in res ? res.loading : false,\n hasError: !!res.error,\n error: res.error,\n });\n },\n error: (error: unknown) => {\n state.set({\n loading: false,\n hasError: true,\n error,\n });\n },\n });\n }\n\n onCleanup(() => {\n sub?.unsubscribe();\n });\n });\n\n return state;\n}\n","/*\n * Public API Surface of apollo-angular-signal\n */\n\nexport * from './lib/apollo-angular-signal';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAsBM,SAAU,QAAQ,CACtB,KAA+D,EAAA;AAE/D,IAAA,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;AAC/B,QAAA,OAAO,QAAQ,CAAC,KAAK,CAAC;IACxB;SAAO;QACL,MAAM,KAAK,GAAG,MAAM,CAAe;AACjC,YAAA,OAAO,EAAE,IAAI;AACb,YAAA,QAAQ,EAAE,KAAK;AAChB,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I,EAAE,CAAC,GAAG,KAAI;oBACZ,KAAK,CAAC,GAAG,CAAC;wBACR,IAAI,EAAE,GAAG,CAAC,IAAS;AACnB,wBAAA,OAAO,EAAE,SAAS,IAAI,GAAG,GAAG,GAAG,CAAC,OAAO,GAAG,KAAK;AAC/C,wBAAA,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK;wBACrB,KAAK,EAAE,GAAG,CAAC,KAAK;AACjB,qBAAA,CAAC;gBACJ,CAAC;AACD,gBAAA,KAAK,EAAE,CAAC,KAAc,KAAI;oBACxB,KAAK,CAAC,GAAG,CAAC;AACR,wBAAA,OAAO,EAAE,KAAK;AACd,wBAAA,QAAQ,EAAE,IAAI;wBACd,KAAK;AACN,qBAAA,CAAC;gBACJ,CAAC;AACF,aAAA,CAAC;QACJ;QAEA,SAAS,CAAC,MAAK;YACb,GAAG,EAAE,WAAW,EAAE;AACpB,QAAA,CAAC,CAAC;AACJ,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,KAAK;AACd;;AC9FA;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "apollo-angular-signal",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/common": "^20 || ^21",
|
|
6
|
+
"@angular/core": "^20 || ^21",
|
|
7
|
+
"apollo-angular": "^13",
|
|
8
|
+
"rxjs": "^7"
|
|
9
|
+
},
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"module": "fesm2022/apollo-angular-signal.mjs",
|
|
12
|
+
"typings": "types/apollo-angular-signal.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
"./package.json": {
|
|
15
|
+
"default": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./types/apollo-angular-signal.d.ts",
|
|
19
|
+
"default": "./fesm2022/apollo-angular-signal.mjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"tslib": "^2.3.0"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Signal } from '@angular/core';
|
|
2
|
+
import { ObservableQuery } from '@apollo/client';
|
|
3
|
+
import { Apollo } from 'apollo-angular';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
|
|
6
|
+
type GqlQueryResult<T> = Apollo.QueryResult<T> | Apollo.SubscribeResult<T> | ObservableQuery.Result<T>;
|
|
7
|
+
type ObservableResult<T> = Observable<GqlQueryResult<T>>;
|
|
8
|
+
type Maybe<T> = T | null | undefined;
|
|
9
|
+
interface LibResult<T> {
|
|
10
|
+
data?: T;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
hasError: boolean;
|
|
13
|
+
error?: unknown;
|
|
14
|
+
}
|
|
15
|
+
declare function gqlQuery<T>(query: ObservableResult<T> | (() => Maybe<ObservableResult<T>>)): Signal<LibResult<T>>;
|
|
16
|
+
|
|
17
|
+
export { gqlQuery };
|
|
18
|
+
export type { GqlQueryResult, ObservableResult };
|