houdini 1.0.0-next.9 → 1.0.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 +4 -1
- package/build/cmd-cjs/index.js +2281 -105
- package/build/cmd-esm/index.js +2281 -105
- package/build/codegen/generators/runtime/runtimeConfig.d.ts +7 -0
- package/build/codegen/utils/flattenSelections.d.ts +1 -1
- package/build/codegen-cjs/index.js +2876 -674
- package/build/codegen-esm/index.js +2876 -674
- package/build/lib/config.d.ts +4 -6
- package/build/lib/types.d.ts +18 -15
- package/build/lib-cjs/index.js +3159 -171
- package/build/lib-esm/index.js +3152 -171
- package/build/runtime/cache/storage.d.ts +18 -15
- package/build/runtime/client/documentStore.d.ts +15 -13
- package/build/runtime/client/utils/documentPlugins.d.ts +2 -2
- package/build/runtime/imports/pluginConfig.d.ts +3 -0
- package/build/runtime/lib/config.d.ts +2 -2
- package/build/runtime/lib/scalars.d.ts +1 -1
- package/build/runtime/lib/types.d.ts +41 -42
- package/build/runtime-cjs/cache/storage.d.ts +18 -15
- package/build/runtime-cjs/cache/storage.js +9 -11
- package/build/runtime-cjs/client/documentStore.d.ts +15 -13
- package/build/runtime-cjs/client/documentStore.js +10 -7
- package/build/runtime-cjs/client/index.js +3 -0
- package/build/runtime-cjs/client/plugins/cache.js +3 -3
- package/build/runtime-cjs/client/plugins/fetch.js +2 -2
- package/build/runtime-cjs/client/plugins/query.js +1 -1
- package/build/runtime-cjs/client/plugins/subscription.js +2 -2
- package/build/runtime-cjs/client/utils/documentPlugins.d.ts +2 -2
- package/build/runtime-cjs/imports/pluginConfig.d.ts +3 -0
- package/build/runtime-cjs/imports/pluginConfig.js +27 -0
- package/build/runtime-cjs/lib/config.d.ts +2 -2
- package/build/runtime-cjs/lib/config.js +11 -1
- package/build/runtime-cjs/lib/scalars.d.ts +1 -1
- package/build/runtime-cjs/lib/scalars.js +13 -2
- package/build/runtime-cjs/lib/types.d.ts +41 -42
- package/build/runtime-cjs/lib/types.js +26 -30
- package/build/runtime-esm/cache/storage.d.ts +18 -15
- package/build/runtime-esm/cache/storage.js +9 -11
- package/build/runtime-esm/client/documentStore.d.ts +15 -13
- package/build/runtime-esm/client/documentStore.js +10 -7
- package/build/runtime-esm/client/index.js +5 -2
- package/build/runtime-esm/client/plugins/cache.js +3 -3
- package/build/runtime-esm/client/plugins/fetch.js +2 -2
- package/build/runtime-esm/client/plugins/query.js +1 -1
- package/build/runtime-esm/client/plugins/subscription.js +2 -2
- package/build/runtime-esm/client/utils/documentPlugins.d.ts +2 -2
- package/build/runtime-esm/imports/pluginConfig.d.ts +3 -0
- package/build/runtime-esm/imports/pluginConfig.js +5 -0
- package/build/runtime-esm/lib/config.d.ts +2 -2
- package/build/runtime-esm/lib/config.js +11 -1
- package/build/runtime-esm/lib/scalars.d.ts +1 -1
- package/build/runtime-esm/lib/scalars.js +13 -2
- package/build/runtime-esm/lib/types.d.ts +41 -42
- package/build/runtime-esm/lib/types.js +26 -30
- package/build/test-cjs/index.js +2258 -82
- package/build/test-esm/index.js +2258 -82
- package/build/vite/houdini.d.ts +2 -0
- package/build/vite-cjs/index.js +2284 -106
- package/build/vite-esm/index.js +2284 -106
- package/package.json +2 -2
|
@@ -7,7 +7,7 @@ export declare class InMemoryStorage {
|
|
|
7
7
|
get layerCount(): number;
|
|
8
8
|
get nextRank(): number;
|
|
9
9
|
createLayer(optimistic?: boolean): Layer;
|
|
10
|
-
insert(id: string, field: string, location:
|
|
10
|
+
insert(id: string, field: string, location: OperationLocations, target: string): void;
|
|
11
11
|
remove(id: string, field: string, target: string): void;
|
|
12
12
|
delete(id: string): void;
|
|
13
13
|
deleteField(id: string, field: string): void;
|
|
@@ -47,7 +47,7 @@ export declare class Layer {
|
|
|
47
47
|
removeUndefinedFields(): void;
|
|
48
48
|
delete(id: string): void;
|
|
49
49
|
deleteField(id: string, field: string): void;
|
|
50
|
-
insert(id: string, field: string, where:
|
|
50
|
+
insert(id: string, field: string, where: OperationLocations, target: string): void;
|
|
51
51
|
remove(id: string, field: string, target: string): void;
|
|
52
52
|
writeLayer(layer: Layer): void;
|
|
53
53
|
private addFieldOperation;
|
|
@@ -71,28 +71,31 @@ type OperationMap = {
|
|
|
71
71
|
};
|
|
72
72
|
type NestedList<_Result = string> = (_Result | null | NestedList<_Result>)[];
|
|
73
73
|
type InsertOperation = {
|
|
74
|
-
kind:
|
|
75
|
-
location:
|
|
74
|
+
kind: 'insert';
|
|
75
|
+
location: OperationLocations;
|
|
76
76
|
id: string;
|
|
77
77
|
};
|
|
78
78
|
type RemoveOperation = {
|
|
79
|
-
kind:
|
|
79
|
+
kind: 'remove';
|
|
80
80
|
id: string;
|
|
81
81
|
};
|
|
82
82
|
type DeleteOperation = {
|
|
83
|
-
kind:
|
|
83
|
+
kind: 'delete';
|
|
84
84
|
target: string;
|
|
85
85
|
};
|
|
86
86
|
type ListOperation = InsertOperation | RemoveOperation;
|
|
87
87
|
type Operation = ListOperation | DeleteOperation;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
type ValuesOf<Target> = Target[keyof Target];
|
|
89
|
+
export declare const OperationLocation: {
|
|
90
|
+
readonly start: "start";
|
|
91
|
+
readonly end: "end";
|
|
92
|
+
};
|
|
93
|
+
export type OperationLocations = ValuesOf<typeof OperationLocation>;
|
|
94
|
+
export declare const OperationKind: {
|
|
95
|
+
readonly delete: "delete";
|
|
96
|
+
readonly insert: "insert";
|
|
97
|
+
readonly remove: "remove";
|
|
98
|
+
};
|
|
99
|
+
export type OperationKinds = ValuesOf<typeof OperationKind>;
|
|
97
100
|
export type LayerID = number;
|
|
98
101
|
export {};
|
|
@@ -2,7 +2,7 @@ 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 {
|
|
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
8
|
constructor({ artifact, plugins, pipeline, client, cache, initialValue, fetching, }: {
|
|
@@ -14,16 +14,7 @@ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends R
|
|
|
14
14
|
initialValue?: _Data | null;
|
|
15
15
|
fetching?: boolean;
|
|
16
16
|
});
|
|
17
|
-
send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, }?:
|
|
18
|
-
fetch?: Fetch;
|
|
19
|
-
variables?: Record<string, any> | null;
|
|
20
|
-
metadata?: App.Metadata | null;
|
|
21
|
-
session?: App.Session | null;
|
|
22
|
-
policy?: CachePolicy;
|
|
23
|
-
stuff?: Partial<App.Stuff>;
|
|
24
|
-
cacheParams?: ClientPluginContext['cacheParams'];
|
|
25
|
-
setup?: boolean;
|
|
26
|
-
}): Promise<QueryResult<_Data, _Input>>;
|
|
17
|
+
send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, silenceEcho, }?: SendParams): Promise<QueryResult<_Data, _Input>>;
|
|
27
18
|
}
|
|
28
19
|
declare function marshalVariables<_Data extends GraphQLObject, _Input extends {}>(ctx: ClientPluginContext): Record<string, any>;
|
|
29
20
|
export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
|
|
@@ -42,9 +33,9 @@ export type ClientPluginContext = {
|
|
|
42
33
|
text: string;
|
|
43
34
|
hash: string;
|
|
44
35
|
artifact: DocumentArtifact;
|
|
45
|
-
policy?:
|
|
36
|
+
policy?: CachePolicies;
|
|
46
37
|
fetch?: Fetch;
|
|
47
|
-
variables?: Record<string, any
|
|
38
|
+
variables?: Record<string, any> | null;
|
|
48
39
|
metadata?: App.Metadata | null;
|
|
49
40
|
session?: App.Session | null;
|
|
50
41
|
fetchParams?: RequestInit;
|
|
@@ -85,4 +76,15 @@ export type ClientPluginExitHandlers = Omit<ClientPluginEnterHandlers, 'resolve'
|
|
|
85
76
|
export type ClientPluginErrorHandlers = ClientPluginEnterHandlers & {
|
|
86
77
|
error: unknown;
|
|
87
78
|
};
|
|
79
|
+
export type SendParams = {
|
|
80
|
+
fetch?: Fetch;
|
|
81
|
+
variables?: Record<string, any> | null;
|
|
82
|
+
metadata?: App.Metadata | null;
|
|
83
|
+
session?: App.Session | null;
|
|
84
|
+
policy?: CachePolicies;
|
|
85
|
+
stuff?: Partial<App.Stuff>;
|
|
86
|
+
cacheParams?: ClientPluginContext['cacheParams'];
|
|
87
|
+
setup?: boolean;
|
|
88
|
+
silenceEcho?: boolean;
|
|
89
|
+
};
|
|
88
90
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ArtifactKinds } from '../../lib/types';
|
|
2
2
|
import type { ClientPlugin, ClientHooks } from '../documentStore';
|
|
3
|
-
export declare const documentPlugin: (kind:
|
|
3
|
+
export declare const documentPlugin: (kind: ArtifactKinds, source: () => ClientHooks) => ClientPlugin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GraphQLSchema } from 'graphql';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CachePolicies } from './types';
|
|
3
3
|
export declare function getMockConfig(): ConfigFile | null;
|
|
4
4
|
export declare function setMockConfig(config: ConfigFile | null): void;
|
|
5
5
|
export declare function defaultConfigValues(file: ConfigFile): ConfigFile;
|
|
@@ -50,7 +50,7 @@ export type ConfigFile = {
|
|
|
50
50
|
/**
|
|
51
51
|
* The default cache policy to use for queries. For more information: https://www.houdinigraphql.com/guides/caching-data
|
|
52
52
|
*/
|
|
53
|
-
defaultCachePolicy?:
|
|
53
|
+
defaultCachePolicy?: CachePolicies;
|
|
54
54
|
/**
|
|
55
55
|
* Specifies whether or not the cache should always use partial data. For more information: https://www.houdinigraphql.com/guides/caching-data#partial-data
|
|
56
56
|
*/
|
|
@@ -12,4 +12,4 @@ export declare function marshalInputs<T>({ artifact, input, config, rootType, }:
|
|
|
12
12
|
}): {} | null | undefined;
|
|
13
13
|
export declare function unmarshalSelection(config: ConfigFile, selection: SubscriptionSelection, data: any): {} | null | undefined;
|
|
14
14
|
export declare function isScalar(config: ConfigFile, type: string): boolean;
|
|
15
|
-
export declare function parseScalar(config: ConfigFile, type: string, value
|
|
15
|
+
export declare function parseScalar(config: ConfigFile, type: string, value?: string): string | number | boolean | undefined;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
CacheOrNetwork
|
|
3
|
-
CacheOnly
|
|
4
|
-
NetworkOnly
|
|
5
|
-
CacheAndNetwork
|
|
6
|
-
}
|
|
1
|
+
export declare const CachePolicy: {
|
|
2
|
+
readonly CacheOrNetwork: "CacheOrNetwork";
|
|
3
|
+
readonly CacheOnly: "CacheOnly";
|
|
4
|
+
readonly NetworkOnly: "NetworkOnly";
|
|
5
|
+
readonly CacheAndNetwork: "CacheAndNetwork";
|
|
6
|
+
};
|
|
7
|
+
type ValuesOf<Target> = Target[keyof Target];
|
|
8
|
+
export type CachePolicies = ValuesOf<typeof CachePolicy>;
|
|
7
9
|
declare global {
|
|
8
10
|
namespace App {
|
|
9
11
|
interface Session {
|
|
@@ -29,42 +31,38 @@ export type Operation<_Result, _Input> = {
|
|
|
29
31
|
};
|
|
30
32
|
export type Maybe<T> = T | null | undefined;
|
|
31
33
|
export type DocumentArtifact = FragmentArtifact | QueryArtifact | MutationArtifact | SubscriptionArtifact;
|
|
32
|
-
export declare
|
|
33
|
-
Query
|
|
34
|
-
Subscription
|
|
35
|
-
Mutation
|
|
36
|
-
Fragment
|
|
37
|
-
}
|
|
38
|
-
export
|
|
39
|
-
export declare const
|
|
40
|
-
export declare const
|
|
41
|
-
export declare const
|
|
42
|
-
export
|
|
43
|
-
export type
|
|
44
|
-
|
|
45
|
-
policy?:
|
|
34
|
+
export declare const ArtifactKind: {
|
|
35
|
+
readonly Query: "HoudiniQuery";
|
|
36
|
+
readonly Subscription: "HoudiniSubscription";
|
|
37
|
+
readonly Mutation: "HoudiniMutation";
|
|
38
|
+
readonly Fragment: "HoudiniFragment";
|
|
39
|
+
};
|
|
40
|
+
export type ArtifactKinds = ValuesOf<typeof ArtifactKind>;
|
|
41
|
+
export declare const CompiledFragmentKind: "HoudiniFragment";
|
|
42
|
+
export declare const CompiledMutationKind: "HoudiniMutation";
|
|
43
|
+
export declare const CompiledQueryKind: "HoudiniQuery";
|
|
44
|
+
export declare const CompiledSubscriptionKind: "HoudiniSubscription";
|
|
45
|
+
export type CompiledDocumentKind = ArtifactKinds;
|
|
46
|
+
export type QueryArtifact = BaseCompiledDocument<'HoudiniQuery'> & {
|
|
47
|
+
policy?: CachePolicies;
|
|
46
48
|
partial?: boolean;
|
|
47
49
|
};
|
|
48
|
-
export type MutationArtifact = BaseCompiledDocument
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
kind: ArtifactKind.Subscription;
|
|
50
|
+
export type MutationArtifact = BaseCompiledDocument<'HoudiniMutation'>;
|
|
51
|
+
export type FragmentArtifact = BaseCompiledDocument<'HoudiniFragment'>;
|
|
52
|
+
export type SubscriptionArtifact = BaseCompiledDocument<'HoudiniSubscription'>;
|
|
53
|
+
export declare const RefetchUpdateMode: {
|
|
54
|
+
readonly append: "append";
|
|
55
|
+
readonly prepend: "prepend";
|
|
56
|
+
readonly replace: "replace";
|
|
56
57
|
};
|
|
57
|
-
export
|
|
58
|
-
append = "append",
|
|
59
|
-
prepend = "prepend",
|
|
60
|
-
replace = "replace"
|
|
61
|
-
}
|
|
58
|
+
export type RefetchUpdateModes = ValuesOf<typeof RefetchUpdateMode>;
|
|
62
59
|
export type InputObject = {
|
|
63
60
|
fields: Record<string, string>;
|
|
64
61
|
types: Record<string, Record<string, string>>;
|
|
65
62
|
};
|
|
66
|
-
export type BaseCompiledDocument = {
|
|
63
|
+
export type BaseCompiledDocument<_Kind extends ArtifactKinds> = {
|
|
67
64
|
name: string;
|
|
65
|
+
kind: _Kind;
|
|
68
66
|
raw: string;
|
|
69
67
|
hash: string;
|
|
70
68
|
selection: SubscriptionSelection;
|
|
@@ -80,7 +78,7 @@ export type BaseCompiledDocument = {
|
|
|
80
78
|
paginated: boolean;
|
|
81
79
|
direction: 'forward' | 'backward' | 'both';
|
|
82
80
|
};
|
|
83
|
-
|
|
81
|
+
pluginData?: Record<string, any>;
|
|
84
82
|
};
|
|
85
83
|
export type HoudiniFetchContext = {
|
|
86
84
|
variables: () => {};
|
|
@@ -92,20 +90,21 @@ export type ListWhen = {
|
|
|
92
90
|
must?: Filter;
|
|
93
91
|
must_not?: Filter;
|
|
94
92
|
};
|
|
95
|
-
export declare
|
|
93
|
+
export declare const DataSource: {
|
|
96
94
|
/**
|
|
97
95
|
* from the browser cache
|
|
98
96
|
*/
|
|
99
|
-
Cache
|
|
97
|
+
readonly Cache: "cache";
|
|
100
98
|
/**
|
|
101
99
|
* from a browser side `fetch`
|
|
102
100
|
*/
|
|
103
|
-
Network
|
|
101
|
+
readonly Network: "network";
|
|
104
102
|
/**
|
|
105
103
|
* from a server side `fetch`
|
|
106
104
|
*/
|
|
107
|
-
Ssr
|
|
108
|
-
}
|
|
105
|
+
readonly Ssr: "ssr";
|
|
106
|
+
};
|
|
107
|
+
export type DataSources = ValuesOf<typeof DataSource>;
|
|
109
108
|
export type MutationOperation = {
|
|
110
109
|
action: 'insert' | 'remove' | 'delete' | 'toggle';
|
|
111
110
|
list?: string;
|
|
@@ -163,7 +162,7 @@ export type SubscriptionSpec = {
|
|
|
163
162
|
};
|
|
164
163
|
export type FetchQueryResult<_Data> = {
|
|
165
164
|
result: RequestPayload<_Data | null>;
|
|
166
|
-
source:
|
|
165
|
+
source: DataSources | null;
|
|
167
166
|
};
|
|
168
167
|
export type QueryResult<_Data = GraphQLObject, _Input = Record<string, any>> = {
|
|
169
168
|
data: _Data | null;
|
|
@@ -173,7 +172,7 @@ export type QueryResult<_Data = GraphQLObject, _Input = Record<string, any>> = {
|
|
|
173
172
|
fetching: boolean;
|
|
174
173
|
partial: boolean;
|
|
175
174
|
stale: boolean;
|
|
176
|
-
source:
|
|
175
|
+
source: DataSources | null;
|
|
177
176
|
variables: _Input | null;
|
|
178
177
|
};
|
|
179
178
|
export type RequestPayload<GraphQLObject = any> = {
|
|
@@ -7,7 +7,7 @@ export declare class InMemoryStorage {
|
|
|
7
7
|
get layerCount(): number;
|
|
8
8
|
get nextRank(): number;
|
|
9
9
|
createLayer(optimistic?: boolean): Layer;
|
|
10
|
-
insert(id: string, field: string, location:
|
|
10
|
+
insert(id: string, field: string, location: OperationLocations, target: string): void;
|
|
11
11
|
remove(id: string, field: string, target: string): void;
|
|
12
12
|
delete(id: string): void;
|
|
13
13
|
deleteField(id: string, field: string): void;
|
|
@@ -47,7 +47,7 @@ export declare class Layer {
|
|
|
47
47
|
removeUndefinedFields(): void;
|
|
48
48
|
delete(id: string): void;
|
|
49
49
|
deleteField(id: string, field: string): void;
|
|
50
|
-
insert(id: string, field: string, where:
|
|
50
|
+
insert(id: string, field: string, where: OperationLocations, target: string): void;
|
|
51
51
|
remove(id: string, field: string, target: string): void;
|
|
52
52
|
writeLayer(layer: Layer): void;
|
|
53
53
|
private addFieldOperation;
|
|
@@ -71,28 +71,31 @@ type OperationMap = {
|
|
|
71
71
|
};
|
|
72
72
|
type NestedList<_Result = string> = (_Result | null | NestedList<_Result>)[];
|
|
73
73
|
type InsertOperation = {
|
|
74
|
-
kind:
|
|
75
|
-
location:
|
|
74
|
+
kind: 'insert';
|
|
75
|
+
location: OperationLocations;
|
|
76
76
|
id: string;
|
|
77
77
|
};
|
|
78
78
|
type RemoveOperation = {
|
|
79
|
-
kind:
|
|
79
|
+
kind: 'remove';
|
|
80
80
|
id: string;
|
|
81
81
|
};
|
|
82
82
|
type DeleteOperation = {
|
|
83
|
-
kind:
|
|
83
|
+
kind: 'delete';
|
|
84
84
|
target: string;
|
|
85
85
|
};
|
|
86
86
|
type ListOperation = InsertOperation | RemoveOperation;
|
|
87
87
|
type Operation = ListOperation | DeleteOperation;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
type ValuesOf<Target> = Target[keyof Target];
|
|
89
|
+
export declare const OperationLocation: {
|
|
90
|
+
readonly start: "start";
|
|
91
|
+
readonly end: "end";
|
|
92
|
+
};
|
|
93
|
+
export type OperationLocations = ValuesOf<typeof OperationLocation>;
|
|
94
|
+
export declare const OperationKind: {
|
|
95
|
+
readonly delete: "delete";
|
|
96
|
+
readonly insert: "insert";
|
|
97
|
+
readonly remove: "remove";
|
|
98
|
+
};
|
|
99
|
+
export type OperationKinds = ValuesOf<typeof OperationKind>;
|
|
97
100
|
export type LayerID = number;
|
|
98
101
|
export {};
|
|
@@ -376,17 +376,15 @@ function isInsertOperation(value) {
|
|
|
376
376
|
function isRemoveOperation(value) {
|
|
377
377
|
return !!value && value.kind === OperationKind.remove;
|
|
378
378
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
return OperationKind2;
|
|
389
|
-
})(OperationKind || {});
|
|
379
|
+
const OperationLocation = {
|
|
380
|
+
start: "start",
|
|
381
|
+
end: "end"
|
|
382
|
+
};
|
|
383
|
+
const OperationKind = {
|
|
384
|
+
delete: "delete",
|
|
385
|
+
insert: "insert",
|
|
386
|
+
remove: "remove"
|
|
387
|
+
};
|
|
390
388
|
// Annotate the CommonJS export names for ESM import in node:
|
|
391
389
|
0 && (module.exports = {
|
|
392
390
|
InMemoryStorage,
|
|
@@ -2,7 +2,7 @@ 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 {
|
|
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
8
|
constructor({ artifact, plugins, pipeline, client, cache, initialValue, fetching, }: {
|
|
@@ -14,16 +14,7 @@ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends R
|
|
|
14
14
|
initialValue?: _Data | null;
|
|
15
15
|
fetching?: boolean;
|
|
16
16
|
});
|
|
17
|
-
send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, }?:
|
|
18
|
-
fetch?: Fetch;
|
|
19
|
-
variables?: Record<string, any> | null;
|
|
20
|
-
metadata?: App.Metadata | null;
|
|
21
|
-
session?: App.Session | null;
|
|
22
|
-
policy?: CachePolicy;
|
|
23
|
-
stuff?: Partial<App.Stuff>;
|
|
24
|
-
cacheParams?: ClientPluginContext['cacheParams'];
|
|
25
|
-
setup?: boolean;
|
|
26
|
-
}): Promise<QueryResult<_Data, _Input>>;
|
|
17
|
+
send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, silenceEcho, }?: SendParams): Promise<QueryResult<_Data, _Input>>;
|
|
27
18
|
}
|
|
28
19
|
declare function marshalVariables<_Data extends GraphQLObject, _Input extends {}>(ctx: ClientPluginContext): Record<string, any>;
|
|
29
20
|
export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
|
|
@@ -42,9 +33,9 @@ export type ClientPluginContext = {
|
|
|
42
33
|
text: string;
|
|
43
34
|
hash: string;
|
|
44
35
|
artifact: DocumentArtifact;
|
|
45
|
-
policy?:
|
|
36
|
+
policy?: CachePolicies;
|
|
46
37
|
fetch?: Fetch;
|
|
47
|
-
variables?: Record<string, any
|
|
38
|
+
variables?: Record<string, any> | null;
|
|
48
39
|
metadata?: App.Metadata | null;
|
|
49
40
|
session?: App.Session | null;
|
|
50
41
|
fetchParams?: RequestInit;
|
|
@@ -85,4 +76,15 @@ export type ClientPluginExitHandlers = Omit<ClientPluginEnterHandlers, 'resolve'
|
|
|
85
76
|
export type ClientPluginErrorHandlers = ClientPluginEnterHandlers & {
|
|
86
77
|
error: unknown;
|
|
87
78
|
};
|
|
79
|
+
export type SendParams = {
|
|
80
|
+
fetch?: Fetch;
|
|
81
|
+
variables?: Record<string, any> | null;
|
|
82
|
+
metadata?: App.Metadata | null;
|
|
83
|
+
session?: App.Session | null;
|
|
84
|
+
policy?: CachePolicies;
|
|
85
|
+
stuff?: Partial<App.Stuff>;
|
|
86
|
+
cacheParams?: ClientPluginContext['cacheParams'];
|
|
87
|
+
setup?: boolean;
|
|
88
|
+
silenceEcho?: boolean;
|
|
89
|
+
};
|
|
88
90
|
export {};
|
|
@@ -47,9 +47,7 @@ class DocumentStore extends import_store.Writable {
|
|
|
47
47
|
initialValue,
|
|
48
48
|
fetching
|
|
49
49
|
}) {
|
|
50
|
-
|
|
51
|
-
fetching = artifact.kind === import_types.ArtifactKind.Query;
|
|
52
|
-
}
|
|
50
|
+
fetching ??= artifact.kind === import_types.ArtifactKind.Query;
|
|
53
51
|
const initialState = {
|
|
54
52
|
data: initialValue ?? null,
|
|
55
53
|
errors: null,
|
|
@@ -87,14 +85,15 @@ class DocumentStore extends import_store.Writable {
|
|
|
87
85
|
policy,
|
|
88
86
|
stuff,
|
|
89
87
|
cacheParams,
|
|
90
|
-
setup = false
|
|
88
|
+
setup = false,
|
|
89
|
+
silenceEcho = false
|
|
91
90
|
} = {}) {
|
|
92
91
|
let context = new ClientPluginContextWrapper({
|
|
93
92
|
config: this.#configFile,
|
|
94
93
|
text: this.#artifact.raw,
|
|
95
94
|
hash: this.#artifact.hash,
|
|
96
95
|
policy: policy ?? this.#artifact.policy,
|
|
97
|
-
variables:
|
|
96
|
+
variables: null,
|
|
98
97
|
metadata,
|
|
99
98
|
session,
|
|
100
99
|
fetch,
|
|
@@ -111,13 +110,14 @@ class DocumentStore extends import_store.Writable {
|
|
|
111
110
|
cacheParams
|
|
112
111
|
});
|
|
113
112
|
const draft = context.draft();
|
|
114
|
-
draft.variables = variables ??
|
|
113
|
+
draft.variables = variables ?? null;
|
|
115
114
|
context = context.apply(draft, false);
|
|
116
115
|
return await new Promise((resolve, reject) => {
|
|
117
116
|
const state = {
|
|
118
117
|
setup,
|
|
119
118
|
currentStep: 0,
|
|
120
119
|
index: 0,
|
|
120
|
+
silenceEcho,
|
|
121
121
|
promise: {
|
|
122
122
|
resolved: false,
|
|
123
123
|
resolve,
|
|
@@ -255,6 +255,9 @@ class DocumentStore extends import_store.Writable {
|
|
|
255
255
|
}
|
|
256
256
|
this.#lastContext = ctx.context.draft();
|
|
257
257
|
this.#lastVariables = this.#lastContext.stuff.inputs.marshaled;
|
|
258
|
+
if (ctx.silenceEcho && finalValue.data === this.state.data) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
258
261
|
this.set(finalValue);
|
|
259
262
|
}
|
|
260
263
|
}
|
|
@@ -285,7 +288,7 @@ class ClientPluginContextWrapper {
|
|
|
285
288
|
ctx.stuff = val;
|
|
286
289
|
},
|
|
287
290
|
get variables() {
|
|
288
|
-
return ctx.variables ??
|
|
291
|
+
return ctx.variables ?? null;
|
|
289
292
|
},
|
|
290
293
|
set variables(val) {
|
|
291
294
|
Object.assign(ctx, applyVariables(ctx, { variables: val }));
|
|
@@ -82,6 +82,9 @@ class HoudiniClient {
|
|
|
82
82
|
}
|
|
83
83
|
function createPluginHooks(plugins) {
|
|
84
84
|
return plugins.reduce((hooks, plugin) => {
|
|
85
|
+
if (typeof plugin !== "function") {
|
|
86
|
+
throw new Error("Encountered client plugin that's not a function");
|
|
87
|
+
}
|
|
85
88
|
const result = plugin();
|
|
86
89
|
if (!result) {
|
|
87
90
|
return hooks;
|
|
@@ -35,7 +35,7 @@ const cachePolicy = ({
|
|
|
35
35
|
cache: localCache = import_cache.default
|
|
36
36
|
}) => () => {
|
|
37
37
|
return {
|
|
38
|
-
network(ctx, { next, resolve, marshalVariables }) {
|
|
38
|
+
network(ctx, { initialValue, next, resolve, marshalVariables }) {
|
|
39
39
|
const { policy, artifact } = ctx;
|
|
40
40
|
let useCache = false;
|
|
41
41
|
if (enabled && artifact.kind === import_types.ArtifactKind.Query && !ctx.cacheParams?.disableRead) {
|
|
@@ -49,10 +49,10 @@ const cachePolicy = ({
|
|
|
49
49
|
return resolve(ctx, {
|
|
50
50
|
fetching: false,
|
|
51
51
|
variables: ctx.variables ?? null,
|
|
52
|
-
data: value.data,
|
|
52
|
+
data: allowed ? value.data : initialValue.data,
|
|
53
53
|
errors: null,
|
|
54
54
|
source: import_types.DataSource.Cache,
|
|
55
|
-
partial: value.partial,
|
|
55
|
+
partial: allowed ? value.partial : false,
|
|
56
56
|
stale: value.stale
|
|
57
57
|
});
|
|
58
58
|
}
|
|
@@ -53,7 +53,7 @@ const fetch = (target) => {
|
|
|
53
53
|
});
|
|
54
54
|
resolve(ctx, {
|
|
55
55
|
fetching: false,
|
|
56
|
-
variables: ctx.variables ??
|
|
56
|
+
variables: ctx.variables ?? {},
|
|
57
57
|
data: result.data,
|
|
58
58
|
errors: !result.errors || result.errors.length === 0 ? null : result.errors,
|
|
59
59
|
partial: false,
|
|
@@ -67,7 +67,7 @@ const fetch = (target) => {
|
|
|
67
67
|
const defaultFetch = (url, params) => {
|
|
68
68
|
if (!url) {
|
|
69
69
|
throw new Error(
|
|
70
|
-
"Could not find configured client url. Please specify one in your
|
|
70
|
+
"Could not find configured client url. Please specify one in your HoudiniClient constructor."
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
return async ({ fetch: fetch2, text, variables }) => {
|
|
@@ -68,7 +68,7 @@ function subscription(factory) {
|
|
|
68
68
|
partial: true,
|
|
69
69
|
stale: false,
|
|
70
70
|
source: import_types.DataSource.Network,
|
|
71
|
-
variables: ctx.variables ??
|
|
71
|
+
variables: ctx.variables ?? {}
|
|
72
72
|
});
|
|
73
73
|
},
|
|
74
74
|
error(data) {
|
|
@@ -80,7 +80,7 @@ function subscription(factory) {
|
|
|
80
80
|
data: null,
|
|
81
81
|
errors: [data],
|
|
82
82
|
fetching: false,
|
|
83
|
-
variables: ctx.variables ??
|
|
83
|
+
variables: ctx.variables ?? {}
|
|
84
84
|
});
|
|
85
85
|
},
|
|
86
86
|
complete() {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ArtifactKinds } from '../../lib/types';
|
|
2
2
|
import type { ClientPlugin, ClientHooks } from '../documentStore';
|
|
3
|
-
export declare const documentPlugin: (kind:
|
|
3
|
+
export declare const documentPlugin: (kind: ArtifactKinds, source: () => ClientHooks) => ClientPlugin;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var pluginConfig_exports = {};
|
|
20
|
+
__export(pluginConfig_exports, {
|
|
21
|
+
default: () => pluginConfig_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(pluginConfig_exports);
|
|
24
|
+
const configs = [];
|
|
25
|
+
var pluginConfig_default = configs;
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GraphQLSchema } from 'graphql';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CachePolicies } from './types';
|
|
3
3
|
export declare function getMockConfig(): ConfigFile | null;
|
|
4
4
|
export declare function setMockConfig(config: ConfigFile | null): void;
|
|
5
5
|
export declare function defaultConfigValues(file: ConfigFile): ConfigFile;
|
|
@@ -50,7 +50,7 @@ export type ConfigFile = {
|
|
|
50
50
|
/**
|
|
51
51
|
* The default cache policy to use for queries. For more information: https://www.houdinigraphql.com/guides/caching-data
|
|
52
52
|
*/
|
|
53
|
-
defaultCachePolicy?:
|
|
53
|
+
defaultCachePolicy?: CachePolicies;
|
|
54
54
|
/**
|
|
55
55
|
* Specifies whether or not the cache should always use partial data. For more information: https://www.houdinigraphql.com/guides/caching-data#partial-data
|
|
56
56
|
*/
|