houdini 1.0.0-next.2 → 1.0.0-next.21
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 +5366 -2772
- package/build/cmd-esm/index.js +5340 -2746
- package/build/codegen/generators/artifacts/index.d.ts +2 -2
- package/build/codegen/generators/artifacts/indexFile.d.ts +2 -2
- package/build/codegen/generators/artifacts/selection.d.ts +5 -5
- package/build/codegen/generators/artifacts/utils.d.ts +0 -1
- package/build/codegen/generators/indexFile/index.d.ts +2 -2
- package/build/codegen/generators/persistedQueries/index.d.ts +2 -2
- package/build/codegen/generators/runtime/graphqlFunction.d.ts +2 -2
- package/build/codegen/generators/runtime/index.d.ts +2 -2
- package/build/codegen/generators/runtime/runtimeConfig.d.ts +7 -0
- package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
- package/build/codegen/generators/typescript/imperativeTypeDef.d.ts +2 -0
- package/build/codegen/generators/typescript/index.d.ts +2 -2
- package/build/codegen/generators/typescript/typeReference.d.ts +4 -2
- package/build/codegen/generators/typescript/types.d.ts +0 -1
- package/build/codegen/index.d.ts +2 -2
- package/build/codegen/transforms/addID.d.ts +2 -2
- package/build/codegen/transforms/composeQueries.d.ts +4 -4
- package/build/codegen/transforms/fragmentVariables.d.ts +3 -2
- package/build/codegen/transforms/list.d.ts +2 -2
- package/build/codegen/transforms/paginate.d.ts +2 -2
- package/build/codegen/transforms/schema.d.ts +2 -2
- package/build/codegen/transforms/typename.d.ts +2 -2
- package/build/codegen/utils/flattenSelections.d.ts +1 -1
- package/build/codegen/validators/noIDAlias.d.ts +2 -2
- package/build/codegen/validators/plugins.d.ts +2 -2
- package/build/codegen/validators/typeCheck.d.ts +2 -2
- package/build/codegen/validators/uniqueNames.d.ts +2 -2
- package/build/codegen-cjs/index.js +4694 -2137
- package/build/codegen-esm/index.js +4682 -2125
- package/build/lib/config.d.ts +15 -96
- package/build/lib/deepMerge.d.ts +1 -0
- package/build/lib/graphql.d.ts +5 -2
- package/build/lib/index.d.ts +2 -0
- package/build/lib/path.d.ts +1 -1
- package/build/lib/pipeline.d.ts +1 -1
- package/build/lib/plugin.d.ts +2 -0
- package/build/lib/types.d.ts +257 -6
- package/build/lib/walk.d.ts +4 -1
- package/build/lib-cjs/index.js +4108 -928
- package/build/lib-esm/index.js +4078 -907
- package/build/runtime/cache/cache.d.ts +28 -11
- package/build/runtime/cache/lists.d.ts +1 -0
- package/build/runtime/cache/staleManager.d.ts +30 -0
- package/build/runtime/cache/storage.d.ts +23 -20
- package/build/runtime/cache/stuff.d.ts +0 -2
- package/build/runtime/cache/subscription.d.ts +2 -1
- package/build/runtime/client/documentStore.d.ts +20 -17
- package/build/runtime/client/index.d.ts +13 -11
- package/build/runtime/client/plugins/cache.d.ts +1 -1
- package/build/runtime/client/plugins/fetch.d.ts +1 -1
- package/build/runtime/client/plugins/fetchParams.d.ts +2 -2
- package/build/runtime/client/plugins/injectedPlugins.d.ts +2 -1
- package/build/runtime/client/plugins/mutation.d.ts +1 -1
- package/build/runtime/client/plugins/query.d.ts +1 -1
- package/build/runtime/client/plugins/subscription.d.ts +2 -3
- package/build/runtime/client/plugins/throwOnError.d.ts +1 -1
- package/build/runtime/client/utils/documentPlugins.d.ts +3 -3
- package/build/runtime/generated.d.ts +1 -0
- package/build/runtime/imports/pluginConfig.d.ts +3 -0
- package/build/runtime/index.d.ts +1 -1
- package/build/runtime/lib/config.d.ts +27 -24
- package/build/runtime/lib/flatten.d.ts +2 -0
- package/build/runtime/lib/index.d.ts +1 -0
- package/build/runtime/lib/key.d.ts +6 -0
- package/build/runtime/lib/scalars.d.ts +3 -3
- package/build/runtime/lib/types.d.ts +47 -47
- package/build/runtime/public/cache.d.ts +26 -6
- package/build/runtime/public/record.d.ts +26 -17
- package/build/runtime/public/tests/test.d.ts +52 -10
- package/build/runtime/public/types.d.ts +8 -0
- package/build/runtime-cjs/cache/cache.d.ts +28 -11
- package/build/runtime-cjs/cache/cache.js +97 -22
- package/build/runtime-cjs/cache/gc.js +9 -0
- package/build/runtime-cjs/cache/lists.d.ts +1 -0
- package/build/runtime-cjs/cache/lists.js +9 -6
- package/build/runtime-cjs/cache/staleManager.d.ts +30 -0
- package/build/runtime-cjs/cache/staleManager.js +95 -0
- package/build/runtime-cjs/cache/storage.d.ts +23 -20
- package/build/runtime-cjs/cache/storage.js +11 -13
- package/build/runtime-cjs/cache/stuff.d.ts +0 -2
- package/build/runtime-cjs/cache/stuff.js +2 -19
- package/build/runtime-cjs/cache/subscription.d.ts +2 -1
- package/build/runtime-cjs/cache/subscription.js +11 -7
- package/build/runtime-cjs/client/documentStore.d.ts +20 -17
- package/build/runtime-cjs/client/documentStore.js +13 -9
- package/build/runtime-cjs/client/index.d.ts +13 -11
- package/build/runtime-cjs/client/index.js +48 -19
- package/build/runtime-cjs/client/plugins/cache.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/cache.js +12 -10
- package/build/runtime-cjs/client/plugins/fetch.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/fetch.js +10 -9
- package/build/runtime-cjs/client/plugins/fetchParams.d.ts +2 -2
- package/build/runtime-cjs/client/plugins/fetchParams.js +9 -4
- package/build/runtime-cjs/client/plugins/injectedPlugins.d.ts +2 -1
- package/build/runtime-cjs/client/plugins/mutation.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/mutation.js +3 -3
- package/build/runtime-cjs/client/plugins/query.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/query.js +5 -5
- package/build/runtime-cjs/client/plugins/subscription.d.ts +2 -3
- package/build/runtime-cjs/client/plugins/subscription.js +7 -5
- package/build/runtime-cjs/client/plugins/throwOnError.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/throwOnError.js +3 -3
- package/build/runtime-cjs/client/utils/documentPlugins.d.ts +3 -3
- package/build/runtime-cjs/generated.d.ts +1 -0
- package/build/runtime-cjs/imports/pluginConfig.d.ts +3 -0
- package/build/runtime-cjs/imports/pluginConfig.js +27 -0
- package/build/runtime-cjs/index.d.ts +1 -1
- package/build/runtime-cjs/lib/config.d.ts +27 -24
- package/build/runtime-cjs/lib/config.js +11 -1
- package/build/runtime-cjs/lib/flatten.d.ts +2 -0
- package/build/runtime-cjs/lib/flatten.js +41 -0
- package/build/runtime-cjs/lib/index.d.ts +1 -0
- package/build/runtime-cjs/lib/index.js +1 -0
- package/build/runtime-cjs/lib/key.d.ts +6 -0
- package/build/runtime-cjs/lib/key.js +41 -0
- package/build/runtime-cjs/lib/scalars.d.ts +3 -3
- package/build/runtime-cjs/lib/scalars.js +13 -2
- package/build/runtime-cjs/lib/types.d.ts +47 -47
- package/build/runtime-cjs/lib/types.js +26 -30
- package/build/runtime-cjs/public/cache.d.ts +26 -6
- package/build/runtime-cjs/public/cache.js +32 -32
- package/build/runtime-cjs/public/list.js +6 -28
- package/build/runtime-cjs/public/record.d.ts +26 -17
- package/build/runtime-cjs/public/record.js +27 -187
- package/build/runtime-cjs/public/tests/test.d.ts +52 -10
- package/build/runtime-cjs/public/tests/test.js +27 -2
- package/build/runtime-cjs/public/types.d.ts +8 -0
- package/build/runtime-esm/cache/cache.d.ts +28 -11
- package/build/runtime-esm/cache/cache.js +99 -24
- package/build/runtime-esm/cache/gc.js +9 -0
- package/build/runtime-esm/cache/lists.d.ts +1 -0
- package/build/runtime-esm/cache/lists.js +9 -6
- package/build/runtime-esm/cache/staleManager.d.ts +30 -0
- package/build/runtime-esm/cache/staleManager.js +71 -0
- package/build/runtime-esm/cache/storage.d.ts +23 -20
- package/build/runtime-esm/cache/storage.js +11 -13
- package/build/runtime-esm/cache/stuff.d.ts +0 -2
- package/build/runtime-esm/cache/stuff.js +1 -17
- package/build/runtime-esm/cache/subscription.d.ts +2 -1
- package/build/runtime-esm/cache/subscription.js +12 -8
- package/build/runtime-esm/client/documentStore.d.ts +20 -17
- package/build/runtime-esm/client/documentStore.js +14 -10
- package/build/runtime-esm/client/index.d.ts +13 -11
- package/build/runtime-esm/client/index.js +49 -21
- package/build/runtime-esm/client/plugins/cache.d.ts +1 -1
- package/build/runtime-esm/client/plugins/cache.js +11 -9
- package/build/runtime-esm/client/plugins/fetch.d.ts +1 -1
- package/build/runtime-esm/client/plugins/fetch.js +9 -8
- package/build/runtime-esm/client/plugins/fetchParams.d.ts +2 -2
- package/build/runtime-esm/client/plugins/fetchParams.js +8 -3
- package/build/runtime-esm/client/plugins/injectedPlugins.d.ts +2 -1
- package/build/runtime-esm/client/plugins/mutation.d.ts +1 -1
- package/build/runtime-esm/client/plugins/mutation.js +2 -2
- package/build/runtime-esm/client/plugins/query.d.ts +1 -1
- package/build/runtime-esm/client/plugins/query.js +4 -4
- package/build/runtime-esm/client/plugins/subscription.d.ts +2 -3
- package/build/runtime-esm/client/plugins/subscription.js +6 -4
- package/build/runtime-esm/client/plugins/throwOnError.d.ts +1 -1
- package/build/runtime-esm/client/plugins/throwOnError.js +2 -2
- package/build/runtime-esm/client/utils/documentPlugins.d.ts +3 -3
- package/build/runtime-esm/generated.d.ts +1 -0
- package/build/runtime-esm/imports/pluginConfig.d.ts +3 -0
- package/build/runtime-esm/imports/pluginConfig.js +5 -0
- package/build/runtime-esm/index.d.ts +1 -1
- package/build/runtime-esm/lib/config.d.ts +27 -24
- package/build/runtime-esm/lib/config.js +11 -1
- package/build/runtime-esm/lib/flatten.d.ts +2 -0
- package/build/runtime-esm/lib/flatten.js +17 -0
- package/build/runtime-esm/lib/index.d.ts +1 -0
- package/build/runtime-esm/lib/index.js +1 -0
- package/build/runtime-esm/lib/key.d.ts +6 -0
- package/build/runtime-esm/lib/key.js +17 -0
- package/build/runtime-esm/lib/scalars.d.ts +3 -3
- package/build/runtime-esm/lib/scalars.js +13 -2
- package/build/runtime-esm/lib/types.d.ts +47 -47
- package/build/runtime-esm/lib/types.js +26 -30
- package/build/runtime-esm/public/cache.d.ts +26 -6
- package/build/runtime-esm/public/cache.js +31 -30
- package/build/runtime-esm/public/list.js +6 -28
- package/build/runtime-esm/public/record.d.ts +26 -17
- package/build/runtime-esm/public/record.js +26 -183
- package/build/runtime-esm/public/tests/test.d.ts +52 -10
- package/build/runtime-esm/public/tests/test.js +26 -1
- package/build/runtime-esm/public/types.d.ts +8 -0
- package/build/test/index.d.ts +3 -3
- package/build/test-cjs/index.js +5007 -2465
- package/build/test-esm/index.js +4995 -2453
- package/build/vite/houdini.d.ts +2 -0
- package/build/vite-cjs/index.js +5344 -2744
- package/build/vite-esm/index.js +5319 -2719
- package/package.json +6 -5
- package/build/codegen/generators/typescript/imperativeCache.d.ts +0 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { rootID } from "../cache/cache";
|
|
2
|
+
import { marshalInputs } from "../lib";
|
|
2
3
|
import { keyFieldsForType } from "../lib/config";
|
|
3
|
-
import { _typeInfo } from "./cache";
|
|
4
4
|
class Record {
|
|
5
5
|
#id;
|
|
6
6
|
#cache;
|
|
@@ -24,199 +24,42 @@ class Record {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
value
|
|
27
|
+
read({
|
|
28
|
+
fragment,
|
|
29
|
+
variables
|
|
31
30
|
}) {
|
|
32
|
-
this.#cache.
|
|
33
|
-
|
|
34
|
-
const typeInfo = _typeInfo(this.#cache, this.type, field);
|
|
35
|
-
let newValue;
|
|
36
|
-
if (typeInfo.link) {
|
|
37
|
-
const keys = keyFieldsForType(this.#cache.config, typeInfo.type);
|
|
38
|
-
typeInfo.selection = {
|
|
39
|
-
fields: keys.reduce(
|
|
40
|
-
(acc, key2) => {
|
|
41
|
-
const keyInfo = _typeInfo(this.#cache, typeInfo.type, key2);
|
|
42
|
-
return {
|
|
43
|
-
...acc,
|
|
44
|
-
[key2]: {
|
|
45
|
-
type: keyInfo.type,
|
|
46
|
-
keyRaw: key2
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
__typename: {
|
|
52
|
-
type: "String",
|
|
53
|
-
keyRaw: "__typename"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
)
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
if (!typeInfo.link) {
|
|
60
|
-
const fnMarshal = this.#cache.config.scalars?.[typeInfo.type]?.marshal;
|
|
61
|
-
if (fnMarshal) {
|
|
62
|
-
newValue = fnMarshal(value);
|
|
63
|
-
} else {
|
|
64
|
-
newValue = value;
|
|
65
|
-
}
|
|
66
|
-
} else if (value instanceof Record) {
|
|
67
|
-
newValue = {
|
|
68
|
-
...value.idFields,
|
|
69
|
-
__typename: value.type
|
|
70
|
-
};
|
|
71
|
-
} else if (Array.isArray(value)) {
|
|
72
|
-
newValue = marshalNestedList(value);
|
|
73
|
-
} else if (value !== null) {
|
|
74
|
-
throw new Error("Value must be a RecordProxy if the field is a link to another record");
|
|
75
|
-
}
|
|
76
|
-
this.#cache._internal_unstable._internal_unstable.lifetimes.resetLifetime(this.#id, key);
|
|
77
|
-
this.#cache._internal_unstable.write({
|
|
31
|
+
return this.#cache._internal_unstable.read({
|
|
32
|
+
selection: fragment.artifact.selection,
|
|
78
33
|
parent: this.#id,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
data: {
|
|
88
|
-
[field]: newValue
|
|
89
|
-
}
|
|
34
|
+
variables: marshalInputs({
|
|
35
|
+
config: this.#cache.config,
|
|
36
|
+
artifact: fragment.artifact,
|
|
37
|
+
input: variables
|
|
38
|
+
}) ?? void 0
|
|
90
39
|
});
|
|
91
40
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.#cache.validateInstabilityWarning();
|
|
97
|
-
const key = computeKey({ field, args });
|
|
98
|
-
const typeInfo = _typeInfo(this.#cache, this.type, field);
|
|
99
|
-
if (typeInfo.link) {
|
|
100
|
-
const keys = keyFieldsForType(this.#cache.config, typeInfo.type);
|
|
101
|
-
typeInfo.selection = {
|
|
102
|
-
fields: keys.reduce(
|
|
103
|
-
(acc, key2) => {
|
|
104
|
-
const keyInfo = _typeInfo(this.#cache, typeInfo.type, key2);
|
|
105
|
-
return {
|
|
106
|
-
...acc,
|
|
107
|
-
[key2]: {
|
|
108
|
-
type: keyInfo.type,
|
|
109
|
-
keyRaw: key2
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
__typename: {
|
|
115
|
-
type: "String",
|
|
116
|
-
keyRaw: "__typename"
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
)
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
const result = this.#cache._internal_unstable.read({
|
|
41
|
+
write(args) {
|
|
42
|
+
this.#cache._internal_unstable.write({
|
|
43
|
+
data: args.data,
|
|
44
|
+
selection: args.fragment.artifact.selection,
|
|
123
45
|
parent: this.#id,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
if (!typeInfo.link) {
|
|
134
|
-
return result.data?.[field] ?? (typeInfo.nullable ? null : void 0);
|
|
135
|
-
}
|
|
136
|
-
const data = result.data?.[field] || {};
|
|
137
|
-
let finalResult = unmarshalNestedList(
|
|
138
|
-
this.#cache,
|
|
139
|
-
!Array.isArray(data) ? [data] : data
|
|
140
|
-
).map((val) => {
|
|
141
|
-
if (typeInfo.nullable && (val === null || Object.keys(val).length === 0)) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
return val;
|
|
46
|
+
variables: marshalInputs({
|
|
47
|
+
config: this.#cache.config,
|
|
48
|
+
artifact: args.fragment.artifact,
|
|
49
|
+
input: args.variables
|
|
50
|
+
}) ?? void 0,
|
|
51
|
+
forceStale: args.forceStale
|
|
145
52
|
});
|
|
146
|
-
return Array.isArray(data) ? finalResult : finalResult[0];
|
|
147
53
|
}
|
|
148
54
|
delete() {
|
|
149
55
|
this.#cache._internal_unstable.delete(this.#id);
|
|
150
56
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return args && keys.length > 0 ? `${field}(${keys.map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(args[key])}`).join(", ")})` : field;
|
|
156
|
-
}
|
|
157
|
-
const stringifyObjectWithNoQuotesOnKeys = (obj_from_json) => {
|
|
158
|
-
if (Array.isArray(obj_from_json)) {
|
|
159
|
-
return `[${obj_from_json.map((obj) => `${stringifyObjectWithNoQuotesOnKeys(obj)}`).join(", ")}]`;
|
|
160
|
-
}
|
|
161
|
-
if (typeof obj_from_json !== "object" || obj_from_json instanceof Date || obj_from_json === null) {
|
|
162
|
-
return JSON.stringify(obj_from_json).replace(/"([^"]+)":/g, "$1: ");
|
|
163
|
-
}
|
|
164
|
-
return `{${Object.keys(obj_from_json).map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(obj_from_json[key])}`).join(", ")}}`;
|
|
165
|
-
};
|
|
166
|
-
function marshalNestedList(list) {
|
|
167
|
-
const newValue = [];
|
|
168
|
-
for (const inner of list) {
|
|
169
|
-
if (Array.isArray(inner)) {
|
|
170
|
-
newValue.push(marshalNestedList(inner));
|
|
171
|
-
} else if (inner instanceof Record) {
|
|
172
|
-
newValue.push({ ...inner.idFields, __typename: inner.type });
|
|
173
|
-
} else {
|
|
174
|
-
newValue.push(inner);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return newValue;
|
|
178
|
-
}
|
|
179
|
-
function unmarshalNestedList(cache, list) {
|
|
180
|
-
const newValue = [];
|
|
181
|
-
for (const inner of list) {
|
|
182
|
-
if (Array.isArray(inner)) {
|
|
183
|
-
newValue.push(unmarshalNestedList(cache, inner));
|
|
184
|
-
} else if (inner === null) {
|
|
185
|
-
newValue.push(null);
|
|
186
|
-
} else if (inner.__typename) {
|
|
187
|
-
const type = inner.__typename;
|
|
188
|
-
let recordID = cache._internal_unstable._internal_unstable.id(type, inner);
|
|
189
|
-
if (!recordID) {
|
|
190
|
-
throw new Error("todo");
|
|
191
|
-
}
|
|
192
|
-
const typename = cache._internal_unstable.read({
|
|
193
|
-
selection: {
|
|
194
|
-
fields: {
|
|
195
|
-
__typename: {
|
|
196
|
-
keyRaw: "__typename",
|
|
197
|
-
type: "String"
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
|
-
parent: recordID
|
|
202
|
-
}).data?.__typename;
|
|
203
|
-
newValue.push(
|
|
204
|
-
new Record({
|
|
205
|
-
cache,
|
|
206
|
-
type: type || typename,
|
|
207
|
-
idFields: inner,
|
|
208
|
-
id: recordID
|
|
209
|
-
})
|
|
210
|
-
);
|
|
211
|
-
} else {
|
|
212
|
-
newValue.push(inner);
|
|
213
|
-
}
|
|
57
|
+
markStale(field, {
|
|
58
|
+
when
|
|
59
|
+
} = {}) {
|
|
60
|
+
this.#cache._internal_unstable.markRecordStale(this.#id, { field, when });
|
|
214
61
|
}
|
|
215
|
-
return newValue;
|
|
216
62
|
}
|
|
217
63
|
export {
|
|
218
|
-
Record
|
|
219
|
-
computeKey,
|
|
220
|
-
marshalNestedList,
|
|
221
|
-
stringifyObjectWithNoQuotesOnKeys
|
|
64
|
+
Record
|
|
222
65
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { type SubscriptionSelection, type FragmentArtifact, type QueryArtifact } from '../../lib';
|
|
1
2
|
import { Cache } from '../cache';
|
|
2
3
|
import type { Record } from '../record';
|
|
3
|
-
type
|
|
4
|
+
export type CacheTypeDefTest = {
|
|
4
5
|
types: {
|
|
5
6
|
__ROOT__: {
|
|
6
7
|
idFields: {};
|
|
8
|
+
fragments: [];
|
|
7
9
|
fields: {
|
|
8
10
|
test: {
|
|
9
11
|
type: number | null;
|
|
@@ -14,23 +16,23 @@ type CacheTypeDef = {
|
|
|
14
16
|
args: never;
|
|
15
17
|
};
|
|
16
18
|
viewer: {
|
|
17
|
-
type: Record<
|
|
19
|
+
type: Record<CacheTypeDefTest, 'User'> | null;
|
|
18
20
|
args: never;
|
|
19
21
|
};
|
|
20
22
|
pets: {
|
|
21
|
-
type: (Record<
|
|
23
|
+
type: (Record<CacheTypeDefTest, 'Cat'> | Record<CacheTypeDefTest, 'User'>)[];
|
|
22
24
|
args: never;
|
|
23
25
|
};
|
|
24
26
|
listOfLists: {
|
|
25
|
-
type: ((Record<
|
|
27
|
+
type: ((Record<CacheTypeDefTest, 'Cat'> | Record<CacheTypeDefTest, 'User'> | null | (null | Record<CacheTypeDefTest, 'User'>)[])[] | Record<CacheTypeDefTest, 'Cat'> | Record<CacheTypeDefTest, 'User'> | null)[];
|
|
26
28
|
args: never;
|
|
27
29
|
};
|
|
28
30
|
users: {
|
|
29
|
-
type: Record<
|
|
31
|
+
type: Record<CacheTypeDefTest, 'User'>[] | null;
|
|
30
32
|
args: never;
|
|
31
33
|
};
|
|
32
34
|
pet: {
|
|
33
|
-
type: Record<
|
|
35
|
+
type: Record<CacheTypeDefTest, 'Cat'> | Record<CacheTypeDefTest, 'User'>;
|
|
34
36
|
args: never;
|
|
35
37
|
};
|
|
36
38
|
};
|
|
@@ -39,13 +41,26 @@ type CacheTypeDef = {
|
|
|
39
41
|
idFields: {
|
|
40
42
|
id: string;
|
|
41
43
|
};
|
|
44
|
+
fragments: [
|
|
45
|
+
[
|
|
46
|
+
{
|
|
47
|
+
artifact: FragmentArtifact;
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
firstName: string;
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
pattern: string;
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
];
|
|
42
57
|
fields: {
|
|
43
58
|
firstName: {
|
|
44
59
|
type: string;
|
|
45
60
|
args: never;
|
|
46
61
|
};
|
|
47
62
|
parent: {
|
|
48
|
-
type: Record<
|
|
63
|
+
type: Record<CacheTypeDefTest, 'User'>;
|
|
49
64
|
args: never;
|
|
50
65
|
};
|
|
51
66
|
id: {
|
|
@@ -62,13 +77,14 @@ type CacheTypeDef = {
|
|
|
62
77
|
idFields: {
|
|
63
78
|
id: string;
|
|
64
79
|
};
|
|
80
|
+
fragments: [];
|
|
65
81
|
fields: {
|
|
66
82
|
name: {
|
|
67
83
|
type: string | null;
|
|
68
84
|
args: never;
|
|
69
85
|
};
|
|
70
86
|
parent: {
|
|
71
|
-
type: Record<
|
|
87
|
+
type: Record<CacheTypeDefTest, 'User'> | null;
|
|
72
88
|
args: never;
|
|
73
89
|
};
|
|
74
90
|
id: {
|
|
@@ -85,6 +101,7 @@ type CacheTypeDef = {
|
|
|
85
101
|
idFields: {
|
|
86
102
|
id: string;
|
|
87
103
|
};
|
|
104
|
+
fragments: [];
|
|
88
105
|
fields: {
|
|
89
106
|
name: {
|
|
90
107
|
type: string | null;
|
|
@@ -97,6 +114,26 @@ type CacheTypeDef = {
|
|
|
97
114
|
};
|
|
98
115
|
};
|
|
99
116
|
};
|
|
117
|
+
queries: [
|
|
118
|
+
[
|
|
119
|
+
{
|
|
120
|
+
artifact: QueryArtifact;
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
viewer: {
|
|
124
|
+
id: string;
|
|
125
|
+
firstName: string;
|
|
126
|
+
__typename: string;
|
|
127
|
+
parent: {
|
|
128
|
+
id: string;
|
|
129
|
+
firstName: string;
|
|
130
|
+
__typename: string;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
any
|
|
135
|
+
]
|
|
136
|
+
];
|
|
100
137
|
lists: {
|
|
101
138
|
All_Pets: {
|
|
102
139
|
types: 'User' | 'Cat';
|
|
@@ -110,5 +147,10 @@ type CacheTypeDef = {
|
|
|
110
147
|
};
|
|
111
148
|
};
|
|
112
149
|
};
|
|
113
|
-
export declare const testCache: () => Cache<
|
|
114
|
-
export {
|
|
150
|
+
export declare const testCache: () => Cache<CacheTypeDefTest>;
|
|
151
|
+
export declare const testFragment: (selection: SubscriptionSelection) => {
|
|
152
|
+
artifact: FragmentArtifact;
|
|
153
|
+
};
|
|
154
|
+
export declare const testQuery: (selection: SubscriptionSelection) => {
|
|
155
|
+
artifact: QueryArtifact;
|
|
156
|
+
};
|
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
import { testConfigFile } from "../../../test";
|
|
2
2
|
import { Cache as _Cache } from "../../cache/cache";
|
|
3
|
+
import {
|
|
4
|
+
ArtifactKind
|
|
5
|
+
} from "../../lib";
|
|
3
6
|
import { Cache } from "../cache";
|
|
4
7
|
const testCache = () => new Cache(new _Cache(testConfigFile()));
|
|
8
|
+
const testFragment = (selection) => ({
|
|
9
|
+
artifact: {
|
|
10
|
+
kind: ArtifactKind.Fragment,
|
|
11
|
+
hash: "",
|
|
12
|
+
raw: "",
|
|
13
|
+
name: "",
|
|
14
|
+
rootType: "User",
|
|
15
|
+
selection
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const testQuery = (selection) => ({
|
|
19
|
+
artifact: {
|
|
20
|
+
kind: ArtifactKind.Query,
|
|
21
|
+
hash: "",
|
|
22
|
+
raw: "",
|
|
23
|
+
name: "",
|
|
24
|
+
rootType: "Query",
|
|
25
|
+
selection
|
|
26
|
+
}
|
|
27
|
+
});
|
|
5
28
|
export {
|
|
6
|
-
testCache
|
|
29
|
+
testCache,
|
|
30
|
+
testFragment,
|
|
31
|
+
testQuery
|
|
7
32
|
};
|
|
@@ -11,6 +11,7 @@ export type CacheTypeDef = {
|
|
|
11
11
|
type: any;
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
+
fragments: [any, any, any][];
|
|
14
15
|
};
|
|
15
16
|
};
|
|
16
17
|
lists: {
|
|
@@ -19,11 +20,14 @@ export type CacheTypeDef = {
|
|
|
19
20
|
filters: any;
|
|
20
21
|
};
|
|
21
22
|
};
|
|
23
|
+
queries: [any, any, any][];
|
|
22
24
|
};
|
|
23
25
|
export type ValidTypes<Def extends CacheTypeDef> = keyof Def['types'];
|
|
24
26
|
export type TypeFields<Def extends CacheTypeDef, Type extends keyof Def['types']> = Def['types'][Type]['fields'];
|
|
25
27
|
export type TypeFieldNames<Def extends CacheTypeDef, Type extends keyof Def['types']> = Extract<keyof TypeFields<Def, Type>, string>;
|
|
26
28
|
export type TypeNames<Def extends CacheTypeDef> = Extract<Exclude<ValidTypes<Def>, '__ROOT__'>, string>;
|
|
29
|
+
export type FragmentList<Def extends CacheTypeDef, Type extends ValidTypes<Def>> = Def['types'][Type]['fragments'];
|
|
30
|
+
export type QueryList<Def extends CacheTypeDef> = Def['queries'];
|
|
27
31
|
export type IDFields<Def extends CacheTypeDef, Type extends keyof Def['types']> = Def['types'][Type]['idFields'];
|
|
28
32
|
export type ProxyUnion<Def extends CacheTypeDef, U> = U extends null ? null : U extends TypeNames<Def> ? Record<Def, U> : never;
|
|
29
33
|
export type FieldType<Def extends CacheTypeDef, Type extends keyof Def['types'], Field extends keyof TypeFields<Def, Type>> = TypeFields<Def, Type>[Field]['type'];
|
|
@@ -34,3 +38,7 @@ export type ListFilters<Def extends CacheTypeDef, ListName extends ValidLists<De
|
|
|
34
38
|
must_not?: Def['lists'][ListName]['filters'];
|
|
35
39
|
} : never;
|
|
36
40
|
export type ListType<Def extends CacheTypeDef, Name extends ValidLists<Def>> = ProxyUnion<Def, Def['lists'][Name]['types']>;
|
|
41
|
+
export type FragmentVariables<_List, _Target> = _List extends [infer Head, ...infer Rest] ? Head extends [infer _Key, infer _Value, infer _Input] ? _Key extends _Target ? _Input : FragmentValue<Rest, _Target> : 'Encountered unknown fragment. Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).' : 'Encountered unknown fragment. Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).';
|
|
42
|
+
export type FragmentValue<List, _Target> = List extends [infer Head, ...infer Rest] ? Head extends [infer _Key, infer _Value, infer _Input] ? _Key extends _Target ? _Value : FragmentValue<Rest, _Target> : 'Encountered unknown fragment. Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).' : 'Encountered unknown fragment. Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).';
|
|
43
|
+
export type QueryValue<List, _Target> = List extends [infer Head, ...infer Rest] ? Head extends [infer _Key, infer _Value, infer _Input] ? _Key extends _Target ? _Value : QueryValue<Rest, _Target> : 'Encountered unknown query.Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).' : 'Encountered unknown query.Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).';
|
|
44
|
+
export type QueryInput<List, _Target> = List extends [infer Head, ...infer Rest] ? Head extends [infer _Key, infer _Value, infer _Input] ? _Key extends _Target ? _Input : QueryValue<Rest, _Target> : 'Encountered unknown query.Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).' : 'Encountered unknown query.Please make sure your runtime is up to date (ie, `vite dev` or `vite build`).';
|
package/build/test/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Document } from '../lib';
|
|
2
2
|
import { Config } from '../lib';
|
|
3
3
|
import type { ConfigFile } from '../runtime/lib/config';
|
|
4
4
|
export declare function testConfigFile({ plugins, ...config }?: Partial<ConfigFile>): ConfigFile;
|
|
@@ -6,6 +6,6 @@ export declare function testConfig(config?: Partial<ConfigFile>): Config;
|
|
|
6
6
|
export type Partial<T> = {
|
|
7
7
|
[P in keyof T]?: T[P];
|
|
8
8
|
};
|
|
9
|
-
export declare function pipelineTest(config: Config, documents: string[], shouldPass: boolean, testBody?: ((result: Error | Error[]) => void) | ((docs:
|
|
10
|
-
export declare function mockCollectedDoc(query: string):
|
|
9
|
+
export declare function pipelineTest(config: Config, documents: string[], shouldPass: boolean, testBody?: ((result: Error | Error[]) => void) | ((docs: Document[]) => void)): () => Promise<void>;
|
|
10
|
+
export declare function mockCollectedDoc(query: string): Document;
|
|
11
11
|
export declare function clearMock(): void;
|