graphql-persisted 0.0.5 → 0.0.7
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/cjs/GraphQLQueryCache.d.ts +46 -2
- package/cjs/GraphQLQueryCache.js +204 -221
- package/cjs/fragmentData.d.ts +19 -1
- package/cjs/fragmentData.js +5 -1
- package/cjs/graphqlHooks.js +10 -2
- package/cjs/index.d.ts +2 -2
- package/cjs/index.js +2 -1
- package/cjs/types.d.ts +1 -1
- package/mjs/GraphQLQueryCache.d.ts +46 -2
- package/mjs/GraphQLQueryCache.js +203 -221
- package/mjs/fragmentData.d.ts +19 -1
- package/mjs/fragmentData.js +3 -0
- package/mjs/graphqlHooks.js +10 -2
- package/mjs/index.d.ts +2 -2
- package/mjs/index.js +1 -1
- package/mjs/types.d.ts +1 -1
- package/package.json +4 -3
package/cjs/fragmentData.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import './types';
|
|
2
|
+
type Pretty<O> = {
|
|
3
|
+
[K in keyof O]: O[K];
|
|
4
|
+
} & {};
|
|
5
|
+
type UnwrapFragment<T> = T extends Array<infer U> ? Array<UnwrapFragment<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<ReadonlyArray<U>> : T extends object ? T extends {
|
|
6
|
+
' $fragmentRefs'?: infer Refs;
|
|
7
|
+
} ? Pretty<{
|
|
8
|
+
[K in keyof T as K extends ' $fragmentName' | ' $fragmentRefs' ? never : K]: UnwrapFragment<T[K]>;
|
|
9
|
+
} & {
|
|
10
|
+
[K in keyof Refs]: UnwrapFragment<Refs[K]>;
|
|
11
|
+
}[keyof Refs]> : {
|
|
12
|
+
[K in keyof T as K extends ' $fragmentName' ? never : K]: UnwrapFragment<T[K]>;
|
|
13
|
+
} : T;
|
|
2
14
|
export type FragmentType<Frag extends keyof GraphQLQuery.FragmentRegistry> = GraphQLQuery.FragmentRegistry[Frag] extends infer FragType ? FragType extends {
|
|
3
15
|
' $fragmentName'?: infer TKey;
|
|
4
16
|
} ? TKey extends string ? {
|
|
@@ -6,8 +18,14 @@ export type FragmentType<Frag extends keyof GraphQLQuery.FragmentRegistry> = Gra
|
|
|
6
18
|
[key in TKey]: FragType;
|
|
7
19
|
};
|
|
8
20
|
} : never : never : never;
|
|
21
|
+
export type FragmentTypeUnwrapped<Frag extends keyof GraphQLQuery.FragmentRegistry> = GraphQLQuery.FragmentRegistry[Frag] extends infer FragType ? FragType extends object ? UnwrapFragment<FragType> : never : never;
|
|
9
22
|
export declare function unwrapFragment<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: FragmentType<Frag>): GraphQLQuery.FragmentRegistry[Frag];
|
|
10
23
|
export declare function unwrapFragment<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: FragmentType<Frag> | null | undefined): GraphQLQuery.FragmentRegistry[Frag] | null | undefined;
|
|
11
24
|
export declare function unwrapFragment<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: ReadonlyArray<FragmentType<Frag>>): ReadonlyArray<GraphQLQuery.FragmentRegistry[Frag]>;
|
|
12
25
|
export declare function unwrapFragment<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: ReadonlyArray<FragmentType<Frag>> | null | undefined): ReadonlyArray<GraphQLQuery.FragmentRegistry[Frag]> | null | undefined;
|
|
13
|
-
export declare function
|
|
26
|
+
export declare function unwrapFragmentDeep<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: FragmentType<Frag>): FragmentTypeUnwrapped<Frag>;
|
|
27
|
+
export declare function unwrapFragmentDeep<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: FragmentType<Frag> | null | undefined): FragmentTypeUnwrapped<Frag> | null | undefined;
|
|
28
|
+
export declare function unwrapFragmentDeep<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: ReadonlyArray<FragmentType<Frag>>): ReadonlyArray<FragmentTypeUnwrapped<Frag>>;
|
|
29
|
+
export declare function unwrapFragmentDeep<Frag extends keyof GraphQLQuery.FragmentRegistry>(_fragmentName: Frag, fragmentType: ReadonlyArray<FragmentType<Frag>> | null | undefined): ReadonlyArray<FragmentTypeUnwrapped<Frag>> | null | undefined;
|
|
30
|
+
export declare function castFragmentData<F extends keyof GraphQLQuery.FragmentRegistry, FT extends FragmentTypeUnwrapped<F>>(_fragmentName: F, data: FT): FragmentType<F>;
|
|
31
|
+
export {};
|
package/cjs/fragmentData.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.castFragmentData = exports.unwrapFragment = void 0;
|
|
3
|
+
exports.castFragmentData = exports.unwrapFragmentDeep = exports.unwrapFragment = void 0;
|
|
4
4
|
require("./types");
|
|
5
5
|
function unwrapFragment(_fragmentName, fragmentType) {
|
|
6
6
|
return fragmentType;
|
|
7
7
|
}
|
|
8
8
|
exports.unwrapFragment = unwrapFragment;
|
|
9
|
+
function unwrapFragmentDeep(_fragmentName, fragmentType) {
|
|
10
|
+
return fragmentType;
|
|
11
|
+
}
|
|
12
|
+
exports.unwrapFragmentDeep = unwrapFragmentDeep;
|
|
9
13
|
function castFragmentData(_fragmentName, data) {
|
|
10
14
|
return data;
|
|
11
15
|
}
|
package/cjs/graphqlHooks.js
CHANGED
|
@@ -66,6 +66,7 @@ function usePersistedQuery(queryName, options) {
|
|
|
66
66
|
// or it is refetched
|
|
67
67
|
(0, react_1.useEffect)(() => {
|
|
68
68
|
return cache.subscribeToQuery({
|
|
69
|
+
queryResult,
|
|
69
70
|
queryName,
|
|
70
71
|
variables: variableString,
|
|
71
72
|
onUpdate: setQueryResult,
|
|
@@ -91,8 +92,15 @@ function useLazyPersistedQuery(query) {
|
|
|
91
92
|
const [fetched, setIsFetched] = (0, react_1.useState)(false);
|
|
92
93
|
const [loading, setIsLoading] = (0, react_1.useState)(false);
|
|
93
94
|
const loadQuery = (0, react_1.useCallback)((variables) => {
|
|
94
|
-
return new Promise((resolve) => {
|
|
95
|
-
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
const result = cache.readOrFetchQuery({
|
|
97
|
+
queryName: query,
|
|
98
|
+
variables: (0, helpers_1.serializeVariables)(variables),
|
|
99
|
+
options: {},
|
|
100
|
+
});
|
|
101
|
+
// if ('then' in result && typeof result.then === 'function') {
|
|
102
|
+
// Promise.resolve(result).then(resolve, reject)
|
|
103
|
+
// }
|
|
96
104
|
});
|
|
97
105
|
}, [cache, query]);
|
|
98
106
|
const errors = undefined;
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { usePersistedQuery, usePersistedMutation, usePreloadedPersistedQuery, useOnMutation, usePersistedSubscription, } from './graphqlHooks.js';
|
|
2
|
-
export { unwrapFragment, castFragmentData } from './fragmentData.js';
|
|
3
|
-
export type { FragmentType } from './fragmentData.js';
|
|
2
|
+
export { unwrapFragment, castFragmentData, unwrapFragmentDeep } from './fragmentData.js';
|
|
3
|
+
export type { FragmentType, FragmentTypeUnwrapped } from './fragmentData.js';
|
|
4
4
|
export { GraphQLQueryCache } from './GraphQLQueryCache.js';
|
|
5
5
|
export { useGraphQLQueryCache, GraphQLQueryProvider } from './context.js';
|
|
6
6
|
export type { GraphQLPreloadedQueryResult, GraphQLQueryResult, GraphQLQueryCacheConfig } from './types.js';
|
package/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GraphQLQueryProvider = exports.useGraphQLQueryCache = exports.GraphQLQueryCache = exports.castFragmentData = exports.unwrapFragment = exports.usePersistedSubscription = exports.useOnMutation = exports.usePreloadedPersistedQuery = exports.usePersistedMutation = exports.usePersistedQuery = void 0;
|
|
3
|
+
exports.GraphQLQueryProvider = exports.useGraphQLQueryCache = exports.GraphQLQueryCache = exports.unwrapFragmentDeep = exports.castFragmentData = exports.unwrapFragment = exports.usePersistedSubscription = exports.useOnMutation = exports.usePreloadedPersistedQuery = exports.usePersistedMutation = exports.usePersistedQuery = void 0;
|
|
4
4
|
var graphqlHooks_js_1 = require("./graphqlHooks.js");
|
|
5
5
|
Object.defineProperty(exports, "usePersistedQuery", { enumerable: true, get: function () { return graphqlHooks_js_1.usePersistedQuery; } });
|
|
6
6
|
Object.defineProperty(exports, "usePersistedMutation", { enumerable: true, get: function () { return graphqlHooks_js_1.usePersistedMutation; } });
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "usePersistedSubscription", { enumerable: true, g
|
|
|
10
10
|
var fragmentData_js_1 = require("./fragmentData.js");
|
|
11
11
|
Object.defineProperty(exports, "unwrapFragment", { enumerable: true, get: function () { return fragmentData_js_1.unwrapFragment; } });
|
|
12
12
|
Object.defineProperty(exports, "castFragmentData", { enumerable: true, get: function () { return fragmentData_js_1.castFragmentData; } });
|
|
13
|
+
Object.defineProperty(exports, "unwrapFragmentDeep", { enumerable: true, get: function () { return fragmentData_js_1.unwrapFragmentDeep; } });
|
|
13
14
|
var GraphQLQueryCache_js_1 = require("./GraphQLQueryCache.js");
|
|
14
15
|
Object.defineProperty(exports, "GraphQLQueryCache", { enumerable: true, get: function () { return GraphQLQueryCache_js_1.GraphQLQueryCache; } });
|
|
15
16
|
var context_js_1 = require("./context.js");
|
package/cjs/types.d.ts
CHANGED
|
@@ -167,7 +167,7 @@ export interface SubscribeToQueryArgs<Q extends keyof GraphQLQuery.QueryRegistry
|
|
|
167
167
|
/**
|
|
168
168
|
* The result of readQuery, used to check whether the query is stale
|
|
169
169
|
*/
|
|
170
|
-
queryResult?:
|
|
170
|
+
queryResult?: GraphQLOperationResult<Q>;
|
|
171
171
|
/**
|
|
172
172
|
* Invoked when the values for this query are updated
|
|
173
173
|
*/
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NormalizeMetaShape } from 'graphql-normalize';
|
|
2
|
+
import type { GraphQLCacheShape, GraphQLMutationResult, GraphQLOperationResult, GraphQLQueryCacheConfig, GraphQLQueryResult, GraphQLRequestBody, InvalidateQueryArgs, MaybePromise, ExecutionOptions, PersistedQueryOptions, ReadQueryArgs, SerializedVariables, SubscribeToQueryArgs, PreloadQueryOptions } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Manages the cached normalized state, and the execution of
|
|
4
5
|
* data accessed by different components
|
|
5
6
|
*/
|
|
6
7
|
export declare class GraphQLQueryCache {
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* If an alterative fetch is provided, we will use that for operations
|
|
10
|
+
* Otherwise we'll use the native 'fetch'
|
|
11
|
+
*/
|
|
12
|
+
private _fetcher?;
|
|
13
|
+
/**
|
|
14
|
+
* GraphQL API endpoint
|
|
15
|
+
* @default /graphql
|
|
16
|
+
*/
|
|
17
|
+
private _endpoint;
|
|
18
|
+
private _persistedOperations;
|
|
19
|
+
private _persistedDocuments?;
|
|
20
|
+
private _configMeta?;
|
|
21
|
+
private _subscribedQueries;
|
|
22
|
+
private _inFlight;
|
|
23
|
+
private _cacheStore;
|
|
24
|
+
private _runtimeCache;
|
|
25
|
+
private _queryInvalidation;
|
|
26
|
+
private _mutationInvalidation;
|
|
27
|
+
/**
|
|
28
|
+
* A list of all "effects" that have run, used to keep track of
|
|
29
|
+
*/
|
|
30
|
+
private _effectsIssued;
|
|
8
31
|
constructor(config: GraphQLQueryCacheConfig);
|
|
9
32
|
/**
|
|
10
33
|
* Invalidates a query by name or predicate fn
|
|
@@ -53,10 +76,31 @@ export declare class GraphQLQueryCache {
|
|
|
53
76
|
*/
|
|
54
77
|
executeQuery<Q extends keyof GraphQLQuery.QueryRegistry>(queryName: Q, variables: SerializedVariables | GraphQLQuery.OperationVariables[Q]): Promise<GraphQLQueryResult<Q>>;
|
|
55
78
|
executeSubscription(): Promise<void>;
|
|
79
|
+
_getKey(operationName: string, variables: SerializedVariables | object): string;
|
|
56
80
|
/**
|
|
57
81
|
* "Subscribes" to a query, meaning that when there are updates to fields in the
|
|
58
82
|
* field cache, we'll re-materialize the known value of the query. We'll also
|
|
59
83
|
* process based on configuration options, such as TTL, invalidateOnMutation
|
|
60
84
|
*/
|
|
61
85
|
subscribeToQuery<Q extends keyof GraphQLQuery.QueryRegistry>(args: SubscribeToQueryArgs<Q>): () => void;
|
|
86
|
+
_executeOperation<QueryName extends keyof GraphQLQuery.QueryRegistry>(operationType: 'query', operationName: QueryName, variables: SerializedVariables | GraphQLQuery.OperationVariables[QueryName], options?: PersistedQueryOptions): Promise<GraphQLQueryResult<QueryName>>;
|
|
87
|
+
_executeOperation<MutationName extends keyof GraphQLQuery.MutationRegistry>(operationType: 'mutation', operationName: MutationName, variables: SerializedVariables | object, options?: ExecutionOptions): Promise<GraphQLMutationResult<MutationName>>;
|
|
88
|
+
_getMeta(opName: string): NormalizeMetaShape;
|
|
89
|
+
/**
|
|
90
|
+
* Handles "fetch", ensuring we catch network errors and handle non-200
|
|
91
|
+
* responses properly so we're able to forward these on in a normalized fashion
|
|
92
|
+
*/
|
|
93
|
+
_fetch(body: GraphQLRequestBody): Promise<GraphQLOperationResult<any>>;
|
|
94
|
+
_makeFetch(body: GraphQLRequestBody): Promise<Response>;
|
|
95
|
+
/**
|
|
96
|
+
* Determine whether we should refetch the query based on the
|
|
97
|
+
* current value of the query, and the options passed to the query
|
|
98
|
+
*/
|
|
99
|
+
_shouldRefetchQuery(): void;
|
|
100
|
+
/**
|
|
101
|
+
* "Garbage collection" for existing operations. If they have
|
|
102
|
+
* a TTL or are invalidated by other operations, and aren't mounted,
|
|
103
|
+
* then we can go ahead and sweep out any data we might have for them
|
|
104
|
+
*/
|
|
105
|
+
_gcOperations(): void;
|
|
62
106
|
}
|