houdini 1.1.7 → 1.2.0-next.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.
Files changed (85) hide show
  1. package/README.md +1 -1
  2. package/build/cmd-cjs/index.js +30737 -30175
  3. package/build/cmd-esm/index.js +30737 -30175
  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 +30791 -30254
  8. package/build/codegen-esm/index.js +30791 -30254
  9. package/build/lib/code.d.ts +11 -0
  10. package/build/lib/config.d.ts +5 -0
  11. package/build/lib/graphql.d.ts +5 -1
  12. package/build/lib/index.d.ts +1 -0
  13. package/build/lib/parse.d.ts +0 -7
  14. package/build/lib/types.d.ts +4 -1
  15. package/build/lib-cjs/index.js +29888 -29668
  16. package/build/lib-esm/index.js +29885 -29668
  17. package/build/runtime/cache/cache.d.ts +5 -6
  18. package/build/runtime/client/documentStore.d.ts +3 -0
  19. package/build/runtime/client/index.d.ts +7 -6
  20. package/build/runtime/client/plugins/cache.d.ts +1 -1
  21. package/build/runtime/client/plugins/fetch.d.ts +1 -0
  22. package/build/runtime/client/plugins/subscription.d.ts +1 -0
  23. package/build/runtime/client/plugins/throwOnError.d.ts +2 -1
  24. package/build/runtime/lib/pageInfo.d.ts +7 -0
  25. package/build/runtime/lib/pagination.d.ts +27 -0
  26. package/build/runtime/lib/selection.d.ts +1 -1
  27. package/build/runtime/lib/types.d.ts +75 -3
  28. package/build/runtime-cjs/cache/cache.d.ts +5 -6
  29. package/build/runtime-cjs/cache/cache.js +78 -36
  30. package/build/runtime-cjs/cache/subscription.js +5 -5
  31. package/build/runtime-cjs/client/documentStore.d.ts +3 -0
  32. package/build/runtime-cjs/client/documentStore.js +20 -7
  33. package/build/runtime-cjs/client/index.d.ts +7 -6
  34. package/build/runtime-cjs/client/index.js +12 -4
  35. package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
  36. package/build/runtime-cjs/client/plugins/cache.js +12 -2
  37. package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -0
  38. package/build/runtime-cjs/client/plugins/fetch.js +3 -2
  39. package/build/runtime-cjs/client/plugins/fragment.js +8 -1
  40. package/build/runtime-cjs/client/plugins/query.js +2 -1
  41. package/build/runtime-cjs/client/plugins/subscription.d.ts +1 -0
  42. package/build/runtime-cjs/client/plugins/subscription.js +1 -0
  43. package/build/runtime-cjs/client/plugins/throwOnError.d.ts +2 -1
  44. package/build/runtime-cjs/lib/config.js +2 -1
  45. package/build/runtime-cjs/lib/pageInfo.d.ts +7 -0
  46. package/build/runtime-cjs/lib/pageInfo.js +79 -0
  47. package/build/runtime-cjs/lib/pagination.d.ts +27 -0
  48. package/build/runtime-cjs/lib/pagination.js +219 -0
  49. package/build/runtime-cjs/lib/scalars.js +1 -1
  50. package/build/runtime-cjs/lib/selection.d.ts +1 -1
  51. package/build/runtime-cjs/lib/selection.js +28 -1
  52. package/build/runtime-cjs/lib/types.d.ts +75 -3
  53. package/build/runtime-cjs/lib/types.js +3 -0
  54. package/build/runtime-esm/cache/cache.d.ts +5 -6
  55. package/build/runtime-esm/cache/cache.js +79 -37
  56. package/build/runtime-esm/cache/subscription.js +5 -5
  57. package/build/runtime-esm/client/documentStore.d.ts +3 -0
  58. package/build/runtime-esm/client/documentStore.js +20 -7
  59. package/build/runtime-esm/client/index.d.ts +7 -6
  60. package/build/runtime-esm/client/index.js +15 -7
  61. package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
  62. package/build/runtime-esm/client/plugins/cache.js +12 -2
  63. package/build/runtime-esm/client/plugins/fetch.d.ts +1 -0
  64. package/build/runtime-esm/client/plugins/fetch.js +3 -2
  65. package/build/runtime-esm/client/plugins/fragment.js +8 -1
  66. package/build/runtime-esm/client/plugins/query.js +2 -1
  67. package/build/runtime-esm/client/plugins/subscription.d.ts +1 -0
  68. package/build/runtime-esm/client/plugins/subscription.js +1 -0
  69. package/build/runtime-esm/client/plugins/throwOnError.d.ts +2 -1
  70. package/build/runtime-esm/lib/config.js +2 -1
  71. package/build/runtime-esm/lib/pageInfo.d.ts +7 -0
  72. package/build/runtime-esm/lib/pageInfo.js +52 -0
  73. package/build/runtime-esm/lib/pagination.d.ts +27 -0
  74. package/build/runtime-esm/lib/pagination.js +194 -0
  75. package/build/runtime-esm/lib/scalars.js +1 -1
  76. package/build/runtime-esm/lib/selection.d.ts +1 -1
  77. package/build/runtime-esm/lib/selection.js +28 -1
  78. package/build/runtime-esm/lib/types.d.ts +75 -3
  79. package/build/runtime-esm/lib/types.js +2 -0
  80. package/build/test/index.d.ts +15 -0
  81. package/build/test-cjs/index.js +30699 -30140
  82. package/build/test-esm/index.js +30699 -30140
  83. package/build/vite-cjs/index.js +30765 -30205
  84. package/build/vite-esm/index.js +30765 -30205
  85. 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
90
  variables?: {};
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
107
  variables?: {};
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;
@@ -5,6 +5,9 @@ import { Writable } from '../lib/store';
5
5
  import type { DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec, CachePolicies } from '../lib/types';
6
6
  export declare class DocumentStore<_Data extends GraphQLObject, _Input extends Record<string, any>> 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[];
@@ -1,11 +1,11 @@
1
1
  /// <reference path="../../../../../houdini.d.ts" />
2
2
  import type { DocumentArtifact, GraphQLObject, NestedList } from '../lib/types';
3
- import type { ClientPlugin, ClientHooks } from './documentStore';
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);
23
+ readonly plugins: ClientPlugin[];
24
+ readonly throwOnError_operations: ThrowOnErrorOperations[];
25
+ constructor({ url, fetchParams, plugins, pipeline, throwOnError, }: HoudiniClientConstructorArgs);
25
26
  observe<_Data extends GraphQLObject, _Input extends Record<string, any>>({ 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, QueryArtifact, QueryResult, FetchParams } from './types';
3
+ export declare function cursorHandlers<_Data extends GraphQLObject, _Input extends Record<string, any>>({ artifact, fetchUpdate: parentFetchUpdate, fetch: parentFetch, getState, getVariables, getSession, }: {
4
+ artifact: QueryArtifact;
5
+ getState: () => _Data | null;
6
+ getVariables: () => _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 {}>({ 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?: boolean;
55
57
  };
56
58
  export type MutationArtifact = BaseCompiledDocument<'HoudiniMutation'>;
57
- export type FragmentArtifact = BaseCompiledDocument<'HoudiniFragment'>;
59
+ export type FragmentArtifact = BaseCompiledDocument<'HoudiniFragment'> & {
60
+ enableLoadingState?: boolean;
61
+ };
58
62
  export type SubscriptionArtifact = BaseCompiledDocument<'HoudiniSubscription'>;
59
63
  export declare const RefetchUpdateMode: {
60
64
  readonly append: "append";
@@ -128,12 +132,31 @@ 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 LoadingSpec = {
136
+ kind: 'continue';
137
+ list?: {
138
+ depth: number;
139
+ count: number;
140
+ };
141
+ } | {
142
+ kind: 'value';
143
+ value?: any;
144
+ list?: {
145
+ depth: number;
146
+ count: number;
147
+ };
148
+ };
131
149
  export type SubscriptionSelection = {
132
- fragments?: Record<string, ValueMap>;
150
+ loadingTypes?: string[];
151
+ fragments?: Record<string, {
152
+ arguments: ValueMap;
153
+ loading?: boolean;
154
+ }>;
133
155
  fields?: {
134
156
  [fieldName: string]: {
135
157
  type: string;
136
158
  nullable?: boolean;
159
+ required?: boolean;
137
160
  keyRaw: string;
138
161
  operations?: MutationOperation[];
139
162
  list?: {
@@ -141,6 +164,7 @@ export type SubscriptionSelection = {
141
164
  connection: boolean;
142
165
  type: string;
143
166
  };
167
+ loading?: LoadingSpec;
144
168
  directives?: {
145
169
  name: string;
146
170
  arguments: ValueMap;
@@ -153,6 +177,7 @@ export type SubscriptionSelection = {
153
177
  }>;
154
178
  selection?: SubscriptionSelection;
155
179
  abstract?: boolean;
180
+ abstractHasRequired?: boolean;
156
181
  };
157
182
  };
158
183
  abstractFields?: {
@@ -194,9 +219,54 @@ export type RequestPayload<GraphQLObject = any> = {
194
219
  };
195
220
  export type NestedList<_Result = string> = (_Result | null | NestedList<_Result>)[];
196
221
  export type ValueOf<Parent> = Parent[keyof Parent];
197
- export declare const fragmentKey = " $fragments";
222
+ export declare const fragmentKey: " $fragments";
198
223
  export type ValueNode = VariableNode | IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | ListValueNode | ObjectValueNode;
199
224
  export type ValueMap = Record<string, ValueNode>;
225
+ export type FetchParams<_Input> = {
226
+ variables?: _Input;
227
+ /**
228
+ * The policy to use when performing the fetch. If set to CachePolicy.NetworkOnly,
229
+ * a request will always be sent, even if the variables are the same as the last call
230
+ * to fetch.
231
+ */
232
+ policy?: CachePolicies;
233
+ /**
234
+ * An object that will be passed to the fetch function.
235
+ * You can do what you want with it!
236
+ */
237
+ metadata?: App.Metadata;
238
+ };
239
+ export type FetchFn<_Data extends GraphQLObject, _Input = any> = (params?: FetchParams<_Input>) => Promise<QueryResult<_Data, _Input>>;
240
+ export type CursorHandlers<_Data extends GraphQLObject, _Input> = {
241
+ loadNextPage: (args?: {
242
+ first?: number;
243
+ after?: string;
244
+ fetch?: typeof globalThis.fetch;
245
+ metadata?: {};
246
+ }) => Promise<void>;
247
+ loadPreviousPage: (args?: {
248
+ last?: number;
249
+ before?: string;
250
+ fetch?: typeof globalThis.fetch;
251
+ metadata?: {};
252
+ }) => Promise<void>;
253
+ fetch(args?: FetchParams<_Input> | undefined): Promise<QueryResult<_Data, _Input>>;
254
+ };
255
+ export type OffsetHandlers<_Data extends GraphQLObject, _Input> = {
256
+ loadNextPage: (args?: {
257
+ limit?: number;
258
+ offset?: number;
259
+ metadata?: {};
260
+ fetch?: typeof globalThis.fetch;
261
+ }) => Promise<void>;
262
+ fetch(args?: FetchParams<_Input> | undefined): Promise<QueryResult<_Data, _Input>>;
263
+ };
264
+ export type PageInfo = {
265
+ startCursor: string | null;
266
+ endCursor: string | null;
267
+ hasNextPage: boolean;
268
+ hasPreviousPage: boolean;
269
+ };
200
270
  interface IntValueNode {
201
271
  readonly kind: 'IntValue';
202
272
  readonly value: string;
@@ -241,4 +311,6 @@ interface VariableNode {
241
311
  readonly kind: 'Variable';
242
312
  readonly name: NameNode;
243
313
  }
314
+ export declare const PendingValue: unique symbol;
315
+ export type LoadingType = typeof PendingValue;
244
316
  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
90
  variables?: {};
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
107
  variables?: {};
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;
@@ -40,7 +40,7 @@ class InMemorySubscriptions {
40
40
  parentType
41
41
  }) {
42
42
  const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
43
- let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename);
43
+ let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename, false);
44
44
  for (const fieldSelection of Object.values(targetSelection || {})) {
45
45
  const {
46
46
  keyRaw,
@@ -57,7 +57,7 @@ class InMemorySubscriptions {
57
57
  let targetSelection2;
58
58
  if (innerSelection) {
59
59
  const __typename2 = this.cache._internal_unstable.storage.get(parent, "__typename").value;
60
- targetSelection2 = (0, import_selection.getFieldsForType)(innerSelection, __typename2);
60
+ targetSelection2 = (0, import_selection.getFieldsForType)(innerSelection, __typename2, false);
61
61
  }
62
62
  this.addFieldSubscription({
63
63
  id: parent,
@@ -168,7 +168,7 @@ class InMemorySubscriptions {
168
168
  filters
169
169
  } = selection;
170
170
  const key = (0, import_stuff.evaluateKey)(keyRaw, variables);
171
- const fieldSelection = innerSelection ? (0, import_selection.getFieldsForType)(innerSelection, parentType) : void 0;
171
+ const fieldSelection = innerSelection ? (0, import_selection.getFieldsForType)(innerSelection, parentType, false) : void 0;
172
172
  this.addFieldSubscription({
173
173
  id: parent,
174
174
  key,
@@ -198,7 +198,7 @@ class InMemorySubscriptions {
198
198
  linkedRecord,
199
199
  "__typename"
200
200
  ).value;
201
- let targetSelection2 = (0, import_selection.getFieldsForType)(childSelection, __typename);
201
+ let targetSelection2 = (0, import_selection.getFieldsForType)(childSelection, __typename, false);
202
202
  this.addMany({
203
203
  parent: linkedRecord,
204
204
  variables,
@@ -217,7 +217,7 @@ class InMemorySubscriptions {
217
217
  visited.push(id);
218
218
  const linkedIDs = [];
219
219
  const __typename = this.cache._internal_unstable.storage.get(id, "__typename").value;
220
- let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename);
220
+ let targetSelection = (0, import_selection.getFieldsForType)(selection, __typename, false);
221
221
  for (const fieldSelection of Object.values(targetSelection || {})) {
222
222
  const key = (0, import_stuff.evaluateKey)(fieldSelection.keyRaw, variables);
223
223
  this.removeSubscribers(id, key, targets);
@@ -5,6 +5,9 @@ import { Writable } from '../lib/store';
5
5
  import type { DocumentArtifact, QueryResult, GraphQLObject, SubscriptionSpec, CachePolicies } from '../lib/types';
6
6
  export declare class DocumentStore<_Data extends GraphQLObject, _Input extends Record<string, any>> 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[];