houdini 1.1.7 → 1.2.0-next.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.
Files changed (88) hide show
  1. package/README.md +1 -1
  2. package/build/cmd-cjs/index.js +1739 -1256
  3. package/build/cmd-esm/index.js +1739 -1256
  4. package/build/codegen/generators/artifacts/selection.d.ts +2 -1
  5. package/build/codegen/generators/typescript/inlineType.d.ts +5 -2
  6. package/build/codegen/generators/typescript/loadingState.d.ts +8 -0
  7. package/build/codegen-cjs/index.js +1701 -1241
  8. package/build/codegen-esm/index.js +1701 -1241
  9. package/build/lib/config.d.ts +5 -0
  10. package/build/lib/graphql.d.ts +5 -1
  11. package/build/lib/parse.d.ts +11 -1
  12. package/build/lib/types.d.ts +4 -1
  13. package/build/lib-cjs/index.js +611 -493
  14. package/build/lib-esm/index.js +608 -493
  15. package/build/runtime/cache/cache.d.ts +7 -8
  16. package/build/runtime/cache/stuff.d.ts +1 -4
  17. package/build/runtime/client/documentStore.d.ts +6 -3
  18. package/build/runtime/client/index.d.ts +9 -8
  19. package/build/runtime/client/plugins/cache.d.ts +1 -1
  20. package/build/runtime/client/plugins/fetch.d.ts +1 -0
  21. package/build/runtime/client/plugins/subscription.d.ts +1 -0
  22. package/build/runtime/client/plugins/throwOnError.d.ts +2 -1
  23. package/build/runtime/lib/pageInfo.d.ts +7 -0
  24. package/build/runtime/lib/pagination.d.ts +27 -0
  25. package/build/runtime/lib/selection.d.ts +1 -1
  26. package/build/runtime/lib/types.d.ts +79 -4
  27. package/build/runtime-cjs/cache/cache.d.ts +7 -8
  28. package/build/runtime-cjs/cache/cache.js +78 -36
  29. package/build/runtime-cjs/cache/stuff.d.ts +1 -4
  30. package/build/runtime-cjs/cache/stuff.js +2 -2
  31. package/build/runtime-cjs/cache/subscription.js +5 -5
  32. package/build/runtime-cjs/client/documentStore.d.ts +6 -3
  33. package/build/runtime-cjs/client/documentStore.js +20 -7
  34. package/build/runtime-cjs/client/index.d.ts +9 -8
  35. package/build/runtime-cjs/client/index.js +12 -4
  36. package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
  37. package/build/runtime-cjs/client/plugins/cache.js +12 -2
  38. package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -0
  39. package/build/runtime-cjs/client/plugins/fetch.js +3 -2
  40. package/build/runtime-cjs/client/plugins/fragment.js +8 -1
  41. package/build/runtime-cjs/client/plugins/query.js +2 -1
  42. package/build/runtime-cjs/client/plugins/subscription.d.ts +1 -0
  43. package/build/runtime-cjs/client/plugins/subscription.js +1 -0
  44. package/build/runtime-cjs/client/plugins/throwOnError.d.ts +2 -1
  45. package/build/runtime-cjs/lib/config.js +2 -1
  46. package/build/runtime-cjs/lib/pageInfo.d.ts +7 -0
  47. package/build/runtime-cjs/lib/pageInfo.js +79 -0
  48. package/build/runtime-cjs/lib/pagination.d.ts +27 -0
  49. package/build/runtime-cjs/lib/pagination.js +219 -0
  50. package/build/runtime-cjs/lib/scalars.js +1 -1
  51. package/build/runtime-cjs/lib/selection.d.ts +1 -1
  52. package/build/runtime-cjs/lib/selection.js +28 -1
  53. package/build/runtime-cjs/lib/types.d.ts +79 -4
  54. package/build/runtime-cjs/lib/types.js +3 -0
  55. package/build/runtime-esm/cache/cache.d.ts +7 -8
  56. package/build/runtime-esm/cache/cache.js +79 -37
  57. package/build/runtime-esm/cache/stuff.d.ts +1 -4
  58. package/build/runtime-esm/cache/stuff.js +2 -2
  59. package/build/runtime-esm/cache/subscription.js +5 -5
  60. package/build/runtime-esm/client/documentStore.d.ts +6 -3
  61. package/build/runtime-esm/client/documentStore.js +20 -7
  62. package/build/runtime-esm/client/index.d.ts +9 -8
  63. package/build/runtime-esm/client/index.js +15 -7
  64. package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
  65. package/build/runtime-esm/client/plugins/cache.js +12 -2
  66. package/build/runtime-esm/client/plugins/fetch.d.ts +1 -0
  67. package/build/runtime-esm/client/plugins/fetch.js +3 -2
  68. package/build/runtime-esm/client/plugins/fragment.js +8 -1
  69. package/build/runtime-esm/client/plugins/query.js +2 -1
  70. package/build/runtime-esm/client/plugins/subscription.d.ts +1 -0
  71. package/build/runtime-esm/client/plugins/subscription.js +1 -0
  72. package/build/runtime-esm/client/plugins/throwOnError.d.ts +2 -1
  73. package/build/runtime-esm/lib/config.js +2 -1
  74. package/build/runtime-esm/lib/pageInfo.d.ts +7 -0
  75. package/build/runtime-esm/lib/pageInfo.js +52 -0
  76. package/build/runtime-esm/lib/pagination.d.ts +27 -0
  77. package/build/runtime-esm/lib/pagination.js +194 -0
  78. package/build/runtime-esm/lib/scalars.js +1 -1
  79. package/build/runtime-esm/lib/selection.d.ts +1 -1
  80. package/build/runtime-esm/lib/selection.js +28 -1
  81. package/build/runtime-esm/lib/types.d.ts +79 -4
  82. package/build/runtime-esm/lib/types.js +2 -0
  83. package/build/test/index.d.ts +15 -0
  84. package/build/test-cjs/index.js +1706 -1223
  85. package/build/test-esm/index.js +1706 -1223
  86. package/build/vite-cjs/index.js +1757 -1274
  87. package/build/vite-esm/index.js +1757 -1274
  88. package/package.json +5 -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
- schema: SchemaManager;
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,13 @@ declare class CacheInternal {
87
84
  forceNotify?: boolean;
88
85
  forceStale?: boolean;
89
86
  }): FieldSelection[];
90
- getSelection({ selection, parent, variables, stepsFromConnection, ignoreMasking, fullCheck, }: {
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;
96
94
  fullCheck?: boolean;
97
95
  }): {
98
96
  data: GraphQLObject | null;
@@ -104,13 +102,14 @@ declare class CacheInternal {
104
102
  id(type: string, id: string): string | null;
105
103
  idFields(type: string): string[];
106
104
  computeID(type: string, data: any): string;
107
- hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, ignoreMasking, fullCheck, }: {
105
+ hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, ignoreMasking, fullCheck, loading, }: {
108
106
  fields: SubscriptionSelection;
109
- variables?: {};
107
+ variables?: {} | null;
110
108
  linkedList: NestedList;
111
109
  stepsFromConnection: number | null;
112
110
  ignoreMasking: boolean;
113
111
  fullCheck?: boolean;
112
+ loading?: boolean;
114
113
  }): {
115
114
  data: NestedList<GraphQLValue>;
116
115
  partial: boolean;
@@ -1,4 +1 @@
1
- import type { GraphQLValue } from '../lib/types';
2
- export declare function evaluateKey(key: string, variables?: {
3
- [key: string]: GraphQLValue;
4
- }): string;
1
+ export declare function evaluateKey(key: string, variables?: Record<string, any> | null): string;
@@ -2,9 +2,12 @@ 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 Record<string, any>> extends Writable<QueryResult<_Data, _Input>> {
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
+ pendingPromise: {
9
+ then: (val: any) => void;
10
+ } | null;
8
11
  constructor({ artifact, plugins, pipeline, client, cache, initialValue, fetching, }: {
9
12
  artifact: DocumentArtifact;
10
13
  plugins?: ClientHooks[];
@@ -17,7 +20,7 @@ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends R
17
20
  send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, silenceEcho, }?: SendParams): Promise<QueryResult<_Data, _Input>>;
18
21
  cleanup(): Promise<void>;
19
22
  }
20
- declare function marshalVariables<_Data extends GraphQLObject, _Input extends {}>(ctx: ClientPluginContext): Record<string, any>;
23
+ declare function marshalVariables<_Data extends GraphQLObject, _Input extends GraphQLVariables>(ctx: ClientPluginContext): Record<string, any>;
21
24
  export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
22
25
  export type ClientHooks = {
23
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 { ClientPlugin, ClientHooks } from './documentStore';
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 { type FetchParamFn, type ThrowOnErrorParams } from './plugins';
6
- export { DocumentStore, type ClientPlugin } from './documentStore';
5
+ import type { FetchParamFn, ThrowOnErrorOperations, ThrowOnErrorParams } from './plugins';
6
+ export { DocumentStore, type ClientPlugin, type SendParams } from './documentStore';
7
7
  export { fetch, mutation, query, subscription } from './plugins';
8
- type ConstructorArgs = {
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
- constructor({ url, fetchParams, plugins, pipeline, throwOnError }: ConstructorArgs);
25
- observe<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, cache, initialValue, fetching, }: ObserveParams<_Data>): DocumentStore<_Data, _Input>;
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: ('all' | 'query' | 'mutation' | 'subscription')[];
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;
@@ -0,0 +1,7 @@
1
+ import type { GraphQLObject, PageInfo } from './types';
2
+ export declare function nullPageInfo(): PageInfo;
3
+ export declare function missingPageSizeError(fnName: string): {
4
+ message: string;
5
+ };
6
+ export declare function extractPageInfo(data: any, path: string[]): PageInfo;
7
+ export declare function countPage<_Data extends GraphQLObject>(source: string[], value: _Data | null): number;
@@ -0,0 +1,27 @@
1
+ import type { SendParams } from '../client/documentStore';
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, }: {
4
+ artifact: QueryArtifact;
5
+ getState: () => _Data | null;
6
+ getVariables: () => NonNullable<_Input>;
7
+ getSession: () => Promise<App.Session>;
8
+ fetch: FetchFn<_Data, _Input>;
9
+ fetchUpdate: (arg: SendParams, updates: string[]) => ReturnType<FetchFn<_Data, _Input>>;
10
+ }): CursorHandlers<_Data, _Input>;
11
+ export declare function offsetHandlers<_Data extends GraphQLObject, _Input extends GraphQLVariables>({ artifact, storeName, getState, getVariables, fetch: parentFetch, fetchUpdate: parentFetchUpdate, getSession, }: {
12
+ artifact: QueryArtifact;
13
+ fetch: FetchFn<_Data, _Input>;
14
+ fetchUpdate: (arg: SendParams) => ReturnType<FetchFn<_Data, _Input>>;
15
+ storeName: string;
16
+ getState: () => _Data | null;
17
+ getVariables: () => _Input;
18
+ getSession: () => Promise<App.Session>;
19
+ }): {
20
+ loadNextPage: ({ limit, offset, fetch, metadata, }?: {
21
+ limit?: number | undefined;
22
+ offset?: number | undefined;
23
+ fetch?: typeof fetch | undefined;
24
+ metadata?: {} | undefined;
25
+ }) => Promise<void>;
26
+ fetch(params?: FetchParams<_Input>): Promise<QueryResult<_Data, _Input>>;
27
+ };
@@ -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'];
@@ -25,6 +25,7 @@ declare global {
25
25
  };
26
26
  optimisticResponse?: GraphQLObject;
27
27
  parentID?: string;
28
+ silenceLoading?: boolean;
28
29
  }
29
30
  }
30
31
  }
@@ -52,9 +53,12 @@ export type CompiledDocumentKind = ArtifactKinds;
52
53
  export type QueryArtifact = BaseCompiledDocument<'HoudiniQuery'> & {
53
54
  policy?: CachePolicies;
54
55
  partial?: boolean;
56
+ enableLoadingState?: 'global' | 'local';
55
57
  };
56
58
  export type MutationArtifact = BaseCompiledDocument<'HoudiniMutation'>;
57
- export type FragmentArtifact = BaseCompiledDocument<'HoudiniFragment'>;
59
+ export type FragmentArtifact = BaseCompiledDocument<'HoudiniFragment'> & {
60
+ enableLoadingState?: 'global' | 'local';
61
+ };
58
62
  export type SubscriptionArtifact = BaseCompiledDocument<'HoudiniSubscription'>;
59
63
  export declare const RefetchUpdateMode: {
60
64
  readonly append: "append";
@@ -128,12 +132,34 @@ export type GraphQLObject = {
128
132
  [key: string]: GraphQLValue;
129
133
  };
130
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
+ };
131
152
  export type SubscriptionSelection = {
132
- fragments?: Record<string, ValueMap>;
153
+ loadingTypes?: string[];
154
+ fragments?: Record<string, {
155
+ arguments: ValueMap;
156
+ loading?: boolean;
157
+ }>;
133
158
  fields?: {
134
159
  [fieldName: string]: {
135
160
  type: string;
136
161
  nullable?: boolean;
162
+ required?: boolean;
137
163
  keyRaw: string;
138
164
  operations?: MutationOperation[];
139
165
  list?: {
@@ -141,6 +167,7 @@ export type SubscriptionSelection = {
141
167
  connection: boolean;
142
168
  type: string;
143
169
  };
170
+ loading?: LoadingSpec;
144
171
  directives?: {
145
172
  name: string;
146
173
  arguments: ValueMap;
@@ -153,6 +180,7 @@ export type SubscriptionSelection = {
153
180
  }>;
154
181
  selection?: SubscriptionSelection;
155
182
  abstract?: boolean;
183
+ abstractHasRequired?: boolean;
156
184
  };
157
185
  };
158
186
  abstractFields?: {
@@ -175,7 +203,7 @@ export type FetchQueryResult<_Data> = {
175
203
  result: RequestPayload<_Data | null>;
176
204
  source: DataSources | null;
177
205
  };
178
- export type QueryResult<_Data = GraphQLObject, _Input = Record<string, any>> = {
206
+ export type QueryResult<_Data = GraphQLObject, _Input = GraphQLVariables> = {
179
207
  data: _Data | null;
180
208
  errors: {
181
209
  message: string;
@@ -194,9 +222,54 @@ export type RequestPayload<GraphQLObject = any> = {
194
222
  };
195
223
  export type NestedList<_Result = string> = (_Result | null | NestedList<_Result>)[];
196
224
  export type ValueOf<Parent> = Parent[keyof Parent];
197
- export declare const fragmentKey = " $fragments";
225
+ export declare const fragmentKey: " $fragments";
198
226
  export type ValueNode = VariableNode | IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | ListValueNode | ObjectValueNode;
199
227
  export type ValueMap = Record<string, ValueNode>;
228
+ export type FetchParams<_Input> = {
229
+ variables?: _Input;
230
+ /**
231
+ * The policy to use when performing the fetch. If set to CachePolicy.NetworkOnly,
232
+ * a request will always be sent, even if the variables are the same as the last call
233
+ * to fetch.
234
+ */
235
+ policy?: CachePolicies;
236
+ /**
237
+ * An object that will be passed to the fetch function.
238
+ * You can do what you want with it!
239
+ */
240
+ metadata?: App.Metadata;
241
+ };
242
+ export type FetchFn<_Data extends GraphQLObject, _Input = any> = (params?: FetchParams<_Input>) => Promise<QueryResult<_Data, _Input>>;
243
+ export type CursorHandlers<_Data extends GraphQLObject, _Input> = {
244
+ loadNextPage: (args?: {
245
+ first?: number;
246
+ after?: string;
247
+ fetch?: typeof globalThis.fetch;
248
+ metadata?: {};
249
+ }) => Promise<void>;
250
+ loadPreviousPage: (args?: {
251
+ last?: number;
252
+ before?: string;
253
+ fetch?: typeof globalThis.fetch;
254
+ metadata?: {};
255
+ }) => Promise<void>;
256
+ fetch(args?: FetchParams<_Input> | undefined): Promise<QueryResult<_Data, _Input>>;
257
+ };
258
+ export type OffsetHandlers<_Data extends GraphQLObject, _Input> = {
259
+ loadNextPage: (args?: {
260
+ limit?: number;
261
+ offset?: number;
262
+ metadata?: {};
263
+ fetch?: typeof globalThis.fetch;
264
+ }) => Promise<void>;
265
+ fetch(args?: FetchParams<_Input> | undefined): Promise<QueryResult<_Data, _Input>>;
266
+ };
267
+ export type PageInfo = {
268
+ startCursor: string | null;
269
+ endCursor: string | null;
270
+ hasNextPage: boolean;
271
+ hasPreviousPage: boolean;
272
+ };
200
273
  interface IntValueNode {
201
274
  readonly kind: 'IntValue';
202
275
  readonly value: string;
@@ -241,4 +314,6 @@ interface VariableNode {
241
314
  readonly kind: 'Variable';
242
315
  readonly name: NameNode;
243
316
  }
317
+ export declare const PendingValue: unique symbol;
318
+ export type LoadingType = typeof PendingValue;
244
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
- schema: SchemaManager;
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,13 @@ declare class CacheInternal {
87
84
  forceNotify?: boolean;
88
85
  forceStale?: boolean;
89
86
  }): FieldSelection[];
90
- getSelection({ selection, parent, variables, stepsFromConnection, ignoreMasking, fullCheck, }: {
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;
96
94
  fullCheck?: boolean;
97
95
  }): {
98
96
  data: GraphQLObject | null;
@@ -104,13 +102,14 @@ declare class CacheInternal {
104
102
  id(type: string, id: string): string | null;
105
103
  idFields(type: string): string[];
106
104
  computeID(type: string, data: any): string;
107
- hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, ignoreMasking, fullCheck, }: {
105
+ hydrateNestedList({ fields, variables, linkedList, stepsFromConnection, ignoreMasking, fullCheck, loading, }: {
108
106
  fields: SubscriptionSelection;
109
- variables?: {};
107
+ variables?: {} | null;
110
108
  linkedList: NestedList;
111
109
  stepsFromConnection: number | null;
112
110
  ignoreMasking: boolean;
113
111
  fullCheck?: boolean;
112
+ loading?: boolean;
114
113
  }): {
115
114
  data: NestedList<GraphQLValue>;
116
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)(selection, data["__typename"]);
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
  }
@@ -472,32 +463,49 @@ class CacheInternal {
472
463
  variables,
473
464
  stepsFromConnection = null,
474
465
  ignoreMasking,
475
- fullCheck = false
466
+ fullCheck = false,
467
+ loading: generateLoading
476
468
  }) {
477
469
  if (parent === null) {
478
470
  return { data: null, partial: false, stale: false, hasData: true };
479
471
  }
480
472
  const target = {};
481
473
  if (selection.fragments) {
482
- target[import_types.fragmentKey] = Object.fromEntries(
483
- Object.entries(selection.fragments).map(([key, value]) => [
484
- key,
485
- {
486
- parent,
487
- variables: evaluateFragmentVariables(value, variables ?? {})
488
- }
489
- ])
490
- );
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
+ };
491
489
  }
492
490
  let hasData = !!selection.fragments;
493
491
  let partial = false;
494
492
  let cascadeNull = false;
495
493
  let stale = false;
496
494
  const typename = this.storage.get(parent, "__typename").value;
497
- let targetSelection = (0, import_selection.getFieldsForType)(selection, typename);
495
+ let targetSelection = (0, import_selection.getFieldsForType)(selection, typename, !!generateLoading);
498
496
  for (const [
499
497
  attributeName,
500
- { type, keyRaw, selection: fieldSelection, nullable, list, visible, directives }
498
+ {
499
+ type,
500
+ keyRaw,
501
+ selection: fieldSelection,
502
+ nullable,
503
+ list,
504
+ visible,
505
+ directives,
506
+ loading: fieldLoading,
507
+ abstractHasRequired
508
+ }
501
509
  ] of Object.entries(targetSelection)) {
502
510
  if (!visible && !ignoreMasking && !fullCheck) {
503
511
  continue;
@@ -520,11 +528,17 @@ class CacheInternal {
520
528
  }
521
529
  const fieldTarget = visible || ignoreMasking ? target : {};
522
530
  const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
523
- const { value } = this.storage.get(parent, key);
531
+ if (generateLoading && !fieldLoading) {
532
+ continue;
533
+ }
534
+ let { value } = this.storage.get(parent, key);
524
535
  const dt_field = this.staleManager.getFieldTime(parent, key);
525
536
  if (dt_field === null) {
526
537
  stale = true;
527
538
  }
539
+ if (generateLoading) {
540
+ value = void 0;
541
+ }
528
542
  let nextStep = stepsFromConnection;
529
543
  if (nextStep !== null) {
530
544
  if (nextStep >= 2) {
@@ -540,7 +554,10 @@ class CacheInternal {
540
554
  if (typeof value === "undefined" && !embeddedCursor) {
541
555
  partial = true;
542
556
  }
543
- if (typeof value === "undefined" || value === null) {
557
+ if (generateLoading && fieldLoading?.kind === "value") {
558
+ fieldTarget[attributeName] = import_lib.PendingValue;
559
+ hasData = true;
560
+ } else if (!generateLoading && typeof value === "undefined" || value === null) {
544
561
  fieldTarget[attributeName] = null;
545
562
  if (typeof value !== "undefined") {
546
563
  hasData = true;
@@ -560,7 +577,8 @@ class CacheInternal {
560
577
  linkedList: value,
561
578
  stepsFromConnection: nextStep,
562
579
  ignoreMasking: !!ignoreMasking,
563
- fullCheck
580
+ fullCheck,
581
+ loading: generateLoading
564
582
  });
565
583
  fieldTarget[attributeName] = listValue.data;
566
584
  if (listValue.partial) {
@@ -579,7 +597,8 @@ class CacheInternal {
579
597
  variables,
580
598
  stepsFromConnection: nextStep,
581
599
  ignoreMasking,
582
- fullCheck
600
+ fullCheck,
601
+ loading: generateLoading
583
602
  });
584
603
  fieldTarget[attributeName] = objectFields.data;
585
604
  if (objectFields.partial) {
@@ -592,13 +611,27 @@ class CacheInternal {
592
611
  hasData = true;
593
612
  }
594
613
  }
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
+ }
595
622
  if (fieldTarget[attributeName] === null && !nullable && !embeddedCursor) {
596
- cascadeNull = true;
623
+ if (abstractHasRequired) {
624
+ target[attributeName] = {
625
+ __typename: "@required field missing; don't match this"
626
+ };
627
+ } else {
628
+ cascadeNull = true;
629
+ }
597
630
  }
598
631
  }
599
632
  return {
600
633
  data: cascadeNull ? null : target,
601
- partial: hasData && partial,
634
+ partial: !generateLoading && hasData && partial,
602
635
  stale: hasData && stale,
603
636
  hasData
604
637
  };
@@ -625,7 +658,8 @@ class CacheInternal {
625
658
  linkedList,
626
659
  stepsFromConnection,
627
660
  ignoreMasking,
628
- fullCheck
661
+ fullCheck,
662
+ loading
629
663
  }) {
630
664
  const result = [];
631
665
  let partialData = false;
@@ -639,7 +673,8 @@ class CacheInternal {
639
673
  linkedList: entry,
640
674
  stepsFromConnection,
641
675
  ignoreMasking,
642
- fullCheck
676
+ fullCheck,
677
+ loading
643
678
  });
644
679
  result.push(nestedValue.data);
645
680
  if (nestedValue.partial) {
@@ -662,7 +697,8 @@ class CacheInternal {
662
697
  variables,
663
698
  stepsFromConnection,
664
699
  ignoreMasking,
665
- fullCheck
700
+ fullCheck,
701
+ loading
666
702
  });
667
703
  result.push(data);
668
704
  if (partial) {
@@ -769,6 +805,12 @@ function evaluateFragmentVariables(variables, args) {
769
805
  Object.entries(variables).map(([key, value]) => [key, fragmentVariableValue(value, args)])
770
806
  );
771
807
  }
808
+ function wrapInLists(target, count = 0) {
809
+ if (count === 0) {
810
+ return target;
811
+ }
812
+ return wrapInLists([target], count - 1);
813
+ }
772
814
  function fragmentVariableValue(value, args) {
773
815
  if (value.kind === "StringValue") {
774
816
  return value.value;
@@ -1,4 +1 @@
1
- import type { GraphQLValue } from '../lib/types';
2
- export declare function evaluateKey(key: string, variables?: {
3
- [key: string]: GraphQLValue;
4
- }): string;
1
+ export declare function evaluateKey(key: string, variables?: Record<string, any> | null): string;