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
|
@@ -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);
|
|
@@ -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;
|
|
@@ -71,7 +71,15 @@ class DocumentStore extends import_store.Writable {
|
|
|
71
71
|
this.#plugins = pipeline ?? [
|
|
72
72
|
(0, import_plugins.cachePolicy)({
|
|
73
73
|
enabled: cache,
|
|
74
|
-
setFetching: (fetching2
|
|
74
|
+
setFetching: (fetching2, data) => {
|
|
75
|
+
this.update((state) => {
|
|
76
|
+
const newState = { ...state, fetching: fetching2 };
|
|
77
|
+
if (fetching2 && data) {
|
|
78
|
+
newState.data = data;
|
|
79
|
+
}
|
|
80
|
+
return newState;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
75
83
|
})(),
|
|
76
84
|
...plugins ?? []
|
|
77
85
|
];
|
|
@@ -315,7 +323,7 @@ class ClientPluginContextWrapper {
|
|
|
315
323
|
};
|
|
316
324
|
const firstInit = !ctx.stuff.inputs || !ctx.stuff.inputs.init;
|
|
317
325
|
const hasChanged = Object.keys(changed).length > 0 || firstInit;
|
|
318
|
-
if (
|
|
326
|
+
if (hasChanged) {
|
|
319
327
|
const newVariables = {
|
|
320
328
|
...ctx.stuff.inputs?.marshaled,
|
|
321
329
|
...(0, import_scalars.marshalInputs)({
|
|
@@ -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[];
|
|
@@ -41,14 +41,22 @@ var import_documentStore2 = require("./documentStore");
|
|
|
41
41
|
var import_plugins2 = require("./plugins");
|
|
42
42
|
class HoudiniClient {
|
|
43
43
|
url;
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
plugins;
|
|
45
|
+
throwOnError_operations;
|
|
46
|
+
constructor({
|
|
47
|
+
url,
|
|
48
|
+
fetchParams,
|
|
49
|
+
plugins,
|
|
50
|
+
pipeline,
|
|
51
|
+
throwOnError
|
|
52
|
+
}) {
|
|
46
53
|
if (plugins && pipeline) {
|
|
47
54
|
throw new Error(
|
|
48
55
|
"A client cannot be given a pipeline and a list of plugins at the same time."
|
|
49
56
|
);
|
|
50
57
|
}
|
|
51
|
-
this
|
|
58
|
+
this.throwOnError_operations = throwOnError?.operations ?? [];
|
|
59
|
+
this.plugins = (0, import_flatten.flatten)(
|
|
52
60
|
[].concat(
|
|
53
61
|
throwOnError ? [(0, import_plugins.throwOnError)(throwOnError)] : [],
|
|
54
62
|
(0, import_plugins.fetchParams)(fetchParams),
|
|
@@ -74,7 +82,7 @@ class HoudiniClient {
|
|
|
74
82
|
return new import_documentStore.DocumentStore({
|
|
75
83
|
client: this,
|
|
76
84
|
artifact,
|
|
77
|
-
plugins: createPluginHooks(this
|
|
85
|
+
plugins: createPluginHooks(this.plugins),
|
|
78
86
|
cache,
|
|
79
87
|
initialValue,
|
|
80
88
|
fetching
|
|
@@ -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;
|
|
@@ -46,7 +46,7 @@ const cachePolicy = ({
|
|
|
46
46
|
const value = localCache.read({
|
|
47
47
|
selection: artifact.selection,
|
|
48
48
|
variables: marshalVariables(ctx),
|
|
49
|
-
|
|
49
|
+
fullCheck: true
|
|
50
50
|
});
|
|
51
51
|
const allowed = !value.partial || artifact.kind === import_types.ArtifactKind.Query && artifact.partial;
|
|
52
52
|
if (policy === import_types.CachePolicy.CacheOnly) {
|
|
@@ -83,7 +83,15 @@ const cachePolicy = ({
|
|
|
83
83
|
}, 0);
|
|
84
84
|
}
|
|
85
85
|
if (!ctx.stuff?.silenceLoading) {
|
|
86
|
-
|
|
86
|
+
let fetchingState = null;
|
|
87
|
+
if (!useCache && "enableLoadingState" in artifact && artifact.enableLoadingState) {
|
|
88
|
+
fetchingState = localCache.read({
|
|
89
|
+
selection: artifact.selection,
|
|
90
|
+
variables: marshalVariables(ctx),
|
|
91
|
+
loading: true
|
|
92
|
+
}).data;
|
|
93
|
+
}
|
|
94
|
+
setFetching(!useCache, fetchingState);
|
|
87
95
|
}
|
|
88
96
|
return next(ctx);
|
|
89
97
|
},
|
|
@@ -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: {
|
|
@@ -33,6 +33,7 @@ const fetch = (target) => {
|
|
|
33
33
|
}
|
|
34
34
|
const fetch2 = ctx.fetch ?? globalThis.fetch;
|
|
35
35
|
const fetchParams = {
|
|
36
|
+
name: ctx.artifact.name,
|
|
36
37
|
text: ctx.text,
|
|
37
38
|
hash: ctx.hash,
|
|
38
39
|
variables: marshalVariables(ctx)
|
|
@@ -73,10 +74,10 @@ const defaultFetch = (url, params) => {
|
|
|
73
74
|
"Could not find configured client url. Please specify one in your HoudiniClient constructor."
|
|
74
75
|
);
|
|
75
76
|
}
|
|
76
|
-
return async ({ fetch: fetch2, text, variables }) => {
|
|
77
|
+
return async ({ fetch: fetch2, name, text, variables }) => {
|
|
77
78
|
const result = await fetch2(url, {
|
|
78
79
|
method: "POST",
|
|
79
|
-
body: JSON.stringify({ query: text, variables }),
|
|
80
|
+
body: JSON.stringify({ operationName: name, query: text, variables }),
|
|
80
81
|
...params,
|
|
81
82
|
headers: {
|
|
82
83
|
Accept: "application/graphql+json, application/json",
|
|
@@ -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;
|
|
@@ -58,7 +58,8 @@ function defaultConfigValues(file) {
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
function keyFieldsForType(configFile, type) {
|
|
61
|
-
|
|
61
|
+
const withDefault = defaultConfigValues(configFile);
|
|
62
|
+
return withDefault.types?.[type]?.keys || withDefault.defaultKeys;
|
|
62
63
|
}
|
|
63
64
|
function computeID(configFile, type, data) {
|
|
64
65
|
const fields = keyFieldsForType(configFile, type);
|
|
@@ -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>>;
|
|
@@ -23,13 +23,11 @@ __export(pagination_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(pagination_exports);
|
|
25
25
|
var import_config = require("./config");
|
|
26
|
-
var import_constants = require("./constants");
|
|
27
26
|
var import_deepEquals = require("./deepEquals");
|
|
28
27
|
var import_pageInfo = require("./pageInfo");
|
|
29
28
|
var import_types = require("./types");
|
|
30
29
|
function cursorHandlers({
|
|
31
30
|
artifact,
|
|
32
|
-
storeName,
|
|
33
31
|
fetchUpdate: parentFetchUpdate,
|
|
34
32
|
fetch: parentFetch,
|
|
35
33
|
getState,
|
|
@@ -63,16 +61,6 @@ function cursorHandlers({
|
|
|
63
61
|
},
|
|
64
62
|
isSinglePage ? [] : [where === "start" ? "prepend" : "append"]
|
|
65
63
|
);
|
|
66
|
-
const resultPath = [...artifact.refetch.path];
|
|
67
|
-
if (artifact.refetch.embedded) {
|
|
68
|
-
const { targetType } = artifact.refetch;
|
|
69
|
-
if (!config.types?.[targetType]?.resolve) {
|
|
70
|
-
throw new Error(
|
|
71
|
-
`Missing type resolve configuration for ${targetType}. For more information, see ${import_constants.siteURL}/guides/pagination#paginated-fragments`
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
resultPath.unshift(config.types[targetType].resolve.queryField);
|
|
75
|
-
}
|
|
76
64
|
};
|
|
77
65
|
const getPageInfo = () => {
|
|
78
66
|
return (0, import_pageInfo.extractPageInfo)(getState(), artifact.refetch?.path ?? []);
|
|
@@ -37,7 +37,7 @@ async function marshalSelection({
|
|
|
37
37
|
if (Array.isArray(data)) {
|
|
38
38
|
return await Promise.all(data.map((val) => marshalSelection({ selection, data: val })));
|
|
39
39
|
}
|
|
40
|
-
const targetSelection = (0, import_selection.getFieldsForType)(selection, data["__typename"]);
|
|
40
|
+
const targetSelection = (0, import_selection.getFieldsForType)(selection, data["__typename"], false);
|
|
41
41
|
return Object.fromEntries(
|
|
42
42
|
await Promise.all(
|
|
43
43
|
Object.entries(data).map(async ([fieldName, value]) => {
|
|
@@ -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'];
|
|
@@ -21,7 +21,15 @@ __export(selection_exports, {
|
|
|
21
21
|
getFieldsForType: () => getFieldsForType
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(selection_exports);
|
|
24
|
-
function getFieldsForType(selection, __typename) {
|
|
24
|
+
function getFieldsForType(selection, __typename, loading) {
|
|
25
|
+
if (loading) {
|
|
26
|
+
if (selection.loadingTypes && selection.loadingTypes.length > 0) {
|
|
27
|
+
return deepMerge(
|
|
28
|
+
...selection.loadingTypes.map((type) => selection.abstractFields?.fields[type])
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return selection.fields ?? {};
|
|
32
|
+
}
|
|
25
33
|
let targetSelection = selection.fields || {};
|
|
26
34
|
if (selection.abstractFields && __typename) {
|
|
27
35
|
const mappedType = selection.abstractFields.typeMap[__typename];
|
|
@@ -33,6 +41,25 @@ function getFieldsForType(selection, __typename) {
|
|
|
33
41
|
}
|
|
34
42
|
return targetSelection;
|
|
35
43
|
}
|
|
44
|
+
function deepMerge(...objects) {
|
|
45
|
+
const mergedObj = {};
|
|
46
|
+
for (let obj of objects) {
|
|
47
|
+
if (!obj) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
for (let prop in obj) {
|
|
51
|
+
if (prop in obj) {
|
|
52
|
+
const val = obj[prop];
|
|
53
|
+
if (typeof val === "object" && val !== null && !Array.isArray(val)) {
|
|
54
|
+
mergedObj[prop] = deepMerge(mergedObj[prop] || {}, val);
|
|
55
|
+
} else {
|
|
56
|
+
mergedObj[prop] = val;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return mergedObj;
|
|
62
|
+
}
|
|
36
63
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
64
|
0 && (module.exports = {
|
|
38
65
|
getFieldsForType
|
|
@@ -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 {};
|
|
@@ -26,6 +26,7 @@ __export(types_exports, {
|
|
|
26
26
|
CompiledSubscriptionKind: () => CompiledSubscriptionKind,
|
|
27
27
|
DataSource: () => DataSource,
|
|
28
28
|
PaginateMode: () => PaginateMode,
|
|
29
|
+
PendingValue: () => PendingValue,
|
|
29
30
|
RefetchUpdateMode: () => RefetchUpdateMode,
|
|
30
31
|
fragmentKey: () => fragmentKey
|
|
31
32
|
});
|
|
@@ -61,6 +62,7 @@ const DataSource = {
|
|
|
61
62
|
Ssr: "ssr"
|
|
62
63
|
};
|
|
63
64
|
const fragmentKey = " $fragments";
|
|
65
|
+
const PendingValue = Symbol("houdini_loading");
|
|
64
66
|
// Annotate the CommonJS export names for ESM import in node:
|
|
65
67
|
0 && (module.exports = {
|
|
66
68
|
ArtifactKind,
|
|
@@ -71,6 +73,7 @@ const fragmentKey = " $fragments";
|
|
|
71
73
|
CompiledSubscriptionKind,
|
|
72
74
|
DataSource,
|
|
73
75
|
PaginateMode,
|
|
76
|
+
PendingValue,
|
|
74
77
|
RefetchUpdateMode,
|
|
75
78
|
fragmentKey
|
|
76
79
|
});
|
|
@@ -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;
|