houdini 1.2.0-react.1 → 1.2.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/README.md +1 -1
- package/build/cmd-cjs/index.js +2213 -1533
- package/build/cmd-esm/index.js +2213 -1533
- package/build/codegen/generators/artifacts/selection.d.ts +2 -1
- package/build/codegen/generators/typescript/inlineType.d.ts +5 -2
- package/build/codegen/generators/typescript/loadingState.d.ts +8 -0
- package/build/codegen/transforms/fragmentVariables.d.ts +0 -11
- package/build/codegen-cjs/index.js +2143 -1487
- package/build/codegen-esm/index.js +2143 -1487
- package/build/lib/config.d.ts +5 -0
- package/build/lib/graphql.d.ts +5 -1
- package/build/lib/parse.d.ts +10 -1
- package/build/lib-cjs/index.js +702 -578
- package/build/lib-esm/index.js +699 -578
- package/build/runtime/cache/cache.d.ts +9 -8
- package/build/runtime/cache/stuff.d.ts +1 -4
- package/build/runtime/client/documentStore.d.ts +3 -3
- package/build/runtime/client/index.d.ts +8 -7
- package/build/runtime/client/plugins/cache.d.ts +1 -1
- package/build/runtime/client/plugins/fetch.d.ts +1 -0
- package/build/runtime/client/plugins/subscription.d.ts +1 -0
- package/build/runtime/client/plugins/throwOnError.d.ts +2 -1
- package/build/runtime/lib/pagination.d.ts +4 -6
- package/build/runtime/lib/selection.d.ts +1 -1
- package/build/runtime/lib/types.d.ts +37 -4
- package/build/runtime-cjs/cache/cache.d.ts +9 -8
- package/build/runtime-cjs/cache/cache.js +108 -43
- package/build/runtime-cjs/cache/stuff.d.ts +1 -4
- package/build/runtime-cjs/cache/stuff.js +2 -2
- package/build/runtime-cjs/cache/subscription.js +5 -5
- package/build/runtime-cjs/client/documentStore.d.ts +3 -3
- package/build/runtime-cjs/client/documentStore.js +10 -2
- package/build/runtime-cjs/client/index.d.ts +8 -7
- package/build/runtime-cjs/client/index.js +12 -4
- package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/cache.js +10 -2
- package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -0
- package/build/runtime-cjs/client/plugins/fetch.js +3 -2
- package/build/runtime-cjs/client/plugins/subscription.d.ts +1 -0
- package/build/runtime-cjs/client/plugins/subscription.js +1 -0
- package/build/runtime-cjs/client/plugins/throwOnError.d.ts +2 -1
- package/build/runtime-cjs/lib/config.js +2 -1
- package/build/runtime-cjs/lib/pagination.d.ts +4 -6
- package/build/runtime-cjs/lib/pagination.js +0 -12
- package/build/runtime-cjs/lib/scalars.js +1 -1
- package/build/runtime-cjs/lib/selection.d.ts +1 -1
- package/build/runtime-cjs/lib/selection.js +28 -1
- package/build/runtime-cjs/lib/types.d.ts +37 -4
- package/build/runtime-cjs/lib/types.js +3 -0
- package/build/runtime-esm/cache/cache.d.ts +9 -8
- package/build/runtime-esm/cache/cache.js +109 -44
- package/build/runtime-esm/cache/stuff.d.ts +1 -4
- package/build/runtime-esm/cache/stuff.js +2 -2
- package/build/runtime-esm/cache/subscription.js +5 -5
- package/build/runtime-esm/client/documentStore.d.ts +3 -3
- package/build/runtime-esm/client/documentStore.js +10 -2
- package/build/runtime-esm/client/index.d.ts +8 -7
- package/build/runtime-esm/client/index.js +15 -7
- package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
- package/build/runtime-esm/client/plugins/cache.js +10 -2
- package/build/runtime-esm/client/plugins/fetch.d.ts +1 -0
- package/build/runtime-esm/client/plugins/fetch.js +3 -2
- package/build/runtime-esm/client/plugins/subscription.d.ts +1 -0
- package/build/runtime-esm/client/plugins/subscription.js +1 -0
- package/build/runtime-esm/client/plugins/throwOnError.d.ts +2 -1
- package/build/runtime-esm/lib/config.js +2 -1
- package/build/runtime-esm/lib/pagination.d.ts +4 -6
- package/build/runtime-esm/lib/pagination.js +0 -12
- package/build/runtime-esm/lib/scalars.js +1 -1
- package/build/runtime-esm/lib/selection.d.ts +1 -1
- package/build/runtime-esm/lib/selection.js +28 -1
- package/build/runtime-esm/lib/types.d.ts +37 -4
- package/build/runtime-esm/lib/types.js +2 -0
- package/build/test/index.d.ts +15 -0
- package/build/test-cjs/index.js +2174 -1490
- package/build/test-esm/index.js +2174 -1490
- package/build/vite-cjs/index.js +2243 -1561
- package/build/vite-esm/index.js +2243 -1561
- package/package.json +7 -1
|
@@ -3,7 +3,6 @@ import type { GraphQLObject, GraphQLValue, NestedList, SubscriptionSelection, Su
|
|
|
3
3
|
import { GarbageCollector } from './gc';
|
|
4
4
|
import type { ListCollection } from './lists';
|
|
5
5
|
import { ListManager } from './lists';
|
|
6
|
-
import { SchemaManager } from './schema';
|
|
7
6
|
import { StaleManager } from './staleManager';
|
|
8
7
|
import type { Layer, LayerID } from './storage';
|
|
9
8
|
import { InMemoryStorage } from './storage';
|
|
@@ -57,15 +56,13 @@ declare class CacheInternal {
|
|
|
57
56
|
cache: Cache;
|
|
58
57
|
lifetimes: GarbageCollector;
|
|
59
58
|
staleManager: StaleManager;
|
|
60
|
-
|
|
61
|
-
constructor({ storage, subscriptions, lists, cache, lifetimes, staleManager, schema, disabled, config, }: {
|
|
59
|
+
constructor({ storage, subscriptions, lists, cache, lifetimes, staleManager, disabled, config, }: {
|
|
62
60
|
storage: InMemoryStorage;
|
|
63
61
|
subscriptions: InMemorySubscriptions;
|
|
64
62
|
lists: ListManager;
|
|
65
63
|
cache: Cache;
|
|
66
64
|
lifetimes: GarbageCollector;
|
|
67
65
|
staleManager: StaleManager;
|
|
68
|
-
schema: SchemaManager;
|
|
69
66
|
disabled: boolean;
|
|
70
67
|
config?: ConfigFile;
|
|
71
68
|
});
|
|
@@ -87,12 +84,14 @@ declare class CacheInternal {
|
|
|
87
84
|
forceNotify?: boolean;
|
|
88
85
|
forceStale?: boolean;
|
|
89
86
|
}): FieldSelection[];
|
|
90
|
-
getSelection({ selection, parent, variables, stepsFromConnection, ignoreMasking, }: {
|
|
87
|
+
getSelection({ selection, parent, variables, stepsFromConnection, ignoreMasking, fullCheck, loading: generateLoading, }: {
|
|
91
88
|
selection: SubscriptionSelection;
|
|
92
89
|
parent?: string;
|
|
93
|
-
variables?: {};
|
|
90
|
+
variables?: {} | null;
|
|
94
91
|
stepsFromConnection?: number | null;
|
|
95
92
|
ignoreMasking?: boolean;
|
|
93
|
+
loading?: boolean;
|
|
94
|
+
fullCheck?: boolean;
|
|
96
95
|
}): {
|
|
97
96
|
data: GraphQLObject | null;
|
|
98
97
|
partial: boolean;
|
|
@@ -103,12 +102,14 @@ declare class CacheInternal {
|
|
|
103
102
|
id(type: string, id: string): string | null;
|
|
104
103
|
idFields(type: string): string[];
|
|
105
104
|
computeID(type: string, data: any): string;
|
|
106
|
-
hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, ignoreMasking, }: {
|
|
105
|
+
hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, ignoreMasking, fullCheck, loading, }: {
|
|
107
106
|
fields: SubscriptionSelection;
|
|
108
|
-
variables?: {};
|
|
107
|
+
variables?: {} | null;
|
|
109
108
|
linkedList: NestedList;
|
|
110
109
|
stepsFromConnection: number | null;
|
|
111
110
|
ignoreMasking: boolean;
|
|
111
|
+
fullCheck?: boolean;
|
|
112
|
+
loading?: boolean;
|
|
112
113
|
}): {
|
|
113
114
|
data: NestedList<GraphQLValue>;
|
|
114
115
|
partial: boolean;
|
|
@@ -2,8 +2,8 @@ import type { HoudiniClient } from '.';
|
|
|
2
2
|
import type { Layer } from '../cache/storage';
|
|
3
3
|
import type { ConfigFile } from '../lib/config';
|
|
4
4
|
import { Writable } from '../lib/store';
|
|
5
|
-
import type { DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec, CachePolicies } from '../lib/types';
|
|
6
|
-
export declare class DocumentStore<_Data extends GraphQLObject, _Input extends
|
|
5
|
+
import type { DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec, CachePolicies, GraphQLVariables } from '../lib/types';
|
|
6
|
+
export declare class DocumentStore<_Data extends GraphQLObject, _Input extends GraphQLVariables> extends Writable<QueryResult<_Data, _Input>> {
|
|
7
7
|
#private;
|
|
8
8
|
pendingPromise: {
|
|
9
9
|
then: (val: any) => void;
|
|
@@ -20,7 +20,7 @@ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends R
|
|
|
20
20
|
send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, silenceEcho, }?: SendParams): Promise<QueryResult<_Data, _Input>>;
|
|
21
21
|
cleanup(): Promise<void>;
|
|
22
22
|
}
|
|
23
|
-
declare function marshalVariables<_Data extends GraphQLObject, _Input extends
|
|
23
|
+
declare function marshalVariables<_Data extends GraphQLObject, _Input extends GraphQLVariables>(ctx: ClientPluginContext): Record<string, any>;
|
|
24
24
|
export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
|
|
25
25
|
export type ClientHooks = {
|
|
26
26
|
start?: ClientPluginEnterPhase;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference path="../../../../../houdini.d.ts" />
|
|
2
|
-
import type { DocumentArtifact, GraphQLObject, NestedList } from '../lib/types';
|
|
3
|
-
import type {
|
|
2
|
+
import type { DocumentArtifact, GraphQLVariables, GraphQLObject, NestedList } from '../lib/types';
|
|
3
|
+
import type { ClientHooks, ClientPlugin } from './documentStore';
|
|
4
4
|
import { DocumentStore } from './documentStore';
|
|
5
|
-
import {
|
|
5
|
+
import type { FetchParamFn, ThrowOnErrorOperations, ThrowOnErrorParams } from './plugins';
|
|
6
6
|
export { DocumentStore, type ClientPlugin, type SendParams } from './documentStore';
|
|
7
7
|
export { fetch, mutation, query, subscription } from './plugins';
|
|
8
|
-
type
|
|
8
|
+
export type HoudiniClientConstructorArgs = {
|
|
9
9
|
url: string;
|
|
10
10
|
fetchParams?: FetchParamFn;
|
|
11
11
|
plugins?: NestedList<ClientPlugin>;
|
|
@@ -19,9 +19,10 @@ export type ObserveParams<_Data extends GraphQLObject, _Artifact extends Documen
|
|
|
19
19
|
fetching?: boolean;
|
|
20
20
|
};
|
|
21
21
|
export declare class HoudiniClient {
|
|
22
|
-
#private;
|
|
23
22
|
url: string;
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
readonly plugins: ClientPlugin[];
|
|
24
|
+
readonly throwOnError_operations: ThrowOnErrorOperations[];
|
|
25
|
+
constructor({ url, fetchParams, plugins, pipeline, throwOnError, }: HoudiniClientConstructorArgs);
|
|
26
|
+
observe<_Data extends GraphQLObject, _Input extends GraphQLVariables>({ artifact, cache, initialValue, fetching, }: ObserveParams<_Data>): DocumentStore<_Data, _Input>;
|
|
26
27
|
}
|
|
27
28
|
export declare function createPluginHooks(plugins: ClientPlugin[]): ClientHooks[];
|
|
@@ -3,7 +3,7 @@ import { Cache } from '../../cache/cache';
|
|
|
3
3
|
import type { ClientPlugin } from '../documentStore';
|
|
4
4
|
export declare const cachePolicy: ({ enabled, setFetching, cache: localCache, serverSideFallback, }: {
|
|
5
5
|
enabled: boolean;
|
|
6
|
-
setFetching: (val: boolean) => void;
|
|
6
|
+
setFetching: (val: boolean, data?: any) => void;
|
|
7
7
|
cache?: Cache | undefined;
|
|
8
8
|
serverSideFallback?: boolean | undefined;
|
|
9
9
|
}) => ClientPlugin;
|
|
@@ -21,6 +21,7 @@ export type FetchContext = {
|
|
|
21
21
|
export type RequestHandlerArgs = FetchContext & FetchParams;
|
|
22
22
|
export type RequestHandler<_Data = any> = (args: RequestHandlerArgs) => Promise<RequestPayload<_Data>>;
|
|
23
23
|
export type FetchParams = {
|
|
24
|
+
name: string;
|
|
24
25
|
text: string;
|
|
25
26
|
hash: string;
|
|
26
27
|
variables: {
|
|
@@ -3,6 +3,7 @@ export declare function subscription(factory: SubscriptionHandler): import("../d
|
|
|
3
3
|
export type SubscriptionHandler = (ctx: ClientPluginContext) => SubscriptionClient;
|
|
4
4
|
export type SubscriptionClient = {
|
|
5
5
|
subscribe: (payload: {
|
|
6
|
+
operationName: string;
|
|
6
7
|
query: string;
|
|
7
8
|
variables?: {};
|
|
8
9
|
}, handlers: {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { QueryResult } from '../../lib';
|
|
2
2
|
import type { ClientPlugin, ClientPluginContext } from '../documentStore';
|
|
3
|
+
export type ThrowOnErrorOperations = 'all' | 'query' | 'mutation' | 'subscription';
|
|
3
4
|
export type ThrowOnErrorParams = {
|
|
4
|
-
operations:
|
|
5
|
+
operations: ThrowOnErrorOperations[];
|
|
5
6
|
error?: (errors: NonNullable<QueryResult<any, any>['errors']>, ctx: ClientPluginContext) => unknown;
|
|
6
7
|
};
|
|
7
8
|
export declare const throwOnError: ({ operations, error }: ThrowOnErrorParams) => ClientPlugin;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import type { SendParams } from '../client/documentStore';
|
|
2
|
-
import { FetchParams } from './types';
|
|
3
|
-
|
|
4
|
-
export declare function cursorHandlers<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, storeName, fetchUpdate: parentFetchUpdate, fetch: parentFetch, getState, getVariables, getSession, }: {
|
|
2
|
+
import type { CursorHandlers, FetchFn, GraphQLObject, GraphQLVariables, QueryArtifact, QueryResult, FetchParams } from './types';
|
|
3
|
+
export declare function cursorHandlers<_Data extends GraphQLObject, _Input extends GraphQLVariables>({ artifact, fetchUpdate: parentFetchUpdate, fetch: parentFetch, getState, getVariables, getSession, }: {
|
|
5
4
|
artifact: QueryArtifact;
|
|
6
|
-
storeName: string;
|
|
7
5
|
getState: () => _Data | null;
|
|
8
|
-
getVariables: () => _Input
|
|
6
|
+
getVariables: () => NonNullable<_Input>;
|
|
9
7
|
getSession: () => Promise<App.Session>;
|
|
10
8
|
fetch: FetchFn<_Data, _Input>;
|
|
11
9
|
fetchUpdate: (arg: SendParams, updates: string[]) => ReturnType<FetchFn<_Data, _Input>>;
|
|
12
10
|
}): CursorHandlers<_Data, _Input>;
|
|
13
|
-
export declare function offsetHandlers<_Data extends GraphQLObject, _Input extends
|
|
11
|
+
export declare function offsetHandlers<_Data extends GraphQLObject, _Input extends GraphQLVariables>({ artifact, storeName, getState, getVariables, fetch: parentFetch, fetchUpdate: parentFetchUpdate, getSession, }: {
|
|
14
12
|
artifact: QueryArtifact;
|
|
15
13
|
fetch: FetchFn<_Data, _Input>;
|
|
16
14
|
fetchUpdate: (arg: SendParams) => ReturnType<FetchFn<_Data, _Input>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { SubscriptionSelection } from './types';
|
|
2
|
-
export declare function getFieldsForType(selection: SubscriptionSelection, __typename: string | undefined | null): Required<SubscriptionSelection>['fields'];
|
|
2
|
+
export declare function getFieldsForType(selection: SubscriptionSelection, __typename: string | undefined | null, loading: boolean): Required<SubscriptionSelection>['fields'];
|
|
@@ -53,9 +53,12 @@ export type CompiledDocumentKind = ArtifactKinds;
|
|
|
53
53
|
export type QueryArtifact = BaseCompiledDocument<'HoudiniQuery'> & {
|
|
54
54
|
policy?: CachePolicies;
|
|
55
55
|
partial?: boolean;
|
|
56
|
+
enableLoadingState?: 'global' | 'local';
|
|
56
57
|
};
|
|
57
58
|
export type MutationArtifact = BaseCompiledDocument<'HoudiniMutation'>;
|
|
58
|
-
export type FragmentArtifact = BaseCompiledDocument<'HoudiniFragment'
|
|
59
|
+
export type FragmentArtifact = BaseCompiledDocument<'HoudiniFragment'> & {
|
|
60
|
+
enableLoadingState?: 'global' | 'local';
|
|
61
|
+
};
|
|
59
62
|
export type SubscriptionArtifact = BaseCompiledDocument<'HoudiniSubscription'>;
|
|
60
63
|
export declare const RefetchUpdateMode: {
|
|
61
64
|
readonly append: "append";
|
|
@@ -129,12 +132,34 @@ export type GraphQLObject = {
|
|
|
129
132
|
[key: string]: GraphQLValue;
|
|
130
133
|
};
|
|
131
134
|
export type GraphQLValue = number | string | boolean | null | GraphQLObject | GraphQLValue[] | undefined;
|
|
135
|
+
export type GraphQLVariables = {
|
|
136
|
+
[key: string]: any;
|
|
137
|
+
} | null;
|
|
138
|
+
export type LoadingSpec = {
|
|
139
|
+
kind: 'continue';
|
|
140
|
+
list?: {
|
|
141
|
+
depth: number;
|
|
142
|
+
count: number;
|
|
143
|
+
};
|
|
144
|
+
} | {
|
|
145
|
+
kind: 'value';
|
|
146
|
+
value?: any;
|
|
147
|
+
list?: {
|
|
148
|
+
depth: number;
|
|
149
|
+
count: number;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
132
152
|
export type SubscriptionSelection = {
|
|
133
|
-
|
|
153
|
+
loadingTypes?: string[];
|
|
154
|
+
fragments?: Record<string, {
|
|
155
|
+
arguments: ValueMap;
|
|
156
|
+
loading?: boolean;
|
|
157
|
+
}>;
|
|
134
158
|
fields?: {
|
|
135
159
|
[fieldName: string]: {
|
|
136
160
|
type: string;
|
|
137
161
|
nullable?: boolean;
|
|
162
|
+
required?: boolean;
|
|
138
163
|
keyRaw: string;
|
|
139
164
|
operations?: MutationOperation[];
|
|
140
165
|
list?: {
|
|
@@ -142,6 +167,11 @@ export type SubscriptionSelection = {
|
|
|
142
167
|
connection: boolean;
|
|
143
168
|
type: string;
|
|
144
169
|
};
|
|
170
|
+
loading?: LoadingSpec;
|
|
171
|
+
directives?: {
|
|
172
|
+
name: string;
|
|
173
|
+
arguments: ValueMap;
|
|
174
|
+
}[];
|
|
145
175
|
updates?: string[];
|
|
146
176
|
visible?: boolean;
|
|
147
177
|
filters?: Record<string, {
|
|
@@ -150,6 +180,7 @@ export type SubscriptionSelection = {
|
|
|
150
180
|
}>;
|
|
151
181
|
selection?: SubscriptionSelection;
|
|
152
182
|
abstract?: boolean;
|
|
183
|
+
abstractHasRequired?: boolean;
|
|
153
184
|
};
|
|
154
185
|
};
|
|
155
186
|
abstractFields?: {
|
|
@@ -172,7 +203,7 @@ export type FetchQueryResult<_Data> = {
|
|
|
172
203
|
result: RequestPayload<_Data | null>;
|
|
173
204
|
source: DataSources | null;
|
|
174
205
|
};
|
|
175
|
-
export type QueryResult<_Data = GraphQLObject, _Input =
|
|
206
|
+
export type QueryResult<_Data = GraphQLObject, _Input = GraphQLVariables> = {
|
|
176
207
|
data: _Data | null;
|
|
177
208
|
errors: {
|
|
178
209
|
message: string;
|
|
@@ -191,7 +222,7 @@ export type RequestPayload<GraphQLObject = any> = {
|
|
|
191
222
|
};
|
|
192
223
|
export type NestedList<_Result = string> = (_Result | null | NestedList<_Result>)[];
|
|
193
224
|
export type ValueOf<Parent> = Parent[keyof Parent];
|
|
194
|
-
export declare const fragmentKey
|
|
225
|
+
export declare const fragmentKey: " $fragments";
|
|
195
226
|
export type ValueNode = VariableNode | IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | ListValueNode | ObjectValueNode;
|
|
196
227
|
export type ValueMap = Record<string, ValueNode>;
|
|
197
228
|
export type FetchParams<_Input> = {
|
|
@@ -283,4 +314,6 @@ interface VariableNode {
|
|
|
283
314
|
readonly kind: 'Variable';
|
|
284
315
|
readonly name: NameNode;
|
|
285
316
|
}
|
|
317
|
+
export declare const PendingValue: unique symbol;
|
|
318
|
+
export type LoadingType = typeof PendingValue;
|
|
286
319
|
export {};
|
|
@@ -3,7 +3,6 @@ import type { GraphQLObject, GraphQLValue, NestedList, SubscriptionSelection, Su
|
|
|
3
3
|
import { GarbageCollector } from './gc';
|
|
4
4
|
import type { ListCollection } from './lists';
|
|
5
5
|
import { ListManager } from './lists';
|
|
6
|
-
import { SchemaManager } from './schema';
|
|
7
6
|
import { StaleManager } from './staleManager';
|
|
8
7
|
import type { Layer, LayerID } from './storage';
|
|
9
8
|
import { InMemoryStorage } from './storage';
|
|
@@ -57,15 +56,13 @@ declare class CacheInternal {
|
|
|
57
56
|
cache: Cache;
|
|
58
57
|
lifetimes: GarbageCollector;
|
|
59
58
|
staleManager: StaleManager;
|
|
60
|
-
|
|
61
|
-
constructor({ storage, subscriptions, lists, cache, lifetimes, staleManager, schema, disabled, config, }: {
|
|
59
|
+
constructor({ storage, subscriptions, lists, cache, lifetimes, staleManager, disabled, config, }: {
|
|
62
60
|
storage: InMemoryStorage;
|
|
63
61
|
subscriptions: InMemorySubscriptions;
|
|
64
62
|
lists: ListManager;
|
|
65
63
|
cache: Cache;
|
|
66
64
|
lifetimes: GarbageCollector;
|
|
67
65
|
staleManager: StaleManager;
|
|
68
|
-
schema: SchemaManager;
|
|
69
66
|
disabled: boolean;
|
|
70
67
|
config?: ConfigFile;
|
|
71
68
|
});
|
|
@@ -87,12 +84,14 @@ declare class CacheInternal {
|
|
|
87
84
|
forceNotify?: boolean;
|
|
88
85
|
forceStale?: boolean;
|
|
89
86
|
}): FieldSelection[];
|
|
90
|
-
getSelection({ selection, parent, variables, stepsFromConnection, ignoreMasking, }: {
|
|
87
|
+
getSelection({ selection, parent, variables, stepsFromConnection, ignoreMasking, fullCheck, loading: generateLoading, }: {
|
|
91
88
|
selection: SubscriptionSelection;
|
|
92
89
|
parent?: string;
|
|
93
|
-
variables?: {};
|
|
90
|
+
variables?: {} | null;
|
|
94
91
|
stepsFromConnection?: number | null;
|
|
95
92
|
ignoreMasking?: boolean;
|
|
93
|
+
loading?: boolean;
|
|
94
|
+
fullCheck?: boolean;
|
|
96
95
|
}): {
|
|
97
96
|
data: GraphQLObject | null;
|
|
98
97
|
partial: boolean;
|
|
@@ -103,12 +102,14 @@ declare class CacheInternal {
|
|
|
103
102
|
id(type: string, id: string): string | null;
|
|
104
103
|
idFields(type: string): string[];
|
|
105
104
|
computeID(type: string, data: any): string;
|
|
106
|
-
hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, ignoreMasking, }: {
|
|
105
|
+
hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, ignoreMasking, fullCheck, loading, }: {
|
|
107
106
|
fields: SubscriptionSelection;
|
|
108
|
-
variables?: {};
|
|
107
|
+
variables?: {} | null;
|
|
109
108
|
linkedList: NestedList;
|
|
110
109
|
stepsFromConnection: number | null;
|
|
111
110
|
ignoreMasking: boolean;
|
|
111
|
+
fullCheck?: boolean;
|
|
112
|
+
loading?: boolean;
|
|
112
113
|
}): {
|
|
113
114
|
data: NestedList<GraphQLValue>;
|
|
114
115
|
partial: boolean;
|
|
@@ -31,7 +31,6 @@ var import_selection = require("../lib/selection");
|
|
|
31
31
|
var import_types = require("../lib/types");
|
|
32
32
|
var import_gc = require("./gc");
|
|
33
33
|
var import_lists = require("./lists");
|
|
34
|
-
var import_schema = require("./schema");
|
|
35
34
|
var import_staleManager = require("./staleManager");
|
|
36
35
|
var import_storage = require("./storage");
|
|
37
36
|
var import_stuff = require("./stuff");
|
|
@@ -46,7 +45,6 @@ class Cache {
|
|
|
46
45
|
lists: new import_lists.ListManager(this, rootID),
|
|
47
46
|
lifetimes: new import_gc.GarbageCollector(this),
|
|
48
47
|
staleManager: new import_staleManager.StaleManager(this),
|
|
49
|
-
schema: new import_schema.SchemaManager(this),
|
|
50
48
|
disabled: disabled ?? typeof globalThis.window === "undefined"
|
|
51
49
|
});
|
|
52
50
|
if (Object.keys(config).length > 0) {
|
|
@@ -157,7 +155,6 @@ class CacheInternal {
|
|
|
157
155
|
cache;
|
|
158
156
|
lifetimes;
|
|
159
157
|
staleManager;
|
|
160
|
-
schema;
|
|
161
158
|
constructor({
|
|
162
159
|
storage,
|
|
163
160
|
subscriptions,
|
|
@@ -165,7 +162,6 @@ class CacheInternal {
|
|
|
165
162
|
cache,
|
|
166
163
|
lifetimes,
|
|
167
164
|
staleManager,
|
|
168
|
-
schema,
|
|
169
165
|
disabled,
|
|
170
166
|
config
|
|
171
167
|
}) {
|
|
@@ -175,7 +171,6 @@ class CacheInternal {
|
|
|
175
171
|
this.cache = cache;
|
|
176
172
|
this.lifetimes = lifetimes;
|
|
177
173
|
this.staleManager = staleManager;
|
|
178
|
-
this.schema = schema;
|
|
179
174
|
this._config = config;
|
|
180
175
|
this._disabled = disabled;
|
|
181
176
|
try {
|
|
@@ -205,7 +200,11 @@ class CacheInternal {
|
|
|
205
200
|
if (this._disabled) {
|
|
206
201
|
return [];
|
|
207
202
|
}
|
|
208
|
-
let targetSelection = (0, import_selection.getFieldsForType)(
|
|
203
|
+
let targetSelection = (0, import_selection.getFieldsForType)(
|
|
204
|
+
selection,
|
|
205
|
+
data["__typename"],
|
|
206
|
+
false
|
|
207
|
+
);
|
|
209
208
|
for (const [field, value] of Object.entries(data)) {
|
|
210
209
|
if (!selection || !targetSelection[field]) {
|
|
211
210
|
continue;
|
|
@@ -216,17 +215,9 @@ class CacheInternal {
|
|
|
216
215
|
selection: fieldSelection,
|
|
217
216
|
operations,
|
|
218
217
|
abstract: isAbstract,
|
|
219
|
-
updates
|
|
220
|
-
nullable
|
|
218
|
+
updates
|
|
221
219
|
} = targetSelection[field];
|
|
222
220
|
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
223
|
-
this.schema.setFieldType({
|
|
224
|
-
parent,
|
|
225
|
-
key: keyRaw,
|
|
226
|
-
type: linkedType,
|
|
227
|
-
nullable,
|
|
228
|
-
link: !!fieldSelection
|
|
229
|
-
});
|
|
230
221
|
if (value && typeof value === "object" && "__typename" in value && value["__typename"]) {
|
|
231
222
|
linkedType = value["__typename"];
|
|
232
223
|
}
|
|
@@ -471,42 +462,83 @@ class CacheInternal {
|
|
|
471
462
|
parent = rootID,
|
|
472
463
|
variables,
|
|
473
464
|
stepsFromConnection = null,
|
|
474
|
-
ignoreMasking
|
|
465
|
+
ignoreMasking,
|
|
466
|
+
fullCheck = false,
|
|
467
|
+
loading: generateLoading
|
|
475
468
|
}) {
|
|
476
469
|
if (parent === null) {
|
|
477
470
|
return { data: null, partial: false, stale: false, hasData: true };
|
|
478
471
|
}
|
|
479
472
|
const target = {};
|
|
480
473
|
if (selection.fragments) {
|
|
481
|
-
target[import_types.fragmentKey] =
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
474
|
+
target[import_types.fragmentKey] = {
|
|
475
|
+
loading: Boolean(generateLoading),
|
|
476
|
+
values: Object.fromEntries(
|
|
477
|
+
Object.entries(selection.fragments).filter(([, value]) => !generateLoading || value.loading).map(([key, value]) => [
|
|
478
|
+
key,
|
|
479
|
+
{
|
|
480
|
+
parent,
|
|
481
|
+
variables: evaluateFragmentVariables(
|
|
482
|
+
value.arguments,
|
|
483
|
+
variables ?? {}
|
|
484
|
+
)
|
|
485
|
+
}
|
|
486
|
+
])
|
|
487
|
+
)
|
|
488
|
+
};
|
|
490
489
|
}
|
|
491
490
|
let hasData = !!selection.fragments;
|
|
492
491
|
let partial = false;
|
|
493
492
|
let cascadeNull = false;
|
|
494
493
|
let stale = false;
|
|
495
494
|
const typename = this.storage.get(parent, "__typename").value;
|
|
496
|
-
let targetSelection = (0, import_selection.getFieldsForType)(selection, typename);
|
|
495
|
+
let targetSelection = (0, import_selection.getFieldsForType)(selection, typename, !!generateLoading);
|
|
497
496
|
for (const [
|
|
498
497
|
attributeName,
|
|
499
|
-
{
|
|
498
|
+
{
|
|
499
|
+
type,
|
|
500
|
+
keyRaw,
|
|
501
|
+
selection: fieldSelection,
|
|
502
|
+
nullable,
|
|
503
|
+
list,
|
|
504
|
+
visible,
|
|
505
|
+
directives,
|
|
506
|
+
loading: fieldLoading,
|
|
507
|
+
abstractHasRequired
|
|
508
|
+
}
|
|
500
509
|
] of Object.entries(targetSelection)) {
|
|
501
|
-
if (!visible && !ignoreMasking) {
|
|
510
|
+
if (!visible && !ignoreMasking && !fullCheck) {
|
|
502
511
|
continue;
|
|
503
512
|
}
|
|
513
|
+
const includeDirective = directives?.find((d) => {
|
|
514
|
+
return d.name === "include";
|
|
515
|
+
});
|
|
516
|
+
if (includeDirective) {
|
|
517
|
+
if (!evaluateFragmentVariables(includeDirective.arguments, variables ?? {})["if"]) {
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
const skipDirective = directives?.find((d) => {
|
|
522
|
+
return d.name === "skip";
|
|
523
|
+
});
|
|
524
|
+
if (skipDirective) {
|
|
525
|
+
if (evaluateFragmentVariables(skipDirective.arguments, variables ?? {})["if"]) {
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
const fieldTarget = visible || ignoreMasking ? target : {};
|
|
504
530
|
const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
|
|
505
|
-
|
|
531
|
+
if (generateLoading && !fieldLoading) {
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
let { value } = this.storage.get(parent, key);
|
|
506
535
|
const dt_field = this.staleManager.getFieldTime(parent, key);
|
|
507
536
|
if (dt_field === null) {
|
|
508
537
|
stale = true;
|
|
509
538
|
}
|
|
539
|
+
if (generateLoading) {
|
|
540
|
+
value = void 0;
|
|
541
|
+
}
|
|
510
542
|
let nextStep = stepsFromConnection;
|
|
511
543
|
if (nextStep !== null) {
|
|
512
544
|
if (nextStep >= 2) {
|
|
@@ -522,17 +554,20 @@ class CacheInternal {
|
|
|
522
554
|
if (typeof value === "undefined" && !embeddedCursor) {
|
|
523
555
|
partial = true;
|
|
524
556
|
}
|
|
525
|
-
if (
|
|
526
|
-
|
|
557
|
+
if (generateLoading && fieldLoading?.kind === "value") {
|
|
558
|
+
fieldTarget[attributeName] = import_lib.PendingValue;
|
|
559
|
+
hasData = true;
|
|
560
|
+
} else if (!generateLoading && typeof value === "undefined" || value === null) {
|
|
561
|
+
fieldTarget[attributeName] = null;
|
|
527
562
|
if (typeof value !== "undefined") {
|
|
528
563
|
hasData = true;
|
|
529
564
|
}
|
|
530
565
|
} else if (!fieldSelection) {
|
|
531
566
|
const fnUnmarshal = this.config?.scalars?.[type]?.unmarshal;
|
|
532
567
|
if (fnUnmarshal) {
|
|
533
|
-
|
|
568
|
+
fieldTarget[attributeName] = fnUnmarshal(value);
|
|
534
569
|
} else {
|
|
535
|
-
|
|
570
|
+
fieldTarget[attributeName] = value;
|
|
536
571
|
}
|
|
537
572
|
hasData = true;
|
|
538
573
|
} else if (Array.isArray(value)) {
|
|
@@ -541,9 +576,11 @@ class CacheInternal {
|
|
|
541
576
|
variables,
|
|
542
577
|
linkedList: value,
|
|
543
578
|
stepsFromConnection: nextStep,
|
|
544
|
-
ignoreMasking: !!ignoreMasking
|
|
579
|
+
ignoreMasking: !!ignoreMasking,
|
|
580
|
+
fullCheck,
|
|
581
|
+
loading: generateLoading
|
|
545
582
|
});
|
|
546
|
-
|
|
583
|
+
fieldTarget[attributeName] = listValue.data;
|
|
547
584
|
if (listValue.partial) {
|
|
548
585
|
partial = true;
|
|
549
586
|
}
|
|
@@ -559,9 +596,11 @@ class CacheInternal {
|
|
|
559
596
|
selection: fieldSelection,
|
|
560
597
|
variables,
|
|
561
598
|
stepsFromConnection: nextStep,
|
|
562
|
-
ignoreMasking
|
|
599
|
+
ignoreMasking,
|
|
600
|
+
fullCheck,
|
|
601
|
+
loading: generateLoading
|
|
563
602
|
});
|
|
564
|
-
|
|
603
|
+
fieldTarget[attributeName] = objectFields.data;
|
|
565
604
|
if (objectFields.partial) {
|
|
566
605
|
partial = true;
|
|
567
606
|
}
|
|
@@ -572,13 +611,27 @@ class CacheInternal {
|
|
|
572
611
|
hasData = true;
|
|
573
612
|
}
|
|
574
613
|
}
|
|
575
|
-
if (
|
|
576
|
-
|
|
614
|
+
if (generateLoading && fieldLoading?.list) {
|
|
615
|
+
fieldTarget[attributeName] = wrapInLists(
|
|
616
|
+
Array.from({ length: fieldLoading.list.count }).fill(
|
|
617
|
+
fieldTarget[attributeName]
|
|
618
|
+
),
|
|
619
|
+
fieldLoading.list.depth - 1
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
if (fieldTarget[attributeName] === null && !nullable && !embeddedCursor) {
|
|
623
|
+
if (abstractHasRequired) {
|
|
624
|
+
target[attributeName] = {
|
|
625
|
+
__typename: "@required field missing; don't match this"
|
|
626
|
+
};
|
|
627
|
+
} else {
|
|
628
|
+
cascadeNull = true;
|
|
629
|
+
}
|
|
577
630
|
}
|
|
578
631
|
}
|
|
579
632
|
return {
|
|
580
633
|
data: cascadeNull ? null : target,
|
|
581
|
-
partial: hasData && partial,
|
|
634
|
+
partial: !generateLoading && hasData && partial,
|
|
582
635
|
stale: hasData && stale,
|
|
583
636
|
hasData
|
|
584
637
|
};
|
|
@@ -604,7 +657,9 @@ class CacheInternal {
|
|
|
604
657
|
variables,
|
|
605
658
|
linkedList,
|
|
606
659
|
stepsFromConnection,
|
|
607
|
-
ignoreMasking
|
|
660
|
+
ignoreMasking,
|
|
661
|
+
fullCheck,
|
|
662
|
+
loading
|
|
608
663
|
}) {
|
|
609
664
|
const result = [];
|
|
610
665
|
let partialData = false;
|
|
@@ -617,7 +672,9 @@ class CacheInternal {
|
|
|
617
672
|
variables,
|
|
618
673
|
linkedList: entry,
|
|
619
674
|
stepsFromConnection,
|
|
620
|
-
ignoreMasking
|
|
675
|
+
ignoreMasking,
|
|
676
|
+
fullCheck,
|
|
677
|
+
loading
|
|
621
678
|
});
|
|
622
679
|
result.push(nestedValue.data);
|
|
623
680
|
if (nestedValue.partial) {
|
|
@@ -639,7 +696,9 @@ class CacheInternal {
|
|
|
639
696
|
selection: fields,
|
|
640
697
|
variables,
|
|
641
698
|
stepsFromConnection,
|
|
642
|
-
ignoreMasking
|
|
699
|
+
ignoreMasking,
|
|
700
|
+
fullCheck,
|
|
701
|
+
loading
|
|
643
702
|
});
|
|
644
703
|
result.push(data);
|
|
645
704
|
if (partial) {
|
|
@@ -746,6 +805,12 @@ function evaluateFragmentVariables(variables, args) {
|
|
|
746
805
|
Object.entries(variables).map(([key, value]) => [key, fragmentVariableValue(value, args)])
|
|
747
806
|
);
|
|
748
807
|
}
|
|
808
|
+
function wrapInLists(target, count = 0) {
|
|
809
|
+
if (count === 0) {
|
|
810
|
+
return target;
|
|
811
|
+
}
|
|
812
|
+
return wrapInLists([target], count - 1);
|
|
813
|
+
}
|
|
749
814
|
function fragmentVariableValue(value, args) {
|
|
750
815
|
if (value.kind === "StringValue") {
|
|
751
816
|
return value.value;
|
|
@@ -21,7 +21,7 @@ __export(stuff_exports, {
|
|
|
21
21
|
evaluateKey: () => evaluateKey
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(stuff_exports);
|
|
24
|
-
function evaluateKey(key, variables =
|
|
24
|
+
function evaluateKey(key, variables = null) {
|
|
25
25
|
let evaluated = "";
|
|
26
26
|
let varName = "";
|
|
27
27
|
let inString = false;
|
|
@@ -31,7 +31,7 @@ function evaluateKey(key, variables = {}) {
|
|
|
31
31
|
varName += char;
|
|
32
32
|
continue;
|
|
33
33
|
}
|
|
34
|
-
const value = variables[varName.slice(1)];
|
|
34
|
+
const value = variables?.[varName.slice(1)];
|
|
35
35
|
evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
|
|
36
36
|
varName = "";
|
|
37
37
|
}
|