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
|
@@ -33,6 +33,7 @@ __export(config_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(config_exports);
|
|
35
35
|
var import_config = __toESM(require("../imports/config"), 1);
|
|
36
|
+
var import_pluginConfig = __toESM(require("../imports/pluginConfig"), 1);
|
|
36
37
|
let mockConfig = null;
|
|
37
38
|
function getMockConfig() {
|
|
38
39
|
return mockConfig;
|
|
@@ -67,12 +68,21 @@ function computeID(configFile, type, data) {
|
|
|
67
68
|
}
|
|
68
69
|
return id.slice(0, -2);
|
|
69
70
|
}
|
|
71
|
+
let _configFile = null;
|
|
70
72
|
function getCurrentConfig() {
|
|
71
73
|
const mockConfig2 = getMockConfig();
|
|
72
74
|
if (mockConfig2) {
|
|
73
75
|
return mockConfig2;
|
|
74
76
|
}
|
|
75
|
-
|
|
77
|
+
if (_configFile) {
|
|
78
|
+
return _configFile;
|
|
79
|
+
}
|
|
80
|
+
let configFile = defaultConfigValues(import_config.default);
|
|
81
|
+
for (const pluginConfig of import_pluginConfig.default) {
|
|
82
|
+
configFile = pluginConfig(configFile);
|
|
83
|
+
}
|
|
84
|
+
_configFile = configFile;
|
|
85
|
+
return configFile;
|
|
76
86
|
}
|
|
77
87
|
// Annotate the CommonJS export names for ESM import in node:
|
|
78
88
|
0 && (module.exports = {
|
|
@@ -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;
|
|
@@ -145,6 +145,9 @@ function isScalar(config, type) {
|
|
|
145
145
|
return ["String", "Boolean", "Float", "ID", "Int"].concat(Object.keys(config.scalars || {})).includes(type);
|
|
146
146
|
}
|
|
147
147
|
function parseScalar(config, type, value) {
|
|
148
|
+
if (typeof value === "undefined") {
|
|
149
|
+
return void 0;
|
|
150
|
+
}
|
|
148
151
|
if (type === "Boolean") {
|
|
149
152
|
return value === "true";
|
|
150
153
|
}
|
|
@@ -155,10 +158,18 @@ function parseScalar(config, type, value) {
|
|
|
155
158
|
return value;
|
|
156
159
|
}
|
|
157
160
|
if (type === "Int") {
|
|
158
|
-
|
|
161
|
+
const result = parseInt(value, 10);
|
|
162
|
+
if (Number.isNaN(result)) {
|
|
163
|
+
return void 0;
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
159
166
|
}
|
|
160
167
|
if (type === "Float") {
|
|
161
|
-
|
|
168
|
+
const result = parseFloat(value);
|
|
169
|
+
if (Number.isNaN(result)) {
|
|
170
|
+
return void 0;
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
162
173
|
}
|
|
163
174
|
if (config.scalars?.[type]?.marshal) {
|
|
164
175
|
return config.scalars[type]?.marshal(value);
|
|
@@ -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> = {
|
|
@@ -28,36 +28,32 @@ __export(types_exports, {
|
|
|
28
28
|
RefetchUpdateMode: () => RefetchUpdateMode
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(types_exports);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
DataSource2["Network"] = "network";
|
|
58
|
-
DataSource2["Ssr"] = "ssr";
|
|
59
|
-
return DataSource2;
|
|
60
|
-
})(DataSource || {});
|
|
31
|
+
const CachePolicy = {
|
|
32
|
+
CacheOrNetwork: "CacheOrNetwork",
|
|
33
|
+
CacheOnly: "CacheOnly",
|
|
34
|
+
NetworkOnly: "NetworkOnly",
|
|
35
|
+
CacheAndNetwork: "CacheAndNetwork"
|
|
36
|
+
};
|
|
37
|
+
const ArtifactKind = {
|
|
38
|
+
Query: "HoudiniQuery",
|
|
39
|
+
Subscription: "HoudiniSubscription",
|
|
40
|
+
Mutation: "HoudiniMutation",
|
|
41
|
+
Fragment: "HoudiniFragment"
|
|
42
|
+
};
|
|
43
|
+
const CompiledFragmentKind = ArtifactKind.Fragment;
|
|
44
|
+
const CompiledMutationKind = ArtifactKind.Mutation;
|
|
45
|
+
const CompiledQueryKind = ArtifactKind.Query;
|
|
46
|
+
const CompiledSubscriptionKind = ArtifactKind.Subscription;
|
|
47
|
+
const RefetchUpdateMode = {
|
|
48
|
+
append: "append",
|
|
49
|
+
prepend: "prepend",
|
|
50
|
+
replace: "replace"
|
|
51
|
+
};
|
|
52
|
+
const DataSource = {
|
|
53
|
+
Cache: "cache",
|
|
54
|
+
Network: "network",
|
|
55
|
+
Ssr: "ssr"
|
|
56
|
+
};
|
|
61
57
|
// Annotate the CommonJS export names for ESM import in node:
|
|
62
58
|
0 && (module.exports = {
|
|
63
59
|
ArtifactKind,
|
|
@@ -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 {};
|
|
@@ -350,17 +350,15 @@ function isInsertOperation(value) {
|
|
|
350
350
|
function isRemoveOperation(value) {
|
|
351
351
|
return !!value && value.kind === OperationKind.remove;
|
|
352
352
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
return OperationKind2;
|
|
363
|
-
})(OperationKind || {});
|
|
353
|
+
const OperationLocation = {
|
|
354
|
+
start: "start",
|
|
355
|
+
end: "end"
|
|
356
|
+
};
|
|
357
|
+
const OperationKind = {
|
|
358
|
+
delete: "delete",
|
|
359
|
+
insert: "insert",
|
|
360
|
+
remove: "remove"
|
|
361
|
+
};
|
|
364
362
|
export {
|
|
365
363
|
InMemoryStorage,
|
|
366
364
|
Layer,
|
|
@@ -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 {};
|
|
@@ -24,9 +24,7 @@ class DocumentStore extends Writable {
|
|
|
24
24
|
initialValue,
|
|
25
25
|
fetching
|
|
26
26
|
}) {
|
|
27
|
-
|
|
28
|
-
fetching = artifact.kind === ArtifactKind.Query;
|
|
29
|
-
}
|
|
27
|
+
fetching ??= artifact.kind === ArtifactKind.Query;
|
|
30
28
|
const initialState = {
|
|
31
29
|
data: initialValue ?? null,
|
|
32
30
|
errors: null,
|
|
@@ -64,14 +62,15 @@ class DocumentStore extends Writable {
|
|
|
64
62
|
policy,
|
|
65
63
|
stuff,
|
|
66
64
|
cacheParams,
|
|
67
|
-
setup = false
|
|
65
|
+
setup = false,
|
|
66
|
+
silenceEcho = false
|
|
68
67
|
} = {}) {
|
|
69
68
|
let context = new ClientPluginContextWrapper({
|
|
70
69
|
config: this.#configFile,
|
|
71
70
|
text: this.#artifact.raw,
|
|
72
71
|
hash: this.#artifact.hash,
|
|
73
72
|
policy: policy ?? this.#artifact.policy,
|
|
74
|
-
variables:
|
|
73
|
+
variables: null,
|
|
75
74
|
metadata,
|
|
76
75
|
session,
|
|
77
76
|
fetch,
|
|
@@ -88,13 +87,14 @@ class DocumentStore extends Writable {
|
|
|
88
87
|
cacheParams
|
|
89
88
|
});
|
|
90
89
|
const draft = context.draft();
|
|
91
|
-
draft.variables = variables ??
|
|
90
|
+
draft.variables = variables ?? null;
|
|
92
91
|
context = context.apply(draft, false);
|
|
93
92
|
return await new Promise((resolve, reject) => {
|
|
94
93
|
const state = {
|
|
95
94
|
setup,
|
|
96
95
|
currentStep: 0,
|
|
97
96
|
index: 0,
|
|
97
|
+
silenceEcho,
|
|
98
98
|
promise: {
|
|
99
99
|
resolved: false,
|
|
100
100
|
resolve,
|
|
@@ -232,6 +232,9 @@ class DocumentStore extends Writable {
|
|
|
232
232
|
}
|
|
233
233
|
this.#lastContext = ctx.context.draft();
|
|
234
234
|
this.#lastVariables = this.#lastContext.stuff.inputs.marshaled;
|
|
235
|
+
if (ctx.silenceEcho && finalValue.data === this.state.data) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
235
238
|
this.set(finalValue);
|
|
236
239
|
}
|
|
237
240
|
}
|
|
@@ -262,7 +265,7 @@ class ClientPluginContextWrapper {
|
|
|
262
265
|
ctx.stuff = val;
|
|
263
266
|
},
|
|
264
267
|
get variables() {
|
|
265
|
-
return ctx.variables ??
|
|
268
|
+
return ctx.variables ?? null;
|
|
266
269
|
},
|
|
267
270
|
set variables(val) {
|
|
268
271
|
Object.assign(ctx, applyVariables(ctx, { variables: val }));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { flatten } from "../lib/flatten";
|
|
2
2
|
import { DocumentStore } from "./documentStore";
|
|
3
3
|
import {
|
|
4
|
-
fetchParams as fetchParamsPlugin,
|
|
5
4
|
fetch as fetchPlugin,
|
|
6
5
|
mutation as mutationPlugin,
|
|
7
6
|
query as queryPlugin,
|
|
8
|
-
throwOnError as throwOnErrorPlugin
|
|
7
|
+
throwOnError as throwOnErrorPlugin,
|
|
8
|
+
fetchParams as fetchParamsPlugin
|
|
9
9
|
} from "./plugins";
|
|
10
10
|
import pluginsFromPlugins from "./plugins/injectedPlugins";
|
|
11
11
|
import { DocumentStore as DocumentStore2 } from "./documentStore";
|
|
@@ -53,6 +53,9 @@ class HoudiniClient {
|
|
|
53
53
|
}
|
|
54
54
|
function createPluginHooks(plugins) {
|
|
55
55
|
return plugins.reduce((hooks, plugin) => {
|
|
56
|
+
if (typeof plugin !== "function") {
|
|
57
|
+
throw new Error("Encountered client plugin that's not a function");
|
|
58
|
+
}
|
|
56
59
|
const result = plugin();
|
|
57
60
|
if (!result) {
|
|
58
61
|
return hooks;
|
|
@@ -6,7 +6,7 @@ const cachePolicy = ({
|
|
|
6
6
|
cache: localCache = cache
|
|
7
7
|
}) => () => {
|
|
8
8
|
return {
|
|
9
|
-
network(ctx, { next, resolve, marshalVariables }) {
|
|
9
|
+
network(ctx, { initialValue, next, resolve, marshalVariables }) {
|
|
10
10
|
const { policy, artifact } = ctx;
|
|
11
11
|
let useCache = false;
|
|
12
12
|
if (enabled && artifact.kind === ArtifactKind.Query && !ctx.cacheParams?.disableRead) {
|
|
@@ -20,10 +20,10 @@ const cachePolicy = ({
|
|
|
20
20
|
return resolve(ctx, {
|
|
21
21
|
fetching: false,
|
|
22
22
|
variables: ctx.variables ?? null,
|
|
23
|
-
data: value.data,
|
|
23
|
+
data: allowed ? value.data : initialValue.data,
|
|
24
24
|
errors: null,
|
|
25
25
|
source: DataSource.Cache,
|
|
26
|
-
partial: value.partial,
|
|
26
|
+
partial: allowed ? value.partial : false,
|
|
27
27
|
stale: value.stale
|
|
28
28
|
});
|
|
29
29
|
}
|
|
@@ -28,7 +28,7 @@ const fetch = (target) => {
|
|
|
28
28
|
});
|
|
29
29
|
resolve(ctx, {
|
|
30
30
|
fetching: false,
|
|
31
|
-
variables: ctx.variables ??
|
|
31
|
+
variables: ctx.variables ?? {},
|
|
32
32
|
data: result.data,
|
|
33
33
|
errors: !result.errors || result.errors.length === 0 ? null : result.errors,
|
|
34
34
|
partial: false,
|
|
@@ -42,7 +42,7 @@ const fetch = (target) => {
|
|
|
42
42
|
const defaultFetch = (url, params) => {
|
|
43
43
|
if (!url) {
|
|
44
44
|
throw new Error(
|
|
45
|
-
"Could not find configured client url. Please specify one in your
|
|
45
|
+
"Could not find configured client url. Please specify one in your HoudiniClient constructor."
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
48
|
return async ({ fetch: fetch2, text, variables }) => {
|
|
@@ -45,7 +45,7 @@ function subscription(factory) {
|
|
|
45
45
|
partial: true,
|
|
46
46
|
stale: false,
|
|
47
47
|
source: DataSource.Network,
|
|
48
|
-
variables: ctx.variables ??
|
|
48
|
+
variables: ctx.variables ?? {}
|
|
49
49
|
});
|
|
50
50
|
},
|
|
51
51
|
error(data) {
|
|
@@ -57,7 +57,7 @@ function subscription(factory) {
|
|
|
57
57
|
data: null,
|
|
58
58
|
errors: [data],
|
|
59
59
|
fetching: false,
|
|
60
|
-
variables: ctx.variables ??
|
|
60
|
+
variables: ctx.variables ?? {}
|
|
61
61
|
});
|
|
62
62
|
},
|
|
63
63
|
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;
|
|
@@ -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
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import config from "../imports/config";
|
|
2
|
+
import pluginConfigs from "../imports/pluginConfig";
|
|
2
3
|
let mockConfig = null;
|
|
3
4
|
function getMockConfig() {
|
|
4
5
|
return mockConfig;
|
|
@@ -33,12 +34,21 @@ function computeID(configFile, type, data) {
|
|
|
33
34
|
}
|
|
34
35
|
return id.slice(0, -2);
|
|
35
36
|
}
|
|
37
|
+
let _configFile = null;
|
|
36
38
|
function getCurrentConfig() {
|
|
37
39
|
const mockConfig2 = getMockConfig();
|
|
38
40
|
if (mockConfig2) {
|
|
39
41
|
return mockConfig2;
|
|
40
42
|
}
|
|
41
|
-
|
|
43
|
+
if (_configFile) {
|
|
44
|
+
return _configFile;
|
|
45
|
+
}
|
|
46
|
+
let configFile = defaultConfigValues(config);
|
|
47
|
+
for (const pluginConfig of pluginConfigs) {
|
|
48
|
+
configFile = pluginConfig(configFile);
|
|
49
|
+
}
|
|
50
|
+
_configFile = configFile;
|
|
51
|
+
return configFile;
|
|
42
52
|
}
|
|
43
53
|
export {
|
|
44
54
|
computeID,
|
|
@@ -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;
|