houdini 1.0.0-next.2 → 1.0.0-next.4
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/build/cmd-cjs/index.js +1417 -1231
- package/build/cmd-esm/index.js +1417 -1231
- package/build/codegen/generators/artifacts/selection.d.ts +3 -3
- package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
- package/build/codegen/generators/typescript/{imperativeCache.d.ts → imperativeTypeDef.d.ts} +1 -1
- package/build/codegen/transforms/fragmentVariables.d.ts +1 -0
- package/build/codegen-cjs/index.js +1262 -1078
- package/build/codegen-esm/index.js +1262 -1078
- package/build/lib/config.d.ts +1 -1
- package/build/lib/walk.d.ts +4 -1
- package/build/lib-cjs/index.js +10 -10
- package/build/lib-esm/index.js +10 -10
- package/build/runtime/cache/cache.d.ts +3 -3
- package/build/runtime/cache/lists.d.ts +1 -0
- package/build/runtime/client/documentStore.d.ts +1 -1
- package/build/runtime/client/plugins/fetchParams.d.ts +1 -1
- package/build/runtime/generated.d.ts +1 -0
- package/build/runtime/index.d.ts +1 -1
- package/build/runtime/lib/config.d.ts +21 -22
- package/build/runtime/lib/scalars.d.ts +2 -2
- package/build/runtime/lib/types.d.ts +2 -3
- package/build/runtime/public/cache.d.ts +19 -6
- package/build/runtime/public/record.d.ts +17 -17
- package/build/runtime/public/tests/test.d.ts +43 -0
- package/build/runtime/public/types.d.ts +8 -0
- package/build/runtime-cjs/cache/cache.d.ts +3 -3
- package/build/runtime-cjs/cache/cache.js +30 -15
- package/build/runtime-cjs/cache/lists.d.ts +1 -0
- package/build/runtime-cjs/cache/lists.js +6 -3
- package/build/runtime-cjs/client/documentStore.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/fetchParams.d.ts +1 -1
- package/build/runtime-cjs/client/plugins/fetchParams.js +6 -1
- package/build/runtime-cjs/client/plugins/query.js +0 -1
- package/build/runtime-cjs/generated.d.ts +1 -0
- package/build/runtime-cjs/index.d.ts +1 -1
- package/build/runtime-cjs/lib/config.d.ts +21 -22
- package/build/runtime-cjs/lib/scalars.d.ts +2 -2
- package/build/runtime-cjs/lib/types.d.ts +2 -3
- package/build/runtime-cjs/public/cache.d.ts +19 -6
- package/build/runtime-cjs/public/cache.js +29 -32
- package/build/runtime-cjs/public/list.js +6 -28
- package/build/runtime-cjs/public/record.d.ts +17 -17
- package/build/runtime-cjs/public/record.js +22 -188
- package/build/runtime-cjs/public/tests/test.d.ts +43 -0
- 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 +3 -3
- package/build/runtime-esm/cache/cache.js +30 -15
- package/build/runtime-esm/cache/lists.d.ts +1 -0
- package/build/runtime-esm/cache/lists.js +6 -3
- package/build/runtime-esm/client/documentStore.d.ts +1 -1
- package/build/runtime-esm/client/plugins/fetchParams.d.ts +1 -1
- package/build/runtime-esm/client/plugins/fetchParams.js +6 -1
- package/build/runtime-esm/client/plugins/query.js +0 -1
- package/build/runtime-esm/generated.d.ts +1 -0
- package/build/runtime-esm/index.d.ts +1 -1
- package/build/runtime-esm/lib/config.d.ts +21 -22
- package/build/runtime-esm/lib/scalars.d.ts +2 -2
- package/build/runtime-esm/lib/types.d.ts +2 -3
- package/build/runtime-esm/public/cache.d.ts +19 -6
- package/build/runtime-esm/public/cache.js +28 -30
- package/build/runtime-esm/public/list.js +6 -28
- package/build/runtime-esm/public/record.d.ts +17 -17
- package/build/runtime-esm/public/record.js +21 -184
- package/build/runtime-esm/public/tests/test.d.ts +43 -0
- package/build/runtime-esm/public/tests/test.js +26 -1
- package/build/runtime-esm/public/types.d.ts +8 -0
- package/build/test-cjs/index.js +1270 -1087
- package/build/test-esm/index.js +1270 -1087
- package/build/vite-cjs/index.js +1271 -1087
- package/build/vite-esm/index.js +1271 -1087
- package/package.json +1 -1
package/build/cmd-esm/index.js
CHANGED
|
@@ -69862,8 +69862,7 @@ var Config = class {
|
|
|
69862
69862
|
types: types16 = {},
|
|
69863
69863
|
logLevel,
|
|
69864
69864
|
defaultFragmentMasking = "enable",
|
|
69865
|
-
|
|
69866
|
-
schemaPollHeaders = {},
|
|
69865
|
+
watchSchema,
|
|
69867
69866
|
projectDir
|
|
69868
69867
|
} = this.configFile;
|
|
69869
69868
|
if (typeof schema === "string") {
|
|
@@ -69896,8 +69895,8 @@ var Config = class {
|
|
|
69896
69895
|
this.logLevel = (logLevel || LogLevel.Summary).toLowerCase();
|
|
69897
69896
|
this.defaultFragmentMasking = defaultFragmentMasking;
|
|
69898
69897
|
this.routesDir = join2(this.projectRoot, "src", "routes");
|
|
69899
|
-
this.schemaPollInterval =
|
|
69900
|
-
this.schemaPollHeaders =
|
|
69898
|
+
this.schemaPollInterval = watchSchema?.interval ?? 2e3;
|
|
69899
|
+
this.schemaPollHeaders = watchSchema?.headers ?? {};
|
|
69901
69900
|
this.rootDir = join2(this.projectRoot, "$houdini");
|
|
69902
69901
|
if (defaultKeys) {
|
|
69903
69902
|
this.defaultKeys = defaultKeys;
|
|
@@ -69910,11 +69909,12 @@ var Config = class {
|
|
|
69910
69909
|
}
|
|
69911
69910
|
}
|
|
69912
69911
|
async apiURL() {
|
|
69913
|
-
|
|
69912
|
+
const apiURL = this.configFile.watchSchema?.url;
|
|
69913
|
+
if (!apiURL) {
|
|
69914
69914
|
return "";
|
|
69915
69915
|
}
|
|
69916
69916
|
const env = await this.getEnv();
|
|
69917
|
-
return this.processEnvValues(env,
|
|
69917
|
+
return this.processEnvValues(env, apiURL);
|
|
69918
69918
|
}
|
|
69919
69919
|
get include() {
|
|
69920
69920
|
if (this.configFile.include) {
|
|
@@ -70118,8 +70118,8 @@ var Config = class {
|
|
|
70118
70118
|
pluginDirectory(name2) {
|
|
70119
70119
|
return join2(this.pluginRootDirectory, name2);
|
|
70120
70120
|
}
|
|
70121
|
-
get
|
|
70122
|
-
return "
|
|
70121
|
+
get loadDirective() {
|
|
70122
|
+
return "load";
|
|
70123
70123
|
}
|
|
70124
70124
|
get maskEnableDirective() {
|
|
70125
70125
|
return "mask_enable";
|
|
@@ -70236,7 +70236,7 @@ var Config = class {
|
|
|
70236
70236
|
this.withDirective,
|
|
70237
70237
|
this.paginateDirective,
|
|
70238
70238
|
this.cacheDirective,
|
|
70239
|
-
this.
|
|
70239
|
+
this.loadDirective,
|
|
70240
70240
|
this.maskEnableDirective,
|
|
70241
70241
|
this.maskDisableDirective
|
|
70242
70242
|
].includes(name2.value) || this.isDeleteDirective(name2.value);
|
|
@@ -70825,7 +70825,7 @@ async function find_graphql(config2, parsedScript, walker) {
|
|
|
70825
70825
|
return;
|
|
70826
70826
|
}
|
|
70827
70827
|
const parsedTag = graphql4.parse(documentString);
|
|
70828
|
-
if (walker.where && !walker.where(parsedTag)) {
|
|
70828
|
+
if (walker.where && !walker.where(parsedTag, { node, parent })) {
|
|
70829
70829
|
return;
|
|
70830
70830
|
}
|
|
70831
70831
|
const definition = config2.extractDefinition(parsedTag);
|
|
@@ -70869,7 +70869,7 @@ async function find_graphql(config2, parsedScript, walker) {
|
|
|
70869
70869
|
var graphql27 = __toESM(require_graphql2(), 1);
|
|
70870
70870
|
|
|
70871
70871
|
// src/codegen/generators/artifacts/index.ts
|
|
70872
|
-
var
|
|
70872
|
+
var graphql14 = __toESM(require_graphql2(), 1);
|
|
70873
70873
|
var recast5 = __toESM(require_main2(), 1);
|
|
70874
70874
|
|
|
70875
70875
|
// src/codegen/utils/commonjs.ts
|
|
@@ -71127,159 +71127,534 @@ function murmurHash(str) {
|
|
|
71127
71127
|
return s2;
|
|
71128
71128
|
}
|
|
71129
71129
|
|
|
71130
|
-
// src/codegen/
|
|
71131
|
-
async function writeIndexFile(config2, docs) {
|
|
71132
|
-
const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
|
|
71133
|
-
let body = config2.module === "esm" ? docsToGenerate.reduce(
|
|
71134
|
-
(content, doc) => content + `
|
|
71135
|
-
export { default as ${doc.name}} from './${doc.name}'`,
|
|
71136
|
-
""
|
|
71137
|
-
) : docsToGenerate.reduce(
|
|
71138
|
-
(content, doc) => content + `
|
|
71139
|
-
${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
|
|
71140
|
-
cjsIndexFilePreamble
|
|
71141
|
-
);
|
|
71142
|
-
await fs_exports.writeFile(path_exports.join(config2.artifactDirectory, "index.js"), body);
|
|
71143
|
-
}
|
|
71144
|
-
|
|
71145
|
-
// src/codegen/generators/artifacts/inputs.ts
|
|
71130
|
+
// src/codegen/transforms/fragmentVariables.ts
|
|
71146
71131
|
var graphql5 = __toESM(require_graphql2(), 1);
|
|
71147
|
-
var recast3 = __toESM(require_main2(), 1);
|
|
71148
|
-
var AST3 = recast3.types.builders;
|
|
71149
|
-
function inputObject(config2, inputs) {
|
|
71150
|
-
const visitedTypes = /* @__PURE__ */ new Set();
|
|
71151
|
-
const inputObj = {
|
|
71152
|
-
fields: inputs.reduce((fields, input) => {
|
|
71153
|
-
const { type } = unwrapType(config2, input.type);
|
|
71154
|
-
return {
|
|
71155
|
-
...fields,
|
|
71156
|
-
[input.variable.name.value]: type.name
|
|
71157
|
-
};
|
|
71158
|
-
}, {}),
|
|
71159
|
-
types: {}
|
|
71160
|
-
};
|
|
71161
|
-
for (const input of inputs) {
|
|
71162
|
-
walkInputs(config2, visitedTypes, inputObj, input.type);
|
|
71163
|
-
}
|
|
71164
|
-
return inputObj;
|
|
71165
|
-
}
|
|
71166
|
-
function walkInputs(config2, visitedTypes, inputObj, rootType) {
|
|
71167
|
-
const { type } = unwrapType(config2, rootType);
|
|
71168
|
-
if (visitedTypes.has(type.name)) {
|
|
71169
|
-
return;
|
|
71170
|
-
}
|
|
71171
|
-
if (graphql5.isEnumType(type) || graphql5.isScalarType(type)) {
|
|
71172
|
-
return;
|
|
71173
|
-
}
|
|
71174
|
-
if (graphql5.isUnionType(type)) {
|
|
71175
|
-
return;
|
|
71176
|
-
}
|
|
71177
|
-
visitedTypes.add(type.name);
|
|
71178
|
-
inputObj.types[type.name] = Object.values(type.getFields()).reduce(
|
|
71179
|
-
(typeFields, field) => {
|
|
71180
|
-
const { type: fieldType } = unwrapType(config2, field.type);
|
|
71181
|
-
walkInputs(config2, visitedTypes, inputObj, fieldType);
|
|
71182
|
-
return {
|
|
71183
|
-
...typeFields,
|
|
71184
|
-
[field.name]: fieldType.toString()
|
|
71185
|
-
};
|
|
71186
|
-
},
|
|
71187
|
-
{}
|
|
71188
|
-
);
|
|
71189
|
-
}
|
|
71190
71132
|
|
|
71191
|
-
// src/codegen/
|
|
71192
|
-
var
|
|
71193
|
-
|
|
71194
|
-
|
|
71195
|
-
|
|
71196
|
-
|
|
71197
|
-
|
|
71198
|
-
|
|
71199
|
-
|
|
71200
|
-
|
|
71133
|
+
// src/codegen/transforms/composeQueries.ts
|
|
71134
|
+
var import_graphql30 = __toESM(require_graphql2(), 1);
|
|
71135
|
+
async function includeFragmentDefinitions(config2, documents) {
|
|
71136
|
+
const fragments = collectFragments(config2, documents);
|
|
71137
|
+
for (const [index, { name: name2, document, filename }] of documents.entries()) {
|
|
71138
|
+
const operation = document.definitions.find(
|
|
71139
|
+
({ kind }) => kind === import_graphql30.Kind.OPERATION_DEFINITION
|
|
71140
|
+
);
|
|
71141
|
+
if (!operation) {
|
|
71142
|
+
continue;
|
|
71143
|
+
}
|
|
71144
|
+
const allFragments = flattenFragments(
|
|
71145
|
+
filename,
|
|
71146
|
+
{ requiredFragments: findRequiredFragments(operation.selectionSet) },
|
|
71147
|
+
fragments
|
|
71148
|
+
);
|
|
71149
|
+
documents[index].document = {
|
|
71150
|
+
...document,
|
|
71151
|
+
definitions: [
|
|
71152
|
+
operation,
|
|
71153
|
+
...allFragments.map((fragmentName) => fragments[fragmentName].definition)
|
|
71154
|
+
]
|
|
71155
|
+
};
|
|
71201
71156
|
}
|
|
71202
|
-
|
|
71203
|
-
|
|
71204
|
-
|
|
71205
|
-
|
|
71206
|
-
)
|
|
71157
|
+
}
|
|
71158
|
+
function collectFragments(config2, docs) {
|
|
71159
|
+
return docs.reduce((acc, doc) => {
|
|
71160
|
+
const definitions = doc.document.definitions.reduce(
|
|
71161
|
+
(prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
|
|
71162
|
+
...prev,
|
|
71163
|
+
[definition.name.value]: {
|
|
71164
|
+
definition,
|
|
71165
|
+
requiredFragments: findRequiredFragments(definition.selectionSet),
|
|
71166
|
+
document: doc
|
|
71167
|
+
}
|
|
71168
|
+
},
|
|
71169
|
+
{}
|
|
71207
71170
|
);
|
|
71171
|
+
return {
|
|
71172
|
+
...acc,
|
|
71173
|
+
...definitions
|
|
71174
|
+
};
|
|
71175
|
+
}, {});
|
|
71176
|
+
}
|
|
71177
|
+
function findRequiredFragments(selectionSet) {
|
|
71178
|
+
if (selectionSet.selections.length === 0) {
|
|
71179
|
+
return [];
|
|
71208
71180
|
}
|
|
71209
|
-
|
|
71210
|
-
|
|
71211
|
-
|
|
71212
|
-
|
|
71213
|
-
|
|
71214
|
-
);
|
|
71181
|
+
const referencedFragments = [];
|
|
71182
|
+
for (const selection2 of selectionSet.selections) {
|
|
71183
|
+
if (selection2.kind === import_graphql30.Kind.FRAGMENT_SPREAD) {
|
|
71184
|
+
referencedFragments.push(selection2.name.value);
|
|
71185
|
+
} else if (selection2.selectionSet) {
|
|
71186
|
+
referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
|
|
71215
71187
|
}
|
|
71216
|
-
return AST4.stringLiteral(value);
|
|
71217
71188
|
}
|
|
71218
|
-
return
|
|
71189
|
+
return referencedFragments;
|
|
71219
71190
|
}
|
|
71220
|
-
function
|
|
71221
|
-
|
|
71222
|
-
|
|
71223
|
-
|
|
71224
|
-
|
|
71191
|
+
function flattenFragments(filepath, operation, fragments) {
|
|
71192
|
+
const frags = /* @__PURE__ */ new Set();
|
|
71193
|
+
const remaining = [...operation.requiredFragments];
|
|
71194
|
+
while (remaining.length > 0) {
|
|
71195
|
+
const nextFragment = remaining.shift();
|
|
71196
|
+
if (!nextFragment) {
|
|
71197
|
+
continue;
|
|
71225
71198
|
}
|
|
71226
|
-
|
|
71227
|
-
|
|
71228
|
-
|
|
71229
|
-
|
|
71230
|
-
|
|
71231
|
-
|
|
71232
|
-
|
|
71233
|
-
|
|
71234
|
-
|
|
71235
|
-
|
|
71236
|
-
}
|
|
71237
|
-
fields[key].push(value);
|
|
71199
|
+
if (!frags.has(nextFragment)) {
|
|
71200
|
+
frags.add(nextFragment);
|
|
71201
|
+
} else {
|
|
71202
|
+
continue;
|
|
71203
|
+
}
|
|
71204
|
+
const targetFragment = fragments[nextFragment];
|
|
71205
|
+
if (!targetFragment) {
|
|
71206
|
+
throw new HoudiniError({
|
|
71207
|
+
filepath,
|
|
71208
|
+
message: "compose: could not find definition for fragment " + nextFragment
|
|
71209
|
+
});
|
|
71238
71210
|
}
|
|
71211
|
+
remaining.push(...targetFragment.requiredFragments);
|
|
71239
71212
|
}
|
|
71240
|
-
return
|
|
71241
|
-
Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
|
|
71242
|
-
);
|
|
71213
|
+
return [...frags];
|
|
71243
71214
|
}
|
|
71244
|
-
|
|
71245
|
-
|
|
71246
|
-
|
|
71247
|
-
|
|
71248
|
-
|
|
71249
|
-
|
|
71250
|
-
|
|
71251
|
-
|
|
71252
|
-
|
|
71253
|
-
|
|
71254
|
-
|
|
71255
|
-
|
|
71256
|
-
|
|
71257
|
-
|
|
71258
|
-
|
|
71259
|
-
|
|
71260
|
-
|
|
71261
|
-
|
|
71215
|
+
|
|
71216
|
+
// src/codegen/transforms/fragmentVariables.ts
|
|
71217
|
+
var GraphqlKinds2 = graphql5.Kind;
|
|
71218
|
+
async function fragmentVariables(config2, documents) {
|
|
71219
|
+
const fragments = collectFragments(config2, documents);
|
|
71220
|
+
const generatedFragments = {};
|
|
71221
|
+
const visitedFragments = /* @__PURE__ */ new Set();
|
|
71222
|
+
for (const doc2 of documents) {
|
|
71223
|
+
const operation = doc2.document.definitions.find(
|
|
71224
|
+
({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
|
|
71225
|
+
);
|
|
71226
|
+
if (!operation) {
|
|
71227
|
+
continue;
|
|
71228
|
+
}
|
|
71229
|
+
doc2.document = inlineFragmentArgs({
|
|
71230
|
+
config: config2,
|
|
71231
|
+
filepath: doc2.filename,
|
|
71232
|
+
fragmentDefinitions: fragments,
|
|
71233
|
+
document: doc2.document,
|
|
71234
|
+
generatedFragments,
|
|
71235
|
+
visitedFragments,
|
|
71236
|
+
scope: null
|
|
71237
|
+
});
|
|
71262
71238
|
}
|
|
71263
|
-
|
|
71239
|
+
const doc = {
|
|
71240
|
+
kind: graphql5.Kind.DOCUMENT,
|
|
71241
|
+
definitions: Object.values(generatedFragments)
|
|
71242
|
+
};
|
|
71243
|
+
documents.push({
|
|
71244
|
+
name: "generated::fragmentVariables",
|
|
71245
|
+
kind: "HoudiniFragment" /* Fragment */,
|
|
71246
|
+
document: doc,
|
|
71247
|
+
originalDocument: doc,
|
|
71248
|
+
generateStore: false,
|
|
71249
|
+
generateArtifact: false,
|
|
71250
|
+
filename: "generated::fragmentVariables",
|
|
71251
|
+
originalString: ""
|
|
71252
|
+
});
|
|
71264
71253
|
}
|
|
71265
|
-
|
|
71266
|
-
|
|
71267
|
-
|
|
71268
|
-
|
|
71269
|
-
|
|
71254
|
+
function inlineFragmentArgs({
|
|
71255
|
+
config: config2,
|
|
71256
|
+
filepath,
|
|
71257
|
+
fragmentDefinitions,
|
|
71258
|
+
document,
|
|
71259
|
+
generatedFragments,
|
|
71260
|
+
visitedFragments,
|
|
71261
|
+
scope,
|
|
71262
|
+
newName
|
|
71263
|
+
}) {
|
|
71264
|
+
if (!scope) {
|
|
71265
|
+
scope = operationScope(
|
|
71266
|
+
document.definitions.find(
|
|
71267
|
+
({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
|
|
71268
|
+
)
|
|
71269
|
+
);
|
|
71270
71270
|
}
|
|
71271
|
-
const
|
|
71272
|
-
|
|
71273
|
-
|
|
71274
|
-
|
|
71275
|
-
|
|
71276
|
-
|
|
71277
|
-
|
|
71278
|
-
|
|
71279
|
-
|
|
71280
|
-
}
|
|
71281
|
-
|
|
71282
|
-
|
|
71271
|
+
const definitionArgs = fragmentArguments(
|
|
71272
|
+
config2,
|
|
71273
|
+
filepath,
|
|
71274
|
+
document
|
|
71275
|
+
).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
|
|
71276
|
+
const result = graphql5.visit(document, {
|
|
71277
|
+
FragmentSpread(node) {
|
|
71278
|
+
const { definition } = fragmentDefinitions[node.name.value];
|
|
71279
|
+
let { args, hash } = collectWithArguments(config2, filepath, node, scope);
|
|
71280
|
+
const newFragmentName = `${node.name.value}${hash}`;
|
|
71281
|
+
if (!visitedFragments.has(newFragmentName)) {
|
|
71282
|
+
visitedFragments.add(newFragmentName);
|
|
71283
|
+
const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
|
|
71284
|
+
if (args) {
|
|
71285
|
+
for (const [field, value] of Object.entries(defaultArguments || {})) {
|
|
71286
|
+
if (!args[field]) {
|
|
71287
|
+
args[field] = value;
|
|
71288
|
+
}
|
|
71289
|
+
}
|
|
71290
|
+
generatedFragments[newFragmentName] = inlineFragmentArgs({
|
|
71291
|
+
config: config2,
|
|
71292
|
+
filepath,
|
|
71293
|
+
fragmentDefinitions,
|
|
71294
|
+
document: fragmentDefinitions[node.name.value].definition,
|
|
71295
|
+
generatedFragments,
|
|
71296
|
+
visitedFragments,
|
|
71297
|
+
scope: args,
|
|
71298
|
+
newName: newFragmentName
|
|
71299
|
+
});
|
|
71300
|
+
} else {
|
|
71301
|
+
const doc = fragmentDefinitions[node.name.value].document;
|
|
71302
|
+
const definitionIndex = doc.document.definitions.findIndex(
|
|
71303
|
+
(definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
|
|
71304
|
+
);
|
|
71305
|
+
const localDefinitions = [...doc.document.definitions];
|
|
71306
|
+
localDefinitions.splice(definitionIndex, 1);
|
|
71307
|
+
localDefinitions.push(
|
|
71308
|
+
inlineFragmentArgs({
|
|
71309
|
+
config: config2,
|
|
71310
|
+
filepath,
|
|
71311
|
+
fragmentDefinitions,
|
|
71312
|
+
document: fragmentDefinitions[node.name.value].definition,
|
|
71313
|
+
generatedFragments,
|
|
71314
|
+
visitedFragments,
|
|
71315
|
+
scope: defaultArguments,
|
|
71316
|
+
newName: ""
|
|
71317
|
+
})
|
|
71318
|
+
);
|
|
71319
|
+
doc.document = {
|
|
71320
|
+
...doc.document,
|
|
71321
|
+
definitions: localDefinitions
|
|
71322
|
+
};
|
|
71323
|
+
}
|
|
71324
|
+
if (node.name.value !== newFragmentName) {
|
|
71325
|
+
return {
|
|
71326
|
+
...node,
|
|
71327
|
+
name: {
|
|
71328
|
+
kind: "Name",
|
|
71329
|
+
value: newFragmentName
|
|
71330
|
+
}
|
|
71331
|
+
};
|
|
71332
|
+
}
|
|
71333
|
+
}
|
|
71334
|
+
},
|
|
71335
|
+
Argument(node) {
|
|
71336
|
+
const value = node.value;
|
|
71337
|
+
if (value.kind !== "Variable") {
|
|
71338
|
+
return;
|
|
71339
|
+
}
|
|
71340
|
+
if (!scope) {
|
|
71341
|
+
throw new HoudiniError({
|
|
71342
|
+
filepath,
|
|
71343
|
+
message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
|
|
71344
|
+
});
|
|
71345
|
+
}
|
|
71346
|
+
const newValue = scope[value.name.value];
|
|
71347
|
+
if (newValue) {
|
|
71348
|
+
return {
|
|
71349
|
+
...node,
|
|
71350
|
+
value: newValue
|
|
71351
|
+
};
|
|
71352
|
+
}
|
|
71353
|
+
if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
|
|
71354
|
+
throw new HoudiniError({
|
|
71355
|
+
filepath,
|
|
71356
|
+
message: "Missing value for required arg: " + value.name.value
|
|
71357
|
+
});
|
|
71358
|
+
}
|
|
71359
|
+
return null;
|
|
71360
|
+
}
|
|
71361
|
+
});
|
|
71362
|
+
if (newName) {
|
|
71363
|
+
result.name = {
|
|
71364
|
+
kind: graphql5.Kind.NAME,
|
|
71365
|
+
value: newName
|
|
71366
|
+
};
|
|
71367
|
+
}
|
|
71368
|
+
return result;
|
|
71369
|
+
}
|
|
71370
|
+
function withArguments(config2, node) {
|
|
71371
|
+
const withDirectives = node.directives?.filter(
|
|
71372
|
+
(directive) => directive.name.value === config2.withDirective
|
|
71373
|
+
);
|
|
71374
|
+
if (!withDirectives || withDirectives.length === 0) {
|
|
71375
|
+
return [];
|
|
71376
|
+
}
|
|
71377
|
+
return withDirectives.flatMap((directive) => directive.arguments || []);
|
|
71378
|
+
}
|
|
71379
|
+
function fragmentArguments(config2, filepath, definition) {
|
|
71380
|
+
const directives = definition.directives?.filter(
|
|
71381
|
+
(directive) => directive.name.value === config2.argumentsDirective
|
|
71382
|
+
);
|
|
71383
|
+
if (!directives || directives.length === 0) {
|
|
71384
|
+
return [];
|
|
71385
|
+
}
|
|
71386
|
+
return directives.flatMap(
|
|
71387
|
+
(directive) => directive.arguments?.flatMap((arg) => {
|
|
71388
|
+
if (arg.value.kind !== "ObjectValue") {
|
|
71389
|
+
throw new HoudiniError({
|
|
71390
|
+
filepath,
|
|
71391
|
+
message: "values of @argument must be objects"
|
|
71392
|
+
});
|
|
71393
|
+
}
|
|
71394
|
+
const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
|
|
71395
|
+
if (!typeArg || typeArg.kind !== "StringValue") {
|
|
71396
|
+
return [];
|
|
71397
|
+
}
|
|
71398
|
+
let type = typeArg.value;
|
|
71399
|
+
let name2 = arg.name.value;
|
|
71400
|
+
let required = false;
|
|
71401
|
+
let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
|
|
71402
|
+
if (type[type.length - 1] === "!") {
|
|
71403
|
+
type = type.slice(0, -1);
|
|
71404
|
+
required = true;
|
|
71405
|
+
defaultValue = null;
|
|
71406
|
+
}
|
|
71407
|
+
return [
|
|
71408
|
+
{
|
|
71409
|
+
name: name2,
|
|
71410
|
+
type,
|
|
71411
|
+
required,
|
|
71412
|
+
defaultValue
|
|
71413
|
+
}
|
|
71414
|
+
];
|
|
71415
|
+
}) || []
|
|
71416
|
+
);
|
|
71417
|
+
}
|
|
71418
|
+
function collectDefaultArgumentValues(config2, filepath, definition) {
|
|
71419
|
+
let result = {};
|
|
71420
|
+
for (const { name: name2, required, defaultValue } of fragmentArguments(
|
|
71421
|
+
config2,
|
|
71422
|
+
filepath,
|
|
71423
|
+
definition
|
|
71424
|
+
)) {
|
|
71425
|
+
if (required || !defaultValue) {
|
|
71426
|
+
continue;
|
|
71427
|
+
}
|
|
71428
|
+
result[name2] = defaultValue;
|
|
71429
|
+
}
|
|
71430
|
+
return result;
|
|
71431
|
+
}
|
|
71432
|
+
function collectWithArguments(config2, filepath, node, scope = {}) {
|
|
71433
|
+
const withArgs = withArguments(config2, node);
|
|
71434
|
+
if (withArgs.length === 0) {
|
|
71435
|
+
return { args: null, hash: "" };
|
|
71436
|
+
}
|
|
71437
|
+
let args = {};
|
|
71438
|
+
for (const arg of withArgs) {
|
|
71439
|
+
let value = arg.value;
|
|
71440
|
+
if (value.kind === GraphqlKinds2.VARIABLE) {
|
|
71441
|
+
if (!scope || !scope[value.name.value]) {
|
|
71442
|
+
throw new HoudiniError({
|
|
71443
|
+
filepath,
|
|
71444
|
+
message: "Encountered undefined variable: " + value.name.value
|
|
71445
|
+
});
|
|
71446
|
+
}
|
|
71447
|
+
value = scope[value.name.value];
|
|
71448
|
+
}
|
|
71449
|
+
args[arg.name.value] = {
|
|
71450
|
+
...value,
|
|
71451
|
+
loc: void 0
|
|
71452
|
+
};
|
|
71453
|
+
}
|
|
71454
|
+
return {
|
|
71455
|
+
args,
|
|
71456
|
+
hash: "_" + murmurHash(JSON.stringify(args))
|
|
71457
|
+
};
|
|
71458
|
+
}
|
|
71459
|
+
function operationScope(operation) {
|
|
71460
|
+
return operation.variableDefinitions?.reduce(
|
|
71461
|
+
(scope, definition) => ({
|
|
71462
|
+
...scope,
|
|
71463
|
+
[definition.variable.name.value]: {
|
|
71464
|
+
kind: "Variable",
|
|
71465
|
+
name: {
|
|
71466
|
+
kind: "Name",
|
|
71467
|
+
value: definition.variable.name.value
|
|
71468
|
+
}
|
|
71469
|
+
}
|
|
71470
|
+
}),
|
|
71471
|
+
{}
|
|
71472
|
+
) || {};
|
|
71473
|
+
}
|
|
71474
|
+
function fragmentArgumentsDefinitions(config2, filepath, definition) {
|
|
71475
|
+
const args = fragmentArguments(config2, filepath, definition);
|
|
71476
|
+
if (args.length === 0) {
|
|
71477
|
+
return [];
|
|
71478
|
+
}
|
|
71479
|
+
return args.map((arg) => {
|
|
71480
|
+
const innerType = {
|
|
71481
|
+
kind: "NamedType",
|
|
71482
|
+
name: {
|
|
71483
|
+
kind: "Name",
|
|
71484
|
+
value: arg.type
|
|
71485
|
+
}
|
|
71486
|
+
};
|
|
71487
|
+
return {
|
|
71488
|
+
kind: "VariableDefinition",
|
|
71489
|
+
type: arg.required ? innerType : {
|
|
71490
|
+
kind: "NonNullType",
|
|
71491
|
+
type: innerType
|
|
71492
|
+
},
|
|
71493
|
+
variable: {
|
|
71494
|
+
kind: "Variable",
|
|
71495
|
+
name: {
|
|
71496
|
+
kind: "Name",
|
|
71497
|
+
value: arg.name
|
|
71498
|
+
}
|
|
71499
|
+
},
|
|
71500
|
+
defaultValue: arg.defaultValue ?? void 0
|
|
71501
|
+
};
|
|
71502
|
+
});
|
|
71503
|
+
}
|
|
71504
|
+
|
|
71505
|
+
// src/codegen/generators/artifacts/indexFile.ts
|
|
71506
|
+
async function writeIndexFile(config2, docs) {
|
|
71507
|
+
const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
|
|
71508
|
+
let body = config2.module === "esm" ? docsToGenerate.reduce(
|
|
71509
|
+
(content, doc) => content + `
|
|
71510
|
+
export { default as ${doc.name}} from './${doc.name}'`,
|
|
71511
|
+
""
|
|
71512
|
+
) : docsToGenerate.reduce(
|
|
71513
|
+
(content, doc) => content + `
|
|
71514
|
+
${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
|
|
71515
|
+
cjsIndexFilePreamble
|
|
71516
|
+
);
|
|
71517
|
+
await fs_exports.writeFile(path_exports.join(config2.artifactDirectory, "index.js"), body);
|
|
71518
|
+
}
|
|
71519
|
+
|
|
71520
|
+
// src/codegen/generators/artifacts/inputs.ts
|
|
71521
|
+
var graphql6 = __toESM(require_graphql2(), 1);
|
|
71522
|
+
var recast3 = __toESM(require_main2(), 1);
|
|
71523
|
+
var AST3 = recast3.types.builders;
|
|
71524
|
+
function inputObject(config2, inputs) {
|
|
71525
|
+
const visitedTypes = /* @__PURE__ */ new Set();
|
|
71526
|
+
const inputObj = {
|
|
71527
|
+
fields: inputs.reduce((fields, input) => {
|
|
71528
|
+
const { type } = unwrapType(config2, input.type);
|
|
71529
|
+
return {
|
|
71530
|
+
...fields,
|
|
71531
|
+
[input.variable.name.value]: type.name
|
|
71532
|
+
};
|
|
71533
|
+
}, {}),
|
|
71534
|
+
types: {}
|
|
71535
|
+
};
|
|
71536
|
+
for (const input of inputs) {
|
|
71537
|
+
walkInputs(config2, visitedTypes, inputObj, input.type);
|
|
71538
|
+
}
|
|
71539
|
+
return inputObj;
|
|
71540
|
+
}
|
|
71541
|
+
function walkInputs(config2, visitedTypes, inputObj, rootType) {
|
|
71542
|
+
const { type } = unwrapType(config2, rootType);
|
|
71543
|
+
if (visitedTypes.has(type.name)) {
|
|
71544
|
+
return;
|
|
71545
|
+
}
|
|
71546
|
+
if (graphql6.isEnumType(type) || graphql6.isScalarType(type)) {
|
|
71547
|
+
return;
|
|
71548
|
+
}
|
|
71549
|
+
if (graphql6.isUnionType(type)) {
|
|
71550
|
+
return;
|
|
71551
|
+
}
|
|
71552
|
+
visitedTypes.add(type.name);
|
|
71553
|
+
inputObj.types[type.name] = Object.values(type.getFields()).reduce(
|
|
71554
|
+
(typeFields, field) => {
|
|
71555
|
+
const { type: fieldType } = unwrapType(config2, field.type);
|
|
71556
|
+
walkInputs(config2, visitedTypes, inputObj, fieldType);
|
|
71557
|
+
return {
|
|
71558
|
+
...typeFields,
|
|
71559
|
+
[field.name]: fieldType.toString()
|
|
71560
|
+
};
|
|
71561
|
+
},
|
|
71562
|
+
{}
|
|
71563
|
+
);
|
|
71564
|
+
}
|
|
71565
|
+
|
|
71566
|
+
// src/codegen/generators/artifacts/operations.ts
|
|
71567
|
+
var graphql8 = __toESM(require_graphql2(), 1);
|
|
71568
|
+
|
|
71569
|
+
// src/codegen/generators/artifacts/utils.ts
|
|
71570
|
+
var graphql7 = __toESM(require_graphql2(), 1);
|
|
71571
|
+
var recast4 = __toESM(require_main2(), 1);
|
|
71572
|
+
var AST4 = recast4.types.builders;
|
|
71573
|
+
function serializeValue(value) {
|
|
71574
|
+
if (Array.isArray(value)) {
|
|
71575
|
+
return AST4.arrayExpression(value.map(serializeValue));
|
|
71576
|
+
}
|
|
71577
|
+
if (typeof value === "object" && value !== null) {
|
|
71578
|
+
return AST4.objectExpression(
|
|
71579
|
+
Object.entries(value).filter(([, value2]) => typeof value2 !== "undefined").map(
|
|
71580
|
+
([key, value2]) => AST4.objectProperty(AST4.stringLiteral(key), serializeValue(value2))
|
|
71581
|
+
)
|
|
71582
|
+
);
|
|
71583
|
+
}
|
|
71584
|
+
if (typeof value === "string") {
|
|
71585
|
+
if (value.indexOf("\n") !== -1) {
|
|
71586
|
+
return AST4.templateLiteral(
|
|
71587
|
+
[AST4.templateElement({ raw: value, cooked: value }, true)],
|
|
71588
|
+
[]
|
|
71589
|
+
);
|
|
71590
|
+
}
|
|
71591
|
+
return AST4.stringLiteral(value);
|
|
71592
|
+
}
|
|
71593
|
+
return AST4.literal(value);
|
|
71594
|
+
}
|
|
71595
|
+
function deepMerge(filepath, ...targets) {
|
|
71596
|
+
if (typeof targets[0] !== "object") {
|
|
71597
|
+
const matches = targets.filter((val) => val !== targets[0]).length === 0;
|
|
71598
|
+
if (!matches) {
|
|
71599
|
+
throw new HoudiniError({ filepath, message: "could not merge: " + targets });
|
|
71600
|
+
}
|
|
71601
|
+
return targets[0];
|
|
71602
|
+
}
|
|
71603
|
+
if (Array.isArray(targets[0])) {
|
|
71604
|
+
return targets[0].concat(...targets.slice(1));
|
|
71605
|
+
}
|
|
71606
|
+
const fields = {};
|
|
71607
|
+
for (const target of targets) {
|
|
71608
|
+
for (const [key, value] of Object.entries(target)) {
|
|
71609
|
+
if (!fields[key]) {
|
|
71610
|
+
fields[key] = [];
|
|
71611
|
+
}
|
|
71612
|
+
fields[key].push(value);
|
|
71613
|
+
}
|
|
71614
|
+
}
|
|
71615
|
+
return Object.fromEntries(
|
|
71616
|
+
Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
|
|
71617
|
+
);
|
|
71618
|
+
}
|
|
71619
|
+
function convertValue(config2, val) {
|
|
71620
|
+
let value;
|
|
71621
|
+
let kind;
|
|
71622
|
+
if (val.kind === graphql7.Kind.INT) {
|
|
71623
|
+
value = parseInt(val.value, 10);
|
|
71624
|
+
kind = "Int";
|
|
71625
|
+
} else if (val.kind === graphql7.Kind.FLOAT) {
|
|
71626
|
+
value = parseFloat(val.value);
|
|
71627
|
+
kind = "Float";
|
|
71628
|
+
} else if (val.kind === graphql7.Kind.BOOLEAN) {
|
|
71629
|
+
value = val.value;
|
|
71630
|
+
kind = "Boolean";
|
|
71631
|
+
} else if (val.kind === graphql7.Kind.VARIABLE) {
|
|
71632
|
+
value = val.name.value;
|
|
71633
|
+
kind = "Variable";
|
|
71634
|
+
} else if (val.kind === graphql7.Kind.STRING) {
|
|
71635
|
+
value = val.value;
|
|
71636
|
+
kind = "String";
|
|
71637
|
+
}
|
|
71638
|
+
return { kind, value };
|
|
71639
|
+
}
|
|
71640
|
+
|
|
71641
|
+
// src/codegen/generators/artifacts/operations.ts
|
|
71642
|
+
function operationsByPath(config2, filepath, definition, filterTypes) {
|
|
71643
|
+
if (!definition) {
|
|
71644
|
+
return {};
|
|
71645
|
+
}
|
|
71646
|
+
const pathOperations = {};
|
|
71647
|
+
graphql8.visit(definition, {
|
|
71648
|
+
FragmentSpread(node, _, __, ___, ancestors) {
|
|
71649
|
+
if (!config2.isListFragment(node.name.value)) {
|
|
71650
|
+
return;
|
|
71651
|
+
}
|
|
71652
|
+
const path2 = ancestorKey(ancestors);
|
|
71653
|
+
if (!pathOperations[path2]) {
|
|
71654
|
+
pathOperations[path2] = [];
|
|
71655
|
+
}
|
|
71656
|
+
pathOperations[path2].push(
|
|
71657
|
+
operationObject({
|
|
71283
71658
|
config: config2,
|
|
71284
71659
|
filepath,
|
|
71285
71660
|
listName: config2.listNameFromFragment(node.name.value),
|
|
@@ -71428,7 +71803,7 @@ function ancestorKey(ancestors) {
|
|
|
71428
71803
|
}
|
|
71429
71804
|
|
|
71430
71805
|
// src/codegen/generators/artifacts/selection.ts
|
|
71431
|
-
var
|
|
71806
|
+
var graphql13 = __toESM(require_graphql2(), 1);
|
|
71432
71807
|
|
|
71433
71808
|
// ../../node_modules/.pnpm/@kitql+helper@0.5.0/node_modules/@kitql/helper/index.mjs
|
|
71434
71809
|
var config = {
|
|
@@ -71468,16 +71843,16 @@ function logYellow(str) {
|
|
|
71468
71843
|
}
|
|
71469
71844
|
|
|
71470
71845
|
// src/codegen/transforms/list.ts
|
|
71471
|
-
var
|
|
71846
|
+
var graphql11 = __toESM(require_graphql2(), 1);
|
|
71472
71847
|
|
|
71473
71848
|
// src/codegen/utils/objectIdentificationSelection.ts
|
|
71474
|
-
var
|
|
71849
|
+
var graphql9 = __toESM(require_graphql2(), 1);
|
|
71475
71850
|
var objectIdentificationSelection = (config2, type) => {
|
|
71476
71851
|
return config2.keyFieldsForType(type.name).map((key) => {
|
|
71477
71852
|
return {
|
|
71478
|
-
kind:
|
|
71853
|
+
kind: graphql9.Kind.FIELD,
|
|
71479
71854
|
name: {
|
|
71480
|
-
kind:
|
|
71855
|
+
kind: graphql9.Kind.NAME,
|
|
71481
71856
|
value: key
|
|
71482
71857
|
}
|
|
71483
71858
|
};
|
|
@@ -71485,7 +71860,7 @@ var objectIdentificationSelection = (config2, type) => {
|
|
|
71485
71860
|
};
|
|
71486
71861
|
|
|
71487
71862
|
// src/codegen/transforms/paginate.ts
|
|
71488
|
-
var
|
|
71863
|
+
var graphql10 = __toESM(require_graphql2(), 1);
|
|
71489
71864
|
async function paginate(config2, documents) {
|
|
71490
71865
|
const newDocs = [];
|
|
71491
71866
|
for (const doc of documents) {
|
|
@@ -71518,7 +71893,7 @@ async function paginate(config2, documents) {
|
|
|
71518
71893
|
};
|
|
71519
71894
|
let cursorType = "String";
|
|
71520
71895
|
let paginationPath = [];
|
|
71521
|
-
doc.document =
|
|
71896
|
+
doc.document = graphql10.visit(doc.document, {
|
|
71522
71897
|
Field(node, _, __, ___, ancestors) {
|
|
71523
71898
|
const paginateDirective = node.directives?.find(
|
|
71524
71899
|
(directive) => directive.name.value === config2.paginateDirective
|
|
@@ -71529,23 +71904,22 @@ async function paginate(config2, documents) {
|
|
|
71529
71904
|
paginated = true;
|
|
71530
71905
|
const fieldTypeFields = parentTypeFromAncestors(config2.schema, doc.filename, ancestors).getFields()[node.name.value];
|
|
71531
71906
|
const args = new Set(fieldTypeFields.args.map((arg) => arg.name));
|
|
71532
|
-
const passedArgs = new Set(node.arguments?.map((arg) => arg.name.value));
|
|
71533
|
-
const specifiedForwards = passedArgs.has("first");
|
|
71534
|
-
const specifiedBackwards = passedArgs.has("last");
|
|
71535
71907
|
cursorType = fieldTypeFields.args?.find((arg) => ["before", "after"].includes(arg.name))?.type?.name || "String";
|
|
71536
71908
|
flags.after.type = cursorType;
|
|
71537
71909
|
flags.before.type = cursorType;
|
|
71538
|
-
const
|
|
71539
|
-
const
|
|
71540
|
-
const
|
|
71541
|
-
|
|
71542
|
-
|
|
71543
|
-
flags.
|
|
71544
|
-
flags.
|
|
71910
|
+
const passedArgs = new Set(node.arguments?.map((arg) => arg.name.value));
|
|
71911
|
+
const forwards = args.has("first") && args.has("after");
|
|
71912
|
+
const backwards = args.has("last") && args.has("after");
|
|
71913
|
+
const cursorPagination = passedArgs.has("last") || passedArgs.has("first");
|
|
71914
|
+
const offsetPagination = !cursorPagination && args.has("offset") && args.has("limit");
|
|
71915
|
+
flags.first.enabled = forwards;
|
|
71916
|
+
flags.after.enabled = forwards;
|
|
71917
|
+
flags.last.enabled = backwards;
|
|
71918
|
+
flags.before.enabled = backwards;
|
|
71545
71919
|
flags.offset.enabled = offsetPagination;
|
|
71546
71920
|
flags.limit.enabled = offsetPagination;
|
|
71547
71921
|
paginationPath = ancestors.filter(
|
|
71548
|
-
(ancestor) => !Array.isArray(ancestor) && ancestor.kind ===
|
|
71922
|
+
(ancestor) => !Array.isArray(ancestor) && ancestor.kind === graphql10.Kind.FIELD
|
|
71549
71923
|
).concat(node).map((field) => field.alias?.value || field.name.value);
|
|
71550
71924
|
return {
|
|
71551
71925
|
...node,
|
|
@@ -71561,12 +71935,8 @@ async function paginate(config2, documents) {
|
|
|
71561
71935
|
let fragmentName = "";
|
|
71562
71936
|
let refetchQueryName = "";
|
|
71563
71937
|
let nodeQuery = false;
|
|
71564
|
-
let refetchUpdate = "append" /* append */;
|
|
71565
|
-
if (flags.last.enabled) {
|
|
71566
|
-
refetchUpdate = "prepend" /* prepend */;
|
|
71567
|
-
}
|
|
71568
71938
|
let fragment = "";
|
|
71569
|
-
doc.document =
|
|
71939
|
+
doc.document = graphql10.visit(doc.document, {
|
|
71570
71940
|
OperationDefinition(node) {
|
|
71571
71941
|
if (node.operation !== "query") {
|
|
71572
71942
|
throw new HoudiniError({
|
|
@@ -71620,9 +71990,9 @@ async function paginate(config2, documents) {
|
|
|
71620
71990
|
directives: [
|
|
71621
71991
|
...node.directives || [],
|
|
71622
71992
|
{
|
|
71623
|
-
kind:
|
|
71993
|
+
kind: graphql10.Kind.DIRECTIVE,
|
|
71624
71994
|
name: {
|
|
71625
|
-
kind:
|
|
71995
|
+
kind: graphql10.Kind.NAME,
|
|
71626
71996
|
value: config2.argumentsDirective
|
|
71627
71997
|
}
|
|
71628
71998
|
}
|
|
@@ -71659,42 +72029,40 @@ async function paginate(config2, documents) {
|
|
|
71659
72029
|
targetType = fragment;
|
|
71660
72030
|
}
|
|
71661
72031
|
}
|
|
72032
|
+
const pageSize = flags.first.defaultValue ?? flags.last.defaultValue ?? flags.limit.defaultValue;
|
|
72033
|
+
const start = flags.after.defaultValue ?? flags.before.defaultValue ?? flags.offset.defaultValue;
|
|
72034
|
+
let direction = "forward";
|
|
72035
|
+
if (flags.before.enabled && flags.after.enabled) {
|
|
72036
|
+
direction = "both";
|
|
72037
|
+
} else if (flags.before.enabled) {
|
|
72038
|
+
direction = "backward";
|
|
72039
|
+
}
|
|
71662
72040
|
doc.refetch = {
|
|
71663
|
-
update: refetchUpdate,
|
|
71664
72041
|
path: paginationPath,
|
|
71665
72042
|
method: flags.first.enabled || flags.last.enabled ? "cursor" : "offset",
|
|
71666
|
-
pageSize
|
|
72043
|
+
pageSize,
|
|
71667
72044
|
embedded: nodeQuery,
|
|
71668
72045
|
targetType,
|
|
71669
72046
|
paginated: true,
|
|
71670
|
-
direction
|
|
71671
|
-
|
|
71672
|
-
|
|
71673
|
-
doc.refetch.pageSize = flags.first.defaultValue;
|
|
71674
|
-
doc.refetch.start = flags.after.defaultValue;
|
|
71675
|
-
} else if (flags.last.enabled) {
|
|
71676
|
-
doc.refetch.pageSize = flags.last.defaultValue;
|
|
71677
|
-
doc.refetch.start = flags.before.defaultValue;
|
|
71678
|
-
} else if (flags.limit.enabled) {
|
|
71679
|
-
doc.refetch.pageSize = flags.limit.defaultValue;
|
|
71680
|
-
doc.refetch.start = flags.offset.defaultValue;
|
|
71681
|
-
}
|
|
72047
|
+
direction,
|
|
72048
|
+
start
|
|
72049
|
+
};
|
|
71682
72050
|
if (!fragment) {
|
|
71683
72051
|
continue;
|
|
71684
72052
|
}
|
|
71685
72053
|
const paginationArgs = Object.entries(flags).filter(([_, { enabled }]) => enabled).map(([key, value]) => ({ name: key, ...value }));
|
|
71686
72054
|
const fragmentSpreadSelection = [
|
|
71687
72055
|
{
|
|
71688
|
-
kind:
|
|
72056
|
+
kind: graphql10.Kind.FRAGMENT_SPREAD,
|
|
71689
72057
|
name: {
|
|
71690
|
-
kind:
|
|
72058
|
+
kind: graphql10.Kind.NAME,
|
|
71691
72059
|
value: fragmentName
|
|
71692
72060
|
},
|
|
71693
72061
|
directives: [
|
|
71694
72062
|
{
|
|
71695
|
-
kind:
|
|
72063
|
+
kind: graphql10.Kind.DIRECTIVE,
|
|
71696
72064
|
name: {
|
|
71697
|
-
kind:
|
|
72065
|
+
kind: graphql10.Kind.NAME,
|
|
71698
72066
|
value: config2.withDirective
|
|
71699
72067
|
},
|
|
71700
72068
|
["arguments"]: paginationArgs.map(
|
|
@@ -71722,29 +72090,29 @@ async function paginate(config2, documents) {
|
|
|
71722
72090
|
});
|
|
71723
72091
|
const typeConfig = config2.typeConfig?.[fragment];
|
|
71724
72092
|
const queryDoc = {
|
|
71725
|
-
kind:
|
|
72093
|
+
kind: graphql10.Kind.DOCUMENT,
|
|
71726
72094
|
definitions: [
|
|
71727
72095
|
{
|
|
71728
|
-
kind:
|
|
72096
|
+
kind: graphql10.Kind.OPERATION_DEFINITION,
|
|
71729
72097
|
name: {
|
|
71730
|
-
kind:
|
|
72098
|
+
kind: graphql10.Kind.NAME,
|
|
71731
72099
|
value: refetchQueryName
|
|
71732
72100
|
},
|
|
71733
72101
|
operation: "query",
|
|
71734
72102
|
variableDefinitions: paginationArgs.map(
|
|
71735
72103
|
(arg) => ({
|
|
71736
|
-
kind:
|
|
72104
|
+
kind: graphql10.Kind.VARIABLE_DEFINITION,
|
|
71737
72105
|
type: {
|
|
71738
|
-
kind:
|
|
72106
|
+
kind: graphql10.Kind.NAMED_TYPE,
|
|
71739
72107
|
name: {
|
|
71740
|
-
kind:
|
|
72108
|
+
kind: graphql10.Kind.NAME,
|
|
71741
72109
|
value: arg.type
|
|
71742
72110
|
}
|
|
71743
72111
|
},
|
|
71744
72112
|
variable: {
|
|
71745
|
-
kind:
|
|
72113
|
+
kind: graphql10.Kind.VARIABLE,
|
|
71746
72114
|
name: {
|
|
71747
|
-
kind:
|
|
72115
|
+
kind: graphql10.Kind.NAME,
|
|
71748
72116
|
value: arg.name
|
|
71749
72117
|
}
|
|
71750
72118
|
},
|
|
@@ -71756,12 +72124,12 @@ async function paginate(config2, documents) {
|
|
|
71756
72124
|
).concat(
|
|
71757
72125
|
!nodeQuery ? [] : keys.map(
|
|
71758
72126
|
(key) => ({
|
|
71759
|
-
kind:
|
|
72127
|
+
kind: graphql10.Kind.VARIABLE_DEFINITION,
|
|
71760
72128
|
type: key.type,
|
|
71761
72129
|
variable: {
|
|
71762
|
-
kind:
|
|
72130
|
+
kind: graphql10.Kind.VARIABLE,
|
|
71763
72131
|
name: {
|
|
71764
|
-
kind:
|
|
72132
|
+
kind: graphql10.Kind.NAME,
|
|
71765
72133
|
value: key.name
|
|
71766
72134
|
}
|
|
71767
72135
|
}
|
|
@@ -71769,42 +72137,42 @@ async function paginate(config2, documents) {
|
|
|
71769
72137
|
)
|
|
71770
72138
|
),
|
|
71771
72139
|
selectionSet: {
|
|
71772
|
-
kind:
|
|
72140
|
+
kind: graphql10.Kind.SELECTION_SET,
|
|
71773
72141
|
selections: !nodeQuery ? fragmentSpreadSelection : [
|
|
71774
72142
|
{
|
|
71775
|
-
kind:
|
|
72143
|
+
kind: graphql10.Kind.FIELD,
|
|
71776
72144
|
name: {
|
|
71777
|
-
kind:
|
|
72145
|
+
kind: graphql10.Kind.NAME,
|
|
71778
72146
|
value: typeConfig?.resolve?.queryField || "node"
|
|
71779
72147
|
},
|
|
71780
72148
|
["arguments"]: keys.map((key) => ({
|
|
71781
|
-
kind:
|
|
72149
|
+
kind: graphql10.Kind.ARGUMENT,
|
|
71782
72150
|
name: {
|
|
71783
|
-
kind:
|
|
72151
|
+
kind: graphql10.Kind.NAME,
|
|
71784
72152
|
value: key.name
|
|
71785
72153
|
},
|
|
71786
72154
|
value: {
|
|
71787
|
-
kind:
|
|
72155
|
+
kind: graphql10.Kind.VARIABLE,
|
|
71788
72156
|
name: {
|
|
71789
|
-
kind:
|
|
72157
|
+
kind: graphql10.Kind.NAME,
|
|
71790
72158
|
value: key.name
|
|
71791
72159
|
}
|
|
71792
72160
|
}
|
|
71793
72161
|
})),
|
|
71794
72162
|
selectionSet: {
|
|
71795
|
-
kind:
|
|
72163
|
+
kind: graphql10.Kind.SELECTION_SET,
|
|
71796
72164
|
selections: [
|
|
71797
72165
|
{
|
|
71798
|
-
kind:
|
|
72166
|
+
kind: graphql10.Kind.FIELD,
|
|
71799
72167
|
name: {
|
|
71800
|
-
kind:
|
|
72168
|
+
kind: graphql10.Kind.NAME,
|
|
71801
72169
|
value: "__typename"
|
|
71802
72170
|
}
|
|
71803
72171
|
},
|
|
71804
72172
|
...(typeConfig?.keys || ["id"]).map((key) => ({
|
|
71805
|
-
kind:
|
|
72173
|
+
kind: graphql10.Kind.FIELD,
|
|
71806
72174
|
name: {
|
|
71807
|
-
kind:
|
|
72175
|
+
kind: graphql10.Kind.NAME,
|
|
71808
72176
|
value: key
|
|
71809
72177
|
}
|
|
71810
72178
|
})),
|
|
@@ -71854,27 +72222,21 @@ function replaceArgumentsWithVariables(args, flags) {
|
|
|
71854
72222
|
if (flags[name2].defaultValue || !spec.enabled || seenArgs[name2]) {
|
|
71855
72223
|
continue;
|
|
71856
72224
|
}
|
|
71857
|
-
if (["first", "after"].includes(name2) && flags["before"].enabled) {
|
|
71858
|
-
continue;
|
|
71859
|
-
}
|
|
71860
|
-
if (["last", "before"].includes(name2) && flags["first"].enabled) {
|
|
71861
|
-
continue;
|
|
71862
|
-
}
|
|
71863
72225
|
newArgs.push(variableAsArgument(name2));
|
|
71864
72226
|
}
|
|
71865
72227
|
return newArgs;
|
|
71866
72228
|
}
|
|
71867
72229
|
function variableAsArgument(name2, variable) {
|
|
71868
72230
|
return {
|
|
71869
|
-
kind:
|
|
72231
|
+
kind: graphql10.Kind.ARGUMENT,
|
|
71870
72232
|
name: {
|
|
71871
|
-
kind:
|
|
72233
|
+
kind: graphql10.Kind.NAME,
|
|
71872
72234
|
value: name2
|
|
71873
72235
|
},
|
|
71874
72236
|
value: {
|
|
71875
|
-
kind:
|
|
72237
|
+
kind: graphql10.Kind.VARIABLE,
|
|
71876
72238
|
name: {
|
|
71877
|
-
kind:
|
|
72239
|
+
kind: graphql10.Kind.NAME,
|
|
71878
72240
|
value: variable ?? name2
|
|
71879
72241
|
}
|
|
71880
72242
|
}
|
|
@@ -71882,18 +72244,18 @@ function variableAsArgument(name2, variable) {
|
|
|
71882
72244
|
}
|
|
71883
72245
|
function staticVariableDefinition(name2, type, defaultValue, variableName) {
|
|
71884
72246
|
return {
|
|
71885
|
-
kind:
|
|
72247
|
+
kind: graphql10.Kind.VARIABLE_DEFINITION,
|
|
71886
72248
|
type: {
|
|
71887
|
-
kind:
|
|
72249
|
+
kind: graphql10.Kind.NAMED_TYPE,
|
|
71888
72250
|
name: {
|
|
71889
|
-
kind:
|
|
72251
|
+
kind: graphql10.Kind.NAME,
|
|
71890
72252
|
value: type
|
|
71891
72253
|
}
|
|
71892
72254
|
},
|
|
71893
72255
|
variable: {
|
|
71894
|
-
kind:
|
|
72256
|
+
kind: graphql10.Kind.VARIABLE,
|
|
71895
72257
|
name: {
|
|
71896
|
-
kind:
|
|
72258
|
+
kind: graphql10.Kind.NAME,
|
|
71897
72259
|
value: variableName ?? name2
|
|
71898
72260
|
}
|
|
71899
72261
|
},
|
|
@@ -71905,9 +72267,9 @@ function staticVariableDefinition(name2, type, defaultValue, variableName) {
|
|
|
71905
72267
|
}
|
|
71906
72268
|
function argumentNode(name2, value) {
|
|
71907
72269
|
return {
|
|
71908
|
-
kind:
|
|
72270
|
+
kind: graphql10.Kind.ARGUMENT,
|
|
71909
72271
|
name: {
|
|
71910
|
-
kind:
|
|
72272
|
+
kind: graphql10.Kind.NAME,
|
|
71911
72273
|
value: name2
|
|
71912
72274
|
},
|
|
71913
72275
|
value: objectNode(value)
|
|
@@ -71915,16 +72277,16 @@ function argumentNode(name2, value) {
|
|
|
71915
72277
|
}
|
|
71916
72278
|
function objectNode([type, defaultValue]) {
|
|
71917
72279
|
const node = {
|
|
71918
|
-
kind:
|
|
72280
|
+
kind: graphql10.Kind.OBJECT,
|
|
71919
72281
|
fields: [
|
|
71920
72282
|
{
|
|
71921
|
-
kind:
|
|
72283
|
+
kind: graphql10.Kind.OBJECT_FIELD,
|
|
71922
72284
|
name: {
|
|
71923
|
-
kind:
|
|
72285
|
+
kind: graphql10.Kind.NAME,
|
|
71924
72286
|
value: "type"
|
|
71925
72287
|
},
|
|
71926
72288
|
value: {
|
|
71927
|
-
kind:
|
|
72289
|
+
kind: graphql10.Kind.STRING,
|
|
71928
72290
|
value: type
|
|
71929
72291
|
}
|
|
71930
72292
|
}
|
|
@@ -71932,8 +72294,8 @@ function objectNode([type, defaultValue]) {
|
|
|
71932
72294
|
};
|
|
71933
72295
|
if (defaultValue) {
|
|
71934
72296
|
node.fields.push({
|
|
71935
|
-
kind:
|
|
71936
|
-
name: { kind:
|
|
72297
|
+
kind: graphql10.Kind.OBJECT_FIELD,
|
|
72298
|
+
name: { kind: graphql10.Kind.NAME, value: "default" },
|
|
71937
72299
|
value: {
|
|
71938
72300
|
kind: typeof defaultValue === "number" ? "IntValue" : "StringValue",
|
|
71939
72301
|
value: defaultValue.toString()
|
|
@@ -71944,34 +72306,34 @@ function objectNode([type, defaultValue]) {
|
|
|
71944
72306
|
}
|
|
71945
72307
|
var pageInfoSelection = [
|
|
71946
72308
|
{
|
|
71947
|
-
kind:
|
|
72309
|
+
kind: graphql10.Kind.FIELD,
|
|
71948
72310
|
name: {
|
|
71949
|
-
kind:
|
|
72311
|
+
kind: graphql10.Kind.NAME,
|
|
71950
72312
|
value: "edges"
|
|
71951
72313
|
},
|
|
71952
72314
|
selectionSet: {
|
|
71953
|
-
kind:
|
|
72315
|
+
kind: graphql10.Kind.SELECTION_SET,
|
|
71954
72316
|
selections: [
|
|
71955
72317
|
{
|
|
71956
|
-
kind:
|
|
72318
|
+
kind: graphql10.Kind.FIELD,
|
|
71957
72319
|
name: {
|
|
71958
|
-
kind:
|
|
72320
|
+
kind: graphql10.Kind.NAME,
|
|
71959
72321
|
value: "cursor"
|
|
71960
72322
|
}
|
|
71961
72323
|
},
|
|
71962
72324
|
{
|
|
71963
|
-
kind:
|
|
72325
|
+
kind: graphql10.Kind.FIELD,
|
|
71964
72326
|
name: {
|
|
71965
|
-
kind:
|
|
72327
|
+
kind: graphql10.Kind.NAME,
|
|
71966
72328
|
value: "node"
|
|
71967
72329
|
},
|
|
71968
72330
|
selectionSet: {
|
|
71969
|
-
kind:
|
|
72331
|
+
kind: graphql10.Kind.SELECTION_SET,
|
|
71970
72332
|
selections: [
|
|
71971
72333
|
{
|
|
71972
|
-
kind:
|
|
72334
|
+
kind: graphql10.Kind.FIELD,
|
|
71973
72335
|
name: {
|
|
71974
|
-
kind:
|
|
72336
|
+
kind: graphql10.Kind.NAME,
|
|
71975
72337
|
value: "__typename"
|
|
71976
72338
|
}
|
|
71977
72339
|
}
|
|
@@ -71982,39 +72344,39 @@ var pageInfoSelection = [
|
|
|
71982
72344
|
}
|
|
71983
72345
|
},
|
|
71984
72346
|
{
|
|
71985
|
-
kind:
|
|
72347
|
+
kind: graphql10.Kind.FIELD,
|
|
71986
72348
|
name: {
|
|
71987
|
-
kind:
|
|
72349
|
+
kind: graphql10.Kind.NAME,
|
|
71988
72350
|
value: "pageInfo"
|
|
71989
72351
|
},
|
|
71990
72352
|
selectionSet: {
|
|
71991
|
-
kind:
|
|
72353
|
+
kind: graphql10.Kind.SELECTION_SET,
|
|
71992
72354
|
selections: [
|
|
71993
72355
|
{
|
|
71994
|
-
kind:
|
|
72356
|
+
kind: graphql10.Kind.FIELD,
|
|
71995
72357
|
name: {
|
|
71996
|
-
kind:
|
|
72358
|
+
kind: graphql10.Kind.NAME,
|
|
71997
72359
|
value: "hasPreviousPage"
|
|
71998
72360
|
}
|
|
71999
72361
|
},
|
|
72000
72362
|
{
|
|
72001
|
-
kind:
|
|
72363
|
+
kind: graphql10.Kind.FIELD,
|
|
72002
72364
|
name: {
|
|
72003
|
-
kind:
|
|
72365
|
+
kind: graphql10.Kind.NAME,
|
|
72004
72366
|
value: "hasNextPage"
|
|
72005
72367
|
}
|
|
72006
72368
|
},
|
|
72007
72369
|
{
|
|
72008
|
-
kind:
|
|
72370
|
+
kind: graphql10.Kind.FIELD,
|
|
72009
72371
|
name: {
|
|
72010
|
-
kind:
|
|
72372
|
+
kind: graphql10.Kind.NAME,
|
|
72011
72373
|
value: "startCursor"
|
|
72012
72374
|
}
|
|
72013
72375
|
},
|
|
72014
72376
|
{
|
|
72015
|
-
kind:
|
|
72377
|
+
kind: graphql10.Kind.FIELD,
|
|
72016
72378
|
name: {
|
|
72017
|
-
kind:
|
|
72379
|
+
kind: graphql10.Kind.NAME,
|
|
72018
72380
|
value: "endCursor"
|
|
72019
72381
|
}
|
|
72020
72382
|
}
|
|
@@ -72028,15 +72390,15 @@ async function addListFragments(config2, documents) {
|
|
|
72028
72390
|
const lists = {};
|
|
72029
72391
|
const errors = [];
|
|
72030
72392
|
for (const doc of documents) {
|
|
72031
|
-
doc.document =
|
|
72393
|
+
doc.document = graphql11.visit(doc.document, {
|
|
72032
72394
|
Directive(node, key, parent, path2, ancestors) {
|
|
72033
72395
|
if ([config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
|
|
72034
72396
|
const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
|
|
72035
72397
|
let error = {
|
|
72036
|
-
...new
|
|
72398
|
+
...new graphql11.GraphQLError(
|
|
72037
72399
|
"",
|
|
72038
72400
|
node,
|
|
72039
|
-
new
|
|
72401
|
+
new graphql11.Source(""),
|
|
72040
72402
|
node.loc ? [node.loc.start, node.loc.end] : null,
|
|
72041
72403
|
path2
|
|
72042
72404
|
),
|
|
@@ -72088,7 +72450,7 @@ async function addListFragments(config2, documents) {
|
|
|
72088
72450
|
{
|
|
72089
72451
|
kind: "Argument",
|
|
72090
72452
|
name: {
|
|
72091
|
-
kind:
|
|
72453
|
+
kind: graphql11.Kind.NAME,
|
|
72092
72454
|
value: "connection"
|
|
72093
72455
|
},
|
|
72094
72456
|
value: {
|
|
@@ -72138,7 +72500,7 @@ async function addListFragments(config2, documents) {
|
|
|
72138
72500
|
const validDeletes = [
|
|
72139
72501
|
...new Set(
|
|
72140
72502
|
Object.values(lists).map(({ type }) => {
|
|
72141
|
-
if (!(type instanceof
|
|
72503
|
+
if (!(type instanceof graphql11.GraphQLObjectType)) {
|
|
72142
72504
|
return "";
|
|
72143
72505
|
}
|
|
72144
72506
|
if (config2.keyFieldsForType(type.name).length !== 1) {
|
|
@@ -72152,7 +72514,7 @@ async function addListFragments(config2, documents) {
|
|
|
72152
72514
|
return;
|
|
72153
72515
|
}
|
|
72154
72516
|
const generatedDoc = {
|
|
72155
|
-
kind:
|
|
72517
|
+
kind: graphql11.Kind.DOCUMENT,
|
|
72156
72518
|
definitions: Object.entries(lists).flatMap(
|
|
72157
72519
|
([name2, { selection: selection2, type }]) => {
|
|
72158
72520
|
const schemaType = config2.schema.getType(type.name);
|
|
@@ -72160,7 +72522,7 @@ async function addListFragments(config2, documents) {
|
|
|
72160
72522
|
throw new HoudiniError({ message: "Lists must have a selection" });
|
|
72161
72523
|
}
|
|
72162
72524
|
const fragmentSelection = {
|
|
72163
|
-
kind:
|
|
72525
|
+
kind: graphql11.Kind.SELECTION_SET,
|
|
72164
72526
|
selections: [...selection2.selections]
|
|
72165
72527
|
};
|
|
72166
72528
|
if (schemaType && fragmentSelection && !fragmentSelection?.selections.find(
|
|
@@ -72175,14 +72537,14 @@ async function addListFragments(config2, documents) {
|
|
|
72175
72537
|
{
|
|
72176
72538
|
name: {
|
|
72177
72539
|
value: config2.listInsertFragment(name2),
|
|
72178
|
-
kind:
|
|
72540
|
+
kind: graphql11.Kind.NAME
|
|
72179
72541
|
},
|
|
72180
|
-
kind:
|
|
72542
|
+
kind: graphql11.Kind.FRAGMENT_DEFINITION,
|
|
72181
72543
|
selectionSet: fragmentSelection,
|
|
72182
72544
|
typeCondition: {
|
|
72183
|
-
kind:
|
|
72545
|
+
kind: graphql11.Kind.NAMED_TYPE,
|
|
72184
72546
|
name: {
|
|
72185
|
-
kind:
|
|
72547
|
+
kind: graphql11.Kind.NAME,
|
|
72186
72548
|
value: type.name
|
|
72187
72549
|
}
|
|
72188
72550
|
}
|
|
@@ -72190,32 +72552,32 @@ async function addListFragments(config2, documents) {
|
|
|
72190
72552
|
{
|
|
72191
72553
|
name: {
|
|
72192
72554
|
value: config2.listToggleFragment(name2),
|
|
72193
|
-
kind:
|
|
72555
|
+
kind: graphql11.Kind.NAME
|
|
72194
72556
|
},
|
|
72195
|
-
kind:
|
|
72557
|
+
kind: graphql11.Kind.FRAGMENT_DEFINITION,
|
|
72196
72558
|
selectionSet: fragmentSelection,
|
|
72197
72559
|
typeCondition: {
|
|
72198
|
-
kind:
|
|
72560
|
+
kind: graphql11.Kind.NAMED_TYPE,
|
|
72199
72561
|
name: {
|
|
72200
|
-
kind:
|
|
72562
|
+
kind: graphql11.Kind.NAME,
|
|
72201
72563
|
value: type.name
|
|
72202
72564
|
}
|
|
72203
72565
|
}
|
|
72204
72566
|
},
|
|
72205
72567
|
{
|
|
72206
|
-
kind:
|
|
72568
|
+
kind: graphql11.Kind.FRAGMENT_DEFINITION,
|
|
72207
72569
|
name: {
|
|
72208
72570
|
value: config2.listRemoveFragment(name2),
|
|
72209
|
-
kind:
|
|
72571
|
+
kind: graphql11.Kind.NAME
|
|
72210
72572
|
},
|
|
72211
72573
|
selectionSet: {
|
|
72212
|
-
kind:
|
|
72574
|
+
kind: graphql11.Kind.SELECTION_SET,
|
|
72213
72575
|
selections: [...objectIdentificationSelection(config2, type)]
|
|
72214
72576
|
},
|
|
72215
72577
|
typeCondition: {
|
|
72216
|
-
kind:
|
|
72578
|
+
kind: graphql11.Kind.NAMED_TYPE,
|
|
72217
72579
|
name: {
|
|
72218
|
-
kind:
|
|
72580
|
+
kind: graphql11.Kind.NAME,
|
|
72219
72581
|
value: type.name
|
|
72220
72582
|
}
|
|
72221
72583
|
}
|
|
@@ -72224,14 +72586,14 @@ async function addListFragments(config2, documents) {
|
|
|
72224
72586
|
}
|
|
72225
72587
|
).concat(
|
|
72226
72588
|
...validDeletes.map((typeName) => ({
|
|
72227
|
-
kind:
|
|
72589
|
+
kind: graphql11.Kind.DIRECTIVE_DEFINITION,
|
|
72228
72590
|
name: {
|
|
72229
|
-
kind:
|
|
72591
|
+
kind: graphql11.Kind.NAME,
|
|
72230
72592
|
value: config2.listDeleteDirective(typeName)
|
|
72231
72593
|
},
|
|
72232
72594
|
locations: [
|
|
72233
72595
|
{
|
|
72234
|
-
kind:
|
|
72596
|
+
kind: graphql11.Kind.NAME,
|
|
72235
72597
|
value: "FIELD"
|
|
72236
72598
|
}
|
|
72237
72599
|
],
|
|
@@ -72239,8 +72601,8 @@ async function addListFragments(config2, documents) {
|
|
|
72239
72601
|
}))
|
|
72240
72602
|
)
|
|
72241
72603
|
};
|
|
72242
|
-
config2.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(
|
|
72243
|
-
config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(
|
|
72604
|
+
config2.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(graphql11.print).join("\n\n");
|
|
72605
|
+
config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql11.print).join("\n\n");
|
|
72244
72606
|
documents.push({
|
|
72245
72607
|
name: "generated::lists",
|
|
72246
72608
|
kind: "HoudiniFragment" /* Fragment */,
|
|
@@ -72325,11 +72687,11 @@ var nodeNotDefinedMessage = (config2) => `Looks like you are trying to use the $
|
|
|
72325
72687
|
For more information, visit this link: ${siteURL}/guides/pagination`;
|
|
72326
72688
|
|
|
72327
72689
|
// src/codegen/generators/artifacts/fieldKey.ts
|
|
72328
|
-
var
|
|
72690
|
+
var graphql12 = __toESM(require_graphql2(), 1);
|
|
72329
72691
|
function fieldKey(config2, field) {
|
|
72330
72692
|
const attributeName = field.alias?.value || field.name.value;
|
|
72331
|
-
const printed =
|
|
72332
|
-
const secondParse =
|
|
72693
|
+
const printed = graphql12.print(field);
|
|
72694
|
+
const secondParse = graphql12.parse(`{${printed}}`).definitions[0].selectionSet.selections[0];
|
|
72333
72695
|
const paginated = !!field.directives?.find(
|
|
72334
72696
|
(directive) => directive.name.value === config2.paginateDirective
|
|
72335
72697
|
);
|
|
@@ -72367,7 +72729,7 @@ function selection({
|
|
|
72367
72729
|
path: path2 = [],
|
|
72368
72730
|
includeFragments,
|
|
72369
72731
|
document,
|
|
72370
|
-
|
|
72732
|
+
inConnection
|
|
72371
72733
|
}) {
|
|
72372
72734
|
let object = {};
|
|
72373
72735
|
const typeMap = {};
|
|
@@ -72424,8 +72786,8 @@ function selection({
|
|
|
72424
72786
|
const typeConditionName = field.typeCondition.name.value;
|
|
72425
72787
|
const typeCondition = config2.schema.getType(typeConditionName);
|
|
72426
72788
|
const possibleTypes = [];
|
|
72427
|
-
if (!
|
|
72428
|
-
} else if (
|
|
72789
|
+
if (!graphql13.isAbstractType(typeCondition)) {
|
|
72790
|
+
} else if (graphql13.isAbstractType(parentType)) {
|
|
72429
72791
|
const possibleParentTypes = config2.schema.getPossibleTypes(parentType).map((type) => type.name);
|
|
72430
72792
|
for (const possible of config2.schema.getPossibleTypes(typeCondition)) {
|
|
72431
72793
|
if (possibleParentTypes.includes(possible.name)) {
|
|
@@ -72473,7 +72835,7 @@ function selection({
|
|
|
72473
72835
|
} else {
|
|
72474
72836
|
let typeRef = type.getFields()[field.name.value].type;
|
|
72475
72837
|
fieldType = getRootType(typeRef);
|
|
72476
|
-
nullable = !
|
|
72838
|
+
nullable = !graphql13.isNonNullType(typeRef);
|
|
72477
72839
|
}
|
|
72478
72840
|
const typeName = fieldType.toString();
|
|
72479
72841
|
const pathSoFar = path2.concat(attributeName);
|
|
@@ -72509,14 +72871,23 @@ function selection({
|
|
|
72509
72871
|
(directive) => directive.name.value === config2.paginateDirective
|
|
72510
72872
|
);
|
|
72511
72873
|
if (paginated && document.refetch && document.refetch.method === "offset") {
|
|
72512
|
-
fieldObj.
|
|
72874
|
+
fieldObj.updates = ["append" /* append */];
|
|
72875
|
+
}
|
|
72876
|
+
let continueConnection = inConnection;
|
|
72877
|
+
if ([
|
|
72878
|
+
"edges",
|
|
72879
|
+
"endCursor",
|
|
72880
|
+
"startCursor",
|
|
72881
|
+
"hasNextPage",
|
|
72882
|
+
"hasPreviousPage"
|
|
72883
|
+
].includes(attributeName) && inConnection && document.refetch) {
|
|
72884
|
+
fieldObj.updates = ["append" /* append */, "prepend" /* prepend */];
|
|
72513
72885
|
}
|
|
72514
|
-
if (attributeName === "
|
|
72515
|
-
|
|
72516
|
-
markEdges = "";
|
|
72886
|
+
if (attributeName === "node" && inConnection) {
|
|
72887
|
+
continueConnection = false;
|
|
72517
72888
|
}
|
|
72518
72889
|
if (field.selectionSet) {
|
|
72519
|
-
const
|
|
72890
|
+
const connectionState = paginated && document.refetch?.method === "cursor" || continueConnection;
|
|
72520
72891
|
fieldObj.selection = selection({
|
|
72521
72892
|
config: config2,
|
|
72522
72893
|
filepath,
|
|
@@ -72526,7 +72897,7 @@ function selection({
|
|
|
72526
72897
|
path: pathSoFar,
|
|
72527
72898
|
includeFragments,
|
|
72528
72899
|
document,
|
|
72529
|
-
|
|
72900
|
+
inConnection: connectionState
|
|
72530
72901
|
});
|
|
72531
72902
|
}
|
|
72532
72903
|
if (field.arguments?.length && fieldObj.list) {
|
|
@@ -72538,7 +72909,7 @@ function selection({
|
|
|
72538
72909
|
{}
|
|
72539
72910
|
);
|
|
72540
72911
|
}
|
|
72541
|
-
if (
|
|
72912
|
+
if (graphql13.isInterfaceType(fieldType) || graphql13.isUnionType(fieldType)) {
|
|
72542
72913
|
fieldObj.abstract = true;
|
|
72543
72914
|
}
|
|
72544
72915
|
object.fields = {
|
|
@@ -72595,7 +72966,7 @@ function artifactGenerator(stats) {
|
|
|
72595
72966
|
return async function(config2, docs) {
|
|
72596
72967
|
const filterTypes = {};
|
|
72597
72968
|
for (const doc of docs) {
|
|
72598
|
-
|
|
72969
|
+
graphql14.visit(doc.document, {
|
|
72599
72970
|
Directive(node, _, __, ___, ancestors) {
|
|
72600
72971
|
if (node.name.value !== config2.listDirective) {
|
|
72601
72972
|
return;
|
|
@@ -72654,7 +73025,7 @@ function artifactGenerator(stats) {
|
|
|
72654
73025
|
return;
|
|
72655
73026
|
}
|
|
72656
73027
|
const usedVariableNames = /* @__PURE__ */ new Set();
|
|
72657
|
-
let documentWithoutInternalDirectives =
|
|
73028
|
+
let documentWithoutInternalDirectives = graphql14.visit(document, {
|
|
72658
73029
|
Directive(node) {
|
|
72659
73030
|
if (config2.isInternalDirective(node)) {
|
|
72660
73031
|
return null;
|
|
@@ -72667,7 +73038,7 @@ function artifactGenerator(stats) {
|
|
|
72667
73038
|
}
|
|
72668
73039
|
}
|
|
72669
73040
|
});
|
|
72670
|
-
let documentWithoutExtraVariables =
|
|
73041
|
+
let documentWithoutExtraVariables = graphql14.visit(
|
|
72671
73042
|
documentWithoutInternalDirectives,
|
|
72672
73043
|
{
|
|
72673
73044
|
VariableDefinition(variableDefinitionNode) {
|
|
@@ -72678,13 +73049,13 @@ function artifactGenerator(stats) {
|
|
|
72678
73049
|
}
|
|
72679
73050
|
}
|
|
72680
73051
|
);
|
|
72681
|
-
let rawString =
|
|
73052
|
+
let rawString = graphql14.print(documentWithoutExtraVariables);
|
|
72682
73053
|
let docKind = doc.kind;
|
|
72683
73054
|
const operations = document.definitions.filter(
|
|
72684
|
-
({ kind }) => kind ===
|
|
73055
|
+
({ kind }) => kind === graphql14.Kind.OPERATION_DEFINITION
|
|
72685
73056
|
);
|
|
72686
73057
|
const fragments = document.definitions.filter(
|
|
72687
|
-
({ kind }) => kind ===
|
|
73058
|
+
({ kind }) => kind === graphql14.Kind.FRAGMENT_DEFINITION
|
|
72688
73059
|
);
|
|
72689
73060
|
let rootType = "";
|
|
72690
73061
|
let selectionSet;
|
|
@@ -72717,7 +73088,13 @@ function artifactGenerator(stats) {
|
|
|
72717
73088
|
rootType = matchingFragment.typeCondition.name.value;
|
|
72718
73089
|
selectionSet = matchingFragment.selectionSet;
|
|
72719
73090
|
}
|
|
72720
|
-
|
|
73091
|
+
let inputs = operations[0]?.variableDefinitions;
|
|
73092
|
+
let directive = fragments[0]?.directives?.find(
|
|
73093
|
+
(directive2) => directive2.name.value === config2.argumentsDirective
|
|
73094
|
+
);
|
|
73095
|
+
if (docKind === "HoudiniFragment" /* Fragment */ && directive) {
|
|
73096
|
+
inputs = fragmentArgumentsDefinitions(config2, doc.filename, fragments[0]);
|
|
73097
|
+
}
|
|
72721
73098
|
const mergedSelection = flattenSelections({
|
|
72722
73099
|
config: config2,
|
|
72723
73100
|
filepath: doc.filename,
|
|
@@ -72778,7 +73155,7 @@ function artifactGenerator(stats) {
|
|
|
72778
73155
|
}
|
|
72779
73156
|
if (docKind === "HoudiniQuery") {
|
|
72780
73157
|
const cacheDirective = operations[0].directives?.find(
|
|
72781
|
-
(
|
|
73158
|
+
(directive2) => directive2.name.value === config2.cacheDirective
|
|
72782
73159
|
);
|
|
72783
73160
|
if (cacheDirective) {
|
|
72784
73161
|
const args = cacheDirective.arguments?.reduce(
|
|
@@ -72994,19 +73371,19 @@ async function generatePluginRuntime(config2, plugin) {
|
|
|
72994
73371
|
);
|
|
72995
73372
|
}
|
|
72996
73373
|
|
|
72997
|
-
// src/codegen/generators/typescript/
|
|
72998
|
-
var
|
|
73374
|
+
// src/codegen/generators/typescript/documentTypes.ts
|
|
73375
|
+
var recast11 = __toESM(require_main2(), 1);
|
|
72999
73376
|
|
|
73000
73377
|
// src/codegen/generators/typescript/addReferencedInputTypes.ts
|
|
73001
|
-
var
|
|
73378
|
+
var graphql17 = __toESM(require_graphql2(), 1);
|
|
73002
73379
|
var recast9 = __toESM(require_main2(), 1);
|
|
73003
73380
|
|
|
73004
73381
|
// src/codegen/generators/typescript/typeReference.ts
|
|
73005
|
-
var
|
|
73382
|
+
var graphql16 = __toESM(require_graphql2(), 1);
|
|
73006
73383
|
var recast8 = __toESM(require_main2(), 1);
|
|
73007
73384
|
|
|
73008
73385
|
// src/codegen/generators/typescript/types.ts
|
|
73009
|
-
var
|
|
73386
|
+
var graphql15 = __toESM(require_graphql2(), 1);
|
|
73010
73387
|
var recast7 = __toESM(require_main2(), 1);
|
|
73011
73388
|
var AST7 = recast7.types.builders;
|
|
73012
73389
|
function readonlyProperty(prop, enable = true) {
|
|
@@ -73022,351 +73399,104 @@ function nullableField(inner, input = false) {
|
|
|
73022
73399
|
}
|
|
73023
73400
|
return AST7.tsUnionType(members);
|
|
73024
73401
|
}
|
|
73025
|
-
function scalarPropertyValue(config2, missingScalars, target) {
|
|
73026
|
-
switch (target.name) {
|
|
73027
|
-
case "String": {
|
|
73028
|
-
return AST7.tsStringKeyword();
|
|
73029
|
-
}
|
|
73030
|
-
case "Int": {
|
|
73031
|
-
return AST7.tsNumberKeyword();
|
|
73032
|
-
}
|
|
73033
|
-
case "Float": {
|
|
73034
|
-
return AST7.tsNumberKeyword();
|
|
73035
|
-
}
|
|
73036
|
-
case "Boolean": {
|
|
73037
|
-
return AST7.tsBooleanKeyword();
|
|
73038
|
-
}
|
|
73039
|
-
case "ID": {
|
|
73040
|
-
return AST7.tsStringKeyword();
|
|
73041
|
-
}
|
|
73042
|
-
default: {
|
|
73043
|
-
if (
|
|
73044
|
-
return scalarPropertyValue(
|
|
73045
|
-
config2,
|
|
73046
|
-
missingScalars,
|
|
73047
|
-
target.ofType
|
|
73048
|
-
);
|
|
73049
|
-
}
|
|
73050
|
-
if (config2.scalars?.[target.name]) {
|
|
73051
|
-
return AST7.tsTypeReference(AST7.identifier(config2.scalars?.[target.name].type));
|
|
73052
|
-
}
|
|
73053
|
-
missingScalars.add(target.name);
|
|
73054
|
-
return AST7.tsAnyKeyword();
|
|
73055
|
-
}
|
|
73056
|
-
}
|
|
73057
|
-
}
|
|
73058
|
-
|
|
73059
|
-
// src/codegen/generators/typescript/typeReference.ts
|
|
73060
|
-
var AST8 = recast8.types.builders;
|
|
73061
|
-
function tsTypeReference(config2, missingScalars, definition) {
|
|
73062
|
-
const { type, wrappers } = unwrapType(config2, definition.type);
|
|
73063
|
-
let result;
|
|
73064
|
-
if (graphql15.isScalarType(type)) {
|
|
73065
|
-
result = scalarPropertyValue(config2, missingScalars, type);
|
|
73066
|
-
} else {
|
|
73067
|
-
result = AST8.tsTypeReference(AST8.identifier(type.name));
|
|
73068
|
-
}
|
|
73069
|
-
for (const toWrap of wrappers) {
|
|
73070
|
-
if (toWrap === "NonNull" /* NonNull */) {
|
|
73071
|
-
continue;
|
|
73072
|
-
} else if (toWrap === "Nullable" /* Nullable */) {
|
|
73073
|
-
result = nullableField(result, true);
|
|
73074
|
-
} else if (toWrap === "List" /* List */) {
|
|
73075
|
-
result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
|
|
73076
|
-
}
|
|
73077
|
-
}
|
|
73078
|
-
return result;
|
|
73079
|
-
}
|
|
73080
|
-
|
|
73081
|
-
// src/codegen/generators/typescript/addReferencedInputTypes.ts
|
|
73082
|
-
var AST9 = recast9.types.builders;
|
|
73083
|
-
function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, rootType) {
|
|
73084
|
-
const { type } = unwrapType(config2, rootType);
|
|
73085
|
-
if (graphql16.isScalarType(type)) {
|
|
73086
|
-
return;
|
|
73087
|
-
}
|
|
73088
|
-
if (visitedTypes.has(type.name)) {
|
|
73089
|
-
return;
|
|
73090
|
-
}
|
|
73091
|
-
if (graphql16.isUnionType(type)) {
|
|
73092
|
-
throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
|
|
73093
|
-
}
|
|
73094
|
-
visitedTypes.add(type.name);
|
|
73095
|
-
if (graphql16.isEnumType(type)) {
|
|
73096
|
-
ensureImports({
|
|
73097
|
-
config: config2,
|
|
73098
|
-
body,
|
|
73099
|
-
import: [type.name],
|
|
73100
|
-
sourceModule: "$houdini/graphql/enums",
|
|
73101
|
-
importKind: "type"
|
|
73102
|
-
});
|
|
73103
|
-
return;
|
|
73104
|
-
}
|
|
73105
|
-
const members = [];
|
|
73106
|
-
for (const field of Object.values(type.getFields())) {
|
|
73107
|
-
addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, field.type);
|
|
73108
|
-
members.push(
|
|
73109
|
-
AST9.tsPropertySignature(
|
|
73110
|
-
AST9.identifier(field.name),
|
|
73111
|
-
AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
|
|
73112
|
-
graphql16.isNullableType(field.type)
|
|
73113
|
-
)
|
|
73114
|
-
);
|
|
73115
|
-
}
|
|
73116
|
-
body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
|
|
73117
|
-
}
|
|
73118
|
-
|
|
73119
|
-
// src/codegen/generators/typescript/imperativeCache.ts
|
|
73120
|
-
var graphql17 = __toESM(require_graphql2(), 1);
|
|
73121
|
-
var recast10 = __toESM(require_main2(), 1);
|
|
73122
|
-
var AST10 = recast10.types.builders;
|
|
73123
|
-
async function imperativeCacheTypef(config2, docs) {
|
|
73124
|
-
const target = path_exports.join(config2.runtimeDirectory, "generated.d.ts");
|
|
73125
|
-
const body = [];
|
|
73126
|
-
const declaration = AST10.tsTypeAliasDeclaration(
|
|
73127
|
-
AST10.identifier(CacheTypeDefName),
|
|
73128
|
-
AST10.tsTypeLiteral([
|
|
73129
|
-
AST10.tsPropertySignature(
|
|
73130
|
-
AST10.identifier("types"),
|
|
73131
|
-
AST10.tsTypeAnnotation(typeDefinitions(config2, body))
|
|
73132
|
-
),
|
|
73133
|
-
AST10.tsPropertySignature(
|
|
73134
|
-
AST10.identifier("lists"),
|
|
73135
|
-
AST10.tsTypeAnnotation(listDefinitions(config2, docs))
|
|
73136
|
-
)
|
|
73137
|
-
])
|
|
73138
|
-
);
|
|
73139
|
-
declaration.declare = true;
|
|
73140
|
-
const importRecord = AST10.importDeclaration(
|
|
73141
|
-
[AST10.importSpecifier(AST10.identifier("Record"))],
|
|
73142
|
-
AST10.stringLiteral("./public/record")
|
|
73143
|
-
);
|
|
73144
|
-
importRecord.importKind = "type";
|
|
73145
|
-
await fs_exports.writeFile(
|
|
73146
|
-
target,
|
|
73147
|
-
recast10.prettyPrint(
|
|
73148
|
-
AST10.program([importRecord, ...body, AST10.exportNamedDeclaration(declaration)])
|
|
73149
|
-
).code
|
|
73150
|
-
);
|
|
73151
|
-
}
|
|
73152
|
-
function typeDefinitions(config2, body) {
|
|
73153
|
-
const operationTypes = [config2.schema.getMutationType(), config2.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
|
|
73154
|
-
const visitedTypes = /* @__PURE__ */ new Set();
|
|
73155
|
-
const types16 = Object.values(config2.schema.getTypeMap()).filter(
|
|
73156
|
-
(type) => !graphql17.isAbstractType(type) && !graphql17.isScalarType(type) && !graphql17.isEnumType(type) && !graphql17.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
|
|
73157
|
-
);
|
|
73158
|
-
return AST10.tsTypeLiteral(
|
|
73159
|
-
types16.map((type) => {
|
|
73160
|
-
let typeName = type.name;
|
|
73161
|
-
if (config2.schema.getQueryType() && config2.schema.getQueryType()?.name === type.name) {
|
|
73162
|
-
typeName = "__ROOT__";
|
|
73163
|
-
}
|
|
73164
|
-
let idFields = AST10.tsNeverKeyword();
|
|
73165
|
-
const keys = keyFieldsForType(config2.configFile, type.name);
|
|
73166
|
-
if (graphql17.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
|
|
73167
|
-
idFields = AST10.tsTypeLiteral(
|
|
73168
|
-
keys.map((key) => {
|
|
73169
|
-
const fieldType = type.getFields()[key];
|
|
73170
|
-
const unwrapped = unwrapType(config2, fieldType.type);
|
|
73171
|
-
return AST10.tsPropertySignature(
|
|
73172
|
-
AST10.identifier(key),
|
|
73173
|
-
AST10.tsTypeAnnotation(
|
|
73174
|
-
scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
|
|
73175
|
-
)
|
|
73176
|
-
);
|
|
73177
|
-
})
|
|
73178
|
-
);
|
|
73179
|
-
} else if (typeName === "__ROOT__") {
|
|
73180
|
-
idFields = AST10.tsTypeLiteral([]);
|
|
73181
|
-
}
|
|
73182
|
-
let fields = AST10.tsTypeLiteral([]);
|
|
73183
|
-
if (graphql17.isObjectType(type)) {
|
|
73184
|
-
fields = AST10.tsTypeLiteral(
|
|
73185
|
-
Object.entries(type.getFields()).map(
|
|
73186
|
-
([key, fieldType]) => {
|
|
73187
|
-
const unwrapped = unwrapType(config2, fieldType.type);
|
|
73188
|
-
let typeOptions = AST10.tsUnionType([]);
|
|
73189
|
-
if (graphql17.isScalarType(unwrapped.type)) {
|
|
73190
|
-
typeOptions.types.push(
|
|
73191
|
-
scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
|
|
73192
|
-
);
|
|
73193
|
-
} else if (graphql17.isEnumType(unwrapped.type)) {
|
|
73194
|
-
typeOptions.types.push(
|
|
73195
|
-
AST10.tsTypeReference(AST10.identifier(unwrapped.type.name))
|
|
73196
|
-
);
|
|
73197
|
-
} else if (!graphql17.isAbstractType(unwrapped.type)) {
|
|
73198
|
-
typeOptions.types.push(record(unwrapped.type.name));
|
|
73199
|
-
} else {
|
|
73200
|
-
typeOptions.types.push(
|
|
73201
|
-
...config2.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
|
|
73202
|
-
);
|
|
73203
|
-
}
|
|
73204
|
-
for (const wrapper of unwrapped.wrappers) {
|
|
73205
|
-
if (wrapper === "Nullable" /* Nullable */) {
|
|
73206
|
-
typeOptions = AST10.tsParenthesizedType(
|
|
73207
|
-
AST10.tsUnionType([typeOptions, AST10.tsNullKeyword()])
|
|
73208
|
-
);
|
|
73209
|
-
} else if (wrapper === "List" /* List */) {
|
|
73210
|
-
typeOptions = AST10.tsArrayType(
|
|
73211
|
-
AST10.tsParenthesizedType(typeOptions)
|
|
73212
|
-
);
|
|
73213
|
-
}
|
|
73214
|
-
}
|
|
73215
|
-
if (typeOptions.type === "TSParenthesizedType") {
|
|
73216
|
-
typeOptions = typeOptions.typeAnnotation;
|
|
73217
|
-
}
|
|
73218
|
-
let args = AST10.tsNeverKeyword();
|
|
73219
|
-
if (fieldType.args?.length > 0) {
|
|
73220
|
-
args = AST10.tsTypeLiteral(
|
|
73221
|
-
fieldType.args.map((arg) => {
|
|
73222
|
-
addReferencedInputTypes(
|
|
73223
|
-
config2,
|
|
73224
|
-
"",
|
|
73225
|
-
body,
|
|
73226
|
-
visitedTypes,
|
|
73227
|
-
/* @__PURE__ */ new Set(),
|
|
73228
|
-
arg.type
|
|
73229
|
-
);
|
|
73230
|
-
const prop = AST10.tsPropertySignature(
|
|
73231
|
-
AST10.identifier(arg.name),
|
|
73232
|
-
AST10.tsTypeAnnotation(
|
|
73233
|
-
tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
|
|
73234
|
-
)
|
|
73235
|
-
);
|
|
73236
|
-
const unwrapped2 = unwrapType(config2, arg.type);
|
|
73237
|
-
prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
|
|
73238
|
-
return prop;
|
|
73239
|
-
})
|
|
73240
|
-
);
|
|
73241
|
-
}
|
|
73242
|
-
return AST10.tsPropertySignature(
|
|
73243
|
-
AST10.identifier(key),
|
|
73244
|
-
AST10.tsTypeAnnotation(
|
|
73245
|
-
AST10.tsTypeLiteral([
|
|
73246
|
-
AST10.tsPropertySignature(
|
|
73247
|
-
AST10.identifier("type"),
|
|
73248
|
-
AST10.tsTypeAnnotation(typeOptions)
|
|
73249
|
-
),
|
|
73250
|
-
AST10.tsPropertySignature(
|
|
73251
|
-
AST10.identifier("args"),
|
|
73252
|
-
AST10.tsTypeAnnotation(args)
|
|
73253
|
-
)
|
|
73254
|
-
])
|
|
73255
|
-
)
|
|
73256
|
-
);
|
|
73257
|
-
}
|
|
73258
|
-
)
|
|
73259
|
-
);
|
|
73260
|
-
}
|
|
73261
|
-
return AST10.tsPropertySignature(
|
|
73262
|
-
AST10.identifier(typeName),
|
|
73263
|
-
AST10.tsTypeAnnotation(
|
|
73264
|
-
AST10.tsTypeLiteral([
|
|
73265
|
-
AST10.tsPropertySignature(
|
|
73266
|
-
AST10.identifier("idFields"),
|
|
73267
|
-
AST10.tsTypeAnnotation(idFields)
|
|
73268
|
-
),
|
|
73269
|
-
AST10.tsPropertySignature(
|
|
73270
|
-
AST10.identifier("fields"),
|
|
73271
|
-
AST10.tsTypeAnnotation(fields)
|
|
73272
|
-
)
|
|
73273
|
-
])
|
|
73274
|
-
)
|
|
73275
|
-
);
|
|
73276
|
-
})
|
|
73277
|
-
);
|
|
73278
|
-
}
|
|
73279
|
-
function listDefinitions(config2, docs) {
|
|
73280
|
-
const lists = [];
|
|
73281
|
-
const visitedLists = /* @__PURE__ */ new Set();
|
|
73282
|
-
for (const doc of docs) {
|
|
73283
|
-
graphql17.visit(doc.document, {
|
|
73284
|
-
Directive(node, key, parent, path2, ancestors) {
|
|
73285
|
-
if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
|
|
73286
|
-
return;
|
|
73287
|
-
}
|
|
73288
|
-
const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
|
|
73289
|
-
const nameValue = nameArg?.value?.value || "";
|
|
73290
|
-
if (!nameValue || visitedLists.has(nameValue)) {
|
|
73291
|
-
return;
|
|
73292
|
-
}
|
|
73293
|
-
visitedLists.add(nameValue);
|
|
73294
|
-
const parentType = parentTypeFromAncestors(
|
|
73295
|
-
config2.schema,
|
|
73296
|
-
doc.filename,
|
|
73297
|
-
ancestors.slice(0, -1)
|
|
73298
|
-
);
|
|
73299
|
-
const targetField = ancestors[ancestors.length - 1];
|
|
73300
|
-
const targetFieldDefinition = parentType.getFields()[targetField.name.value];
|
|
73301
|
-
const { type: listType } = unwrapType(config2, targetFieldDefinition.type);
|
|
73302
|
-
const possibleTypes = [];
|
|
73303
|
-
if (graphql17.isAbstractType(listType)) {
|
|
73304
|
-
possibleTypes.push(
|
|
73305
|
-
...config2.schema.getPossibleTypes(listType).map((possible) => possible.name)
|
|
73306
|
-
);
|
|
73307
|
-
} else {
|
|
73308
|
-
possibleTypes.push(listType.name);
|
|
73309
|
-
}
|
|
73310
|
-
lists.push(
|
|
73311
|
-
AST10.tsPropertySignature(
|
|
73312
|
-
AST10.identifier(nameValue),
|
|
73313
|
-
AST10.tsTypeAnnotation(
|
|
73314
|
-
AST10.tsTypeLiteral([
|
|
73315
|
-
AST10.tsPropertySignature(
|
|
73316
|
-
AST10.identifier("types"),
|
|
73317
|
-
AST10.tsTypeAnnotation(
|
|
73318
|
-
AST10.tsUnionType(
|
|
73319
|
-
possibleTypes.map(
|
|
73320
|
-
(possible) => AST10.tsLiteralType(AST10.stringLiteral(possible))
|
|
73321
|
-
)
|
|
73322
|
-
)
|
|
73323
|
-
)
|
|
73324
|
-
),
|
|
73325
|
-
AST10.tsPropertySignature(
|
|
73326
|
-
AST10.identifier("filters"),
|
|
73327
|
-
AST10.tsTypeAnnotation(
|
|
73328
|
-
targetFieldDefinition.args.length === 0 ? AST10.tsNeverKeyword() : AST10.tsTypeLiteral(
|
|
73329
|
-
targetFieldDefinition.args.map((arg) => {
|
|
73330
|
-
const argDef = AST10.tsPropertySignature(
|
|
73331
|
-
AST10.identifier(arg.name),
|
|
73332
|
-
AST10.tsTypeAnnotation(
|
|
73333
|
-
tsTypeReference(
|
|
73334
|
-
config2,
|
|
73335
|
-
/* @__PURE__ */ new Set(),
|
|
73336
|
-
arg
|
|
73337
|
-
)
|
|
73338
|
-
)
|
|
73339
|
-
);
|
|
73340
|
-
argDef.optional = true;
|
|
73341
|
-
return argDef;
|
|
73342
|
-
})
|
|
73343
|
-
)
|
|
73344
|
-
)
|
|
73345
|
-
)
|
|
73346
|
-
])
|
|
73347
|
-
)
|
|
73348
|
-
)
|
|
73402
|
+
function scalarPropertyValue(config2, missingScalars, target) {
|
|
73403
|
+
switch (target.name) {
|
|
73404
|
+
case "String": {
|
|
73405
|
+
return AST7.tsStringKeyword();
|
|
73406
|
+
}
|
|
73407
|
+
case "Int": {
|
|
73408
|
+
return AST7.tsNumberKeyword();
|
|
73409
|
+
}
|
|
73410
|
+
case "Float": {
|
|
73411
|
+
return AST7.tsNumberKeyword();
|
|
73412
|
+
}
|
|
73413
|
+
case "Boolean": {
|
|
73414
|
+
return AST7.tsBooleanKeyword();
|
|
73415
|
+
}
|
|
73416
|
+
case "ID": {
|
|
73417
|
+
return AST7.tsStringKeyword();
|
|
73418
|
+
}
|
|
73419
|
+
default: {
|
|
73420
|
+
if (graphql15.isNonNullType(target) && "ofType" in target) {
|
|
73421
|
+
return scalarPropertyValue(
|
|
73422
|
+
config2,
|
|
73423
|
+
missingScalars,
|
|
73424
|
+
target.ofType
|
|
73349
73425
|
);
|
|
73350
73426
|
}
|
|
73351
|
-
|
|
73427
|
+
if (config2.scalars?.[target.name]) {
|
|
73428
|
+
return AST7.tsTypeReference(AST7.identifier(config2.scalars?.[target.name].type));
|
|
73429
|
+
}
|
|
73430
|
+
missingScalars.add(target.name);
|
|
73431
|
+
return AST7.tsAnyKeyword();
|
|
73432
|
+
}
|
|
73352
73433
|
}
|
|
73353
|
-
return AST10.tsTypeLiteral(lists);
|
|
73354
73434
|
}
|
|
73355
|
-
|
|
73356
|
-
|
|
73357
|
-
|
|
73358
|
-
|
|
73359
|
-
|
|
73360
|
-
|
|
73361
|
-
|
|
73362
|
-
|
|
73363
|
-
|
|
73435
|
+
|
|
73436
|
+
// src/codegen/generators/typescript/typeReference.ts
|
|
73437
|
+
var AST8 = recast8.types.builders;
|
|
73438
|
+
function tsTypeReference(config2, missingScalars, definition) {
|
|
73439
|
+
const { type, wrappers } = unwrapType(config2, definition.type);
|
|
73440
|
+
let result;
|
|
73441
|
+
if (graphql16.isScalarType(type)) {
|
|
73442
|
+
result = scalarPropertyValue(config2, missingScalars, type);
|
|
73443
|
+
} else {
|
|
73444
|
+
result = AST8.tsTypeReference(AST8.identifier(type.name));
|
|
73445
|
+
}
|
|
73446
|
+
for (const toWrap of wrappers) {
|
|
73447
|
+
if (toWrap === "NonNull" /* NonNull */) {
|
|
73448
|
+
continue;
|
|
73449
|
+
} else if (toWrap === "Nullable" /* Nullable */) {
|
|
73450
|
+
result = nullableField(result, true);
|
|
73451
|
+
} else if (toWrap === "List" /* List */) {
|
|
73452
|
+
result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
|
|
73453
|
+
}
|
|
73454
|
+
}
|
|
73455
|
+
return result;
|
|
73456
|
+
}
|
|
73457
|
+
|
|
73458
|
+
// src/codegen/generators/typescript/addReferencedInputTypes.ts
|
|
73459
|
+
var AST9 = recast9.types.builders;
|
|
73460
|
+
function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, rootType) {
|
|
73461
|
+
const { type } = unwrapType(config2, rootType);
|
|
73462
|
+
if (graphql17.isScalarType(type)) {
|
|
73463
|
+
return;
|
|
73464
|
+
}
|
|
73465
|
+
if (visitedTypes.has(type.name)) {
|
|
73466
|
+
return;
|
|
73467
|
+
}
|
|
73468
|
+
if (graphql17.isUnionType(type)) {
|
|
73469
|
+
throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
|
|
73470
|
+
}
|
|
73471
|
+
visitedTypes.add(type.name);
|
|
73472
|
+
if (graphql17.isEnumType(type)) {
|
|
73473
|
+
ensureImports({
|
|
73474
|
+
config: config2,
|
|
73475
|
+
body,
|
|
73476
|
+
import: [type.name],
|
|
73477
|
+
sourceModule: "$houdini/graphql/enums",
|
|
73478
|
+
importKind: "type"
|
|
73479
|
+
});
|
|
73480
|
+
return;
|
|
73481
|
+
}
|
|
73482
|
+
const members = [];
|
|
73483
|
+
for (const field of Object.values(type.getFields())) {
|
|
73484
|
+
addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, field.type);
|
|
73485
|
+
members.push(
|
|
73486
|
+
AST9.tsPropertySignature(
|
|
73487
|
+
AST9.identifier(field.name),
|
|
73488
|
+
AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
|
|
73489
|
+
graphql17.isNullableType(field.type)
|
|
73490
|
+
)
|
|
73491
|
+
);
|
|
73492
|
+
}
|
|
73493
|
+
body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
|
|
73364
73494
|
}
|
|
73365
73495
|
|
|
73366
73496
|
// src/codegen/generators/typescript/inlineType.ts
|
|
73367
73497
|
var graphql18 = __toESM(require_graphql2(), 1);
|
|
73368
|
-
var
|
|
73369
|
-
var
|
|
73498
|
+
var recast10 = __toESM(require_main2(), 1);
|
|
73499
|
+
var AST10 = recast10.types.builders;
|
|
73370
73500
|
var fragmentKey = "$fragments";
|
|
73371
73501
|
function inlineType({
|
|
73372
73502
|
config: config2,
|
|
@@ -73395,7 +73525,7 @@ function inlineType({
|
|
|
73395
73525
|
});
|
|
73396
73526
|
visitedTypes.add(type.name);
|
|
73397
73527
|
}
|
|
73398
|
-
result =
|
|
73528
|
+
result = AST10.tsTypeReference(AST10.identifier(type.name));
|
|
73399
73529
|
} else if (selections) {
|
|
73400
73530
|
const rootObj = type;
|
|
73401
73531
|
const inlineFragments = {};
|
|
@@ -73446,7 +73576,7 @@ function inlineType({
|
|
|
73446
73576
|
selectedFields.push(selection2);
|
|
73447
73577
|
}
|
|
73448
73578
|
}
|
|
73449
|
-
result =
|
|
73579
|
+
result = AST10.tsTypeLiteral([
|
|
73450
73580
|
...(selectedFields || []).filter(
|
|
73451
73581
|
(field) => field.kind === "Field"
|
|
73452
73582
|
).map((selection2) => {
|
|
@@ -73466,9 +73596,9 @@ function inlineType({
|
|
|
73466
73596
|
allOptional
|
|
73467
73597
|
});
|
|
73468
73598
|
const prop = readonlyProperty(
|
|
73469
|
-
|
|
73470
|
-
|
|
73471
|
-
|
|
73599
|
+
AST10.tsPropertySignature(
|
|
73600
|
+
AST10.identifier(attributeName),
|
|
73601
|
+
AST10.tsTypeAnnotation(attributeType)
|
|
73472
73602
|
),
|
|
73473
73603
|
allowReadonly
|
|
73474
73604
|
);
|
|
@@ -73482,15 +73612,15 @@ function inlineType({
|
|
|
73482
73612
|
if (includeFragments && fragmentSpreads && fragmentSpreads.length) {
|
|
73483
73613
|
result.members.push(
|
|
73484
73614
|
readonlyProperty(
|
|
73485
|
-
|
|
73486
|
-
|
|
73487
|
-
|
|
73488
|
-
|
|
73615
|
+
AST10.tsPropertySignature(
|
|
73616
|
+
AST10.identifier(fragmentKey),
|
|
73617
|
+
AST10.tsTypeAnnotation(
|
|
73618
|
+
AST10.tsTypeLiteral(
|
|
73489
73619
|
(fragmentSpreads || []).map(
|
|
73490
|
-
(fragmentSpread) =>
|
|
73491
|
-
|
|
73492
|
-
|
|
73493
|
-
|
|
73620
|
+
(fragmentSpread) => AST10.tsPropertySignature(
|
|
73621
|
+
AST10.identifier(fragmentSpread.name.value),
|
|
73622
|
+
AST10.tsTypeAnnotation(
|
|
73623
|
+
AST10.tsLiteralType(AST10.booleanLiteral(true))
|
|
73494
73624
|
)
|
|
73495
73625
|
)
|
|
73496
73626
|
)
|
|
@@ -73536,9 +73666,9 @@ function inlineType({
|
|
|
73536
73666
|
}
|
|
73537
73667
|
objectType.members.push(
|
|
73538
73668
|
readonlyProperty(
|
|
73539
|
-
|
|
73540
|
-
|
|
73541
|
-
|
|
73669
|
+
AST10.tsPropertySignature(
|
|
73670
|
+
AST10.identifier("__typename"),
|
|
73671
|
+
AST10.tsTypeAnnotation(AST10.tsLiteralType(AST10.stringLiteral(typeName)))
|
|
73542
73672
|
),
|
|
73543
73673
|
allowReadonly
|
|
73544
73674
|
)
|
|
@@ -73549,8 +73679,8 @@ function inlineType({
|
|
|
73549
73679
|
if (Object.keys(inlineFragmentSelections).length > 0) {
|
|
73550
73680
|
let selectionTypes = Object.entries(inlineFragmentSelections).map(
|
|
73551
73681
|
([typeName, { type: type2, tsType }]) => {
|
|
73552
|
-
return
|
|
73553
|
-
|
|
73682
|
+
return AST10.tsParenthesizedType(
|
|
73683
|
+
AST10.tsIntersectionType(
|
|
73554
73684
|
[tsType].flatMap((type3) => {
|
|
73555
73685
|
if (type3.type === "TSUnionType") {
|
|
73556
73686
|
return type3.types.filter(
|
|
@@ -73563,9 +73693,9 @@ function inlineType({
|
|
|
73563
73693
|
);
|
|
73564
73694
|
}
|
|
73565
73695
|
);
|
|
73566
|
-
result =
|
|
73696
|
+
result = AST10.tsIntersectionType([
|
|
73567
73697
|
result,
|
|
73568
|
-
|
|
73698
|
+
AST10.tsParenthesizedType(AST10.tsUnionType(selectionTypes))
|
|
73569
73699
|
]);
|
|
73570
73700
|
}
|
|
73571
73701
|
} else {
|
|
@@ -73577,7 +73707,7 @@ function inlineType({
|
|
|
73577
73707
|
} else if (toWrap === "NonNull" /* NonNull */) {
|
|
73578
73708
|
continue;
|
|
73579
73709
|
} else if (toWrap === "List" /* List */) {
|
|
73580
|
-
result =
|
|
73710
|
+
result = AST10.tsArrayType(AST10.tsParenthesizedType(result));
|
|
73581
73711
|
}
|
|
73582
73712
|
}
|
|
73583
73713
|
return result;
|
|
@@ -73621,9 +73751,9 @@ function selectionTypeInfo(schema, filepath, rootType, selection2) {
|
|
|
73621
73751
|
return { field, type: selectionType };
|
|
73622
73752
|
}
|
|
73623
73753
|
|
|
73624
|
-
// src/codegen/generators/typescript/
|
|
73625
|
-
var
|
|
73626
|
-
async function
|
|
73754
|
+
// src/codegen/generators/typescript/documentTypes.ts
|
|
73755
|
+
var AST11 = recast11.types.builders;
|
|
73756
|
+
async function generateDocumentTypes(config2, docs) {
|
|
73627
73757
|
const typePaths = [];
|
|
73628
73758
|
const fragmentDefinitions = {};
|
|
73629
73759
|
for (const document of docs) {
|
|
@@ -73640,7 +73770,7 @@ async function typescriptGenerator(config2, docs) {
|
|
|
73640
73770
|
return;
|
|
73641
73771
|
}
|
|
73642
73772
|
const typeDefPath = config2.artifactTypePath(originalDocument);
|
|
73643
|
-
const program3 =
|
|
73773
|
+
const program3 = AST11.program([]);
|
|
73644
73774
|
const visitedTypes = /* @__PURE__ */ new Set();
|
|
73645
73775
|
let definition = originalDocument.definitions.find(
|
|
73646
73776
|
(def) => (def.kind === "OperationDefinition" || def.kind === "FragmentDefinition") && def.name?.value === name2
|
|
@@ -73673,21 +73803,21 @@ async function typescriptGenerator(config2, docs) {
|
|
|
73673
73803
|
missingScalars
|
|
73674
73804
|
);
|
|
73675
73805
|
}
|
|
73676
|
-
await fs_exports.writeFile(typeDefPath,
|
|
73806
|
+
await fs_exports.writeFile(typeDefPath, recast11.print(program3).code);
|
|
73677
73807
|
typePaths.push(typeDefPath);
|
|
73678
73808
|
})
|
|
73679
73809
|
);
|
|
73680
|
-
const typeIndex =
|
|
73810
|
+
const typeIndex = AST11.program(
|
|
73681
73811
|
typePaths.sort((a, b) => a.localeCompare(b)).map((typePath) => {
|
|
73682
|
-
return
|
|
73683
|
-
|
|
73812
|
+
return AST11.exportAllDeclaration(
|
|
73813
|
+
AST11.literal(
|
|
73684
73814
|
"./" + path_exports.relative(path_exports.resolve(config2.typeIndexPath, ".."), typePath).replace(/\.[^/.]+\.[^/.]+$/, "")
|
|
73685
73815
|
),
|
|
73686
73816
|
null
|
|
73687
73817
|
);
|
|
73688
73818
|
}).concat([
|
|
73689
|
-
|
|
73690
|
-
|
|
73819
|
+
AST11.exportAllDeclaration(AST11.literal("./runtime"), null),
|
|
73820
|
+
AST11.exportAllDeclaration(AST11.literal("./graphql"), null)
|
|
73691
73821
|
])
|
|
73692
73822
|
);
|
|
73693
73823
|
const export_default_as = ({ module, as }) => `
|
|
@@ -73696,7 +73826,7 @@ export { default as ${as} } from "${module}"
|
|
|
73696
73826
|
const export_star_from = ({ module }) => `
|
|
73697
73827
|
export * from "${module}"
|
|
73698
73828
|
`;
|
|
73699
|
-
let indexContent =
|
|
73829
|
+
let indexContent = recast11.print(typeIndex).code;
|
|
73700
73830
|
for (const plugin of config2.plugins) {
|
|
73701
73831
|
if (!plugin.index_file) {
|
|
73702
73832
|
continue;
|
|
@@ -73717,7 +73847,6 @@ export * from "${module}"
|
|
|
73717
73847
|
}
|
|
73718
73848
|
}
|
|
73719
73849
|
await fs_exports.writeFile(config2.typeIndexPath, indexContent);
|
|
73720
|
-
await imperativeCacheTypef(config2, docs);
|
|
73721
73850
|
if (missingScalars.size > 0) {
|
|
73722
73851
|
console.warn(`\u26A0\uFE0F Missing definitions for the following scalars: ${[...missingScalars].join(
|
|
73723
73852
|
", "
|
|
@@ -73759,23 +73888,23 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
|
|
|
73759
73888
|
const optimisticTypeName = `${definition.name.value}$optimistic`;
|
|
73760
73889
|
const hasInputs = definition.variableDefinitions && definition.variableDefinitions.length > 0;
|
|
73761
73890
|
body.push(
|
|
73762
|
-
|
|
73763
|
-
|
|
73764
|
-
|
|
73765
|
-
|
|
73891
|
+
AST11.exportNamedDeclaration(
|
|
73892
|
+
AST11.tsTypeAliasDeclaration(
|
|
73893
|
+
AST11.identifier(definition.name.value),
|
|
73894
|
+
AST11.tsTypeLiteral([
|
|
73766
73895
|
readonlyProperty(
|
|
73767
|
-
|
|
73768
|
-
|
|
73769
|
-
|
|
73896
|
+
AST11.tsPropertySignature(
|
|
73897
|
+
AST11.stringLiteral("input"),
|
|
73898
|
+
AST11.tsTypeAnnotation(AST11.tsTypeReference(AST11.identifier(inputTypeName)))
|
|
73770
73899
|
)
|
|
73771
73900
|
),
|
|
73772
73901
|
readonlyProperty(
|
|
73773
|
-
|
|
73774
|
-
|
|
73775
|
-
|
|
73776
|
-
definition.operation === "mutation" ?
|
|
73777
|
-
|
|
73778
|
-
|
|
73902
|
+
AST11.tsPropertySignature(
|
|
73903
|
+
AST11.stringLiteral("result"),
|
|
73904
|
+
AST11.tsTypeAnnotation(
|
|
73905
|
+
definition.operation === "mutation" ? AST11.tsTypeReference(AST11.identifier(shapeTypeName)) : AST11.tsUnionType([
|
|
73906
|
+
AST11.tsTypeReference(AST11.identifier(shapeTypeName)),
|
|
73907
|
+
AST11.tsUndefinedKeyword()
|
|
73779
73908
|
])
|
|
73780
73909
|
)
|
|
73781
73910
|
)
|
|
@@ -73783,9 +73912,9 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
|
|
|
73783
73912
|
])
|
|
73784
73913
|
)
|
|
73785
73914
|
),
|
|
73786
|
-
|
|
73787
|
-
|
|
73788
|
-
|
|
73915
|
+
AST11.exportNamedDeclaration(
|
|
73916
|
+
AST11.tsTypeAliasDeclaration(
|
|
73917
|
+
AST11.identifier(shapeTypeName),
|
|
73789
73918
|
inlineType({
|
|
73790
73919
|
config: config2,
|
|
73791
73920
|
filepath,
|
|
@@ -73813,15 +73942,15 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
|
|
|
73813
73942
|
);
|
|
73814
73943
|
}
|
|
73815
73944
|
body.push(
|
|
73816
|
-
|
|
73817
|
-
|
|
73818
|
-
|
|
73819
|
-
|
|
73945
|
+
AST11.exportNamedDeclaration(
|
|
73946
|
+
AST11.tsTypeAliasDeclaration(
|
|
73947
|
+
AST11.identifier(inputTypeName),
|
|
73948
|
+
AST11.tsTypeLiteral(
|
|
73820
73949
|
(definition.variableDefinitions || []).map(
|
|
73821
73950
|
(definition2) => {
|
|
73822
|
-
return
|
|
73823
|
-
|
|
73824
|
-
|
|
73951
|
+
return AST11.tsPropertySignature(
|
|
73952
|
+
AST11.identifier(definition2.variable.name.value),
|
|
73953
|
+
AST11.tsTypeAnnotation(
|
|
73825
73954
|
tsTypeReference(config2, missingScalars, definition2)
|
|
73826
73955
|
),
|
|
73827
73956
|
definition2.type.kind !== "NonNullType"
|
|
@@ -73834,16 +73963,16 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
|
|
|
73834
73963
|
);
|
|
73835
73964
|
} else {
|
|
73836
73965
|
body.push(
|
|
73837
|
-
|
|
73838
|
-
|
|
73966
|
+
AST11.exportNamedDeclaration(
|
|
73967
|
+
AST11.tsTypeAliasDeclaration(AST11.identifier(inputTypeName), AST11.tsNullKeyword())
|
|
73839
73968
|
)
|
|
73840
73969
|
);
|
|
73841
73970
|
}
|
|
73842
73971
|
if (definition.operation === "mutation") {
|
|
73843
73972
|
body.push(
|
|
73844
|
-
|
|
73845
|
-
|
|
73846
|
-
|
|
73973
|
+
AST11.exportNamedDeclaration(
|
|
73974
|
+
AST11.tsTypeAliasDeclaration(
|
|
73975
|
+
AST11.identifier(optimisticTypeName),
|
|
73847
73976
|
inlineType({
|
|
73848
73977
|
config: config2,
|
|
73849
73978
|
filepath,
|
|
@@ -73869,65 +73998,463 @@ async function generateFragmentTypeDefs(config2, filepath, body, selections, def
|
|
|
73869
73998
|
}
|
|
73870
73999
|
const propTypeName = definition.name.value;
|
|
73871
74000
|
const shapeTypeName = `${definition.name.value}$data`;
|
|
74001
|
+
const inputTypeName = `${definition.name.value}$input`;
|
|
73872
74002
|
const type = config2.schema.getType(definition.typeCondition.name.value);
|
|
73873
74003
|
if (!type) {
|
|
73874
74004
|
throw new Error("Should not get here");
|
|
73875
74005
|
}
|
|
74006
|
+
let extraExports = [];
|
|
74007
|
+
let directive = definition.directives?.find(
|
|
74008
|
+
(directive2) => directive2.name.value === config2.argumentsDirective
|
|
74009
|
+
);
|
|
74010
|
+
if (directive) {
|
|
74011
|
+
extraExports.push(
|
|
74012
|
+
AST11.exportNamedDeclaration(
|
|
74013
|
+
AST11.tsTypeAliasDeclaration(
|
|
74014
|
+
AST11.identifier(inputTypeName),
|
|
74015
|
+
AST11.tsTypeLiteral(
|
|
74016
|
+
(fragmentArgumentsDefinitions(config2, filepath, definition) || []).map(
|
|
74017
|
+
(definition2) => {
|
|
74018
|
+
return AST11.tsPropertySignature(
|
|
74019
|
+
AST11.identifier(definition2.variable.name.value),
|
|
74020
|
+
AST11.tsTypeAnnotation(
|
|
74021
|
+
tsTypeReference(config2, missingScalars, definition2)
|
|
74022
|
+
),
|
|
74023
|
+
definition2.type.kind !== "NonNullType"
|
|
74024
|
+
);
|
|
74025
|
+
}
|
|
74026
|
+
)
|
|
74027
|
+
)
|
|
74028
|
+
)
|
|
74029
|
+
)
|
|
74030
|
+
);
|
|
74031
|
+
}
|
|
73876
74032
|
body.push(
|
|
73877
|
-
|
|
73878
|
-
|
|
73879
|
-
|
|
73880
|
-
|
|
74033
|
+
...extraExports,
|
|
74034
|
+
AST11.exportNamedDeclaration(
|
|
74035
|
+
AST11.tsTypeAliasDeclaration(
|
|
74036
|
+
AST11.identifier(propTypeName),
|
|
74037
|
+
AST11.tsTypeLiteral([
|
|
73881
74038
|
readonlyProperty(
|
|
73882
|
-
|
|
73883
|
-
|
|
73884
|
-
|
|
73885
|
-
|
|
74039
|
+
AST11.tsPropertySignature(
|
|
74040
|
+
AST11.stringLiteral("shape"),
|
|
74041
|
+
AST11.tsTypeAnnotation(
|
|
74042
|
+
AST11.tsTypeReference(AST11.identifier(shapeTypeName))
|
|
73886
74043
|
),
|
|
73887
74044
|
true
|
|
73888
74045
|
)
|
|
73889
74046
|
),
|
|
73890
74047
|
readonlyProperty(
|
|
73891
|
-
|
|
73892
|
-
|
|
74048
|
+
AST11.tsPropertySignature(
|
|
74049
|
+
AST11.stringLiteral(fragmentKey),
|
|
74050
|
+
AST11.tsTypeAnnotation(
|
|
74051
|
+
AST11.tsTypeLiteral([
|
|
74052
|
+
AST11.tsPropertySignature(
|
|
74053
|
+
AST11.stringLiteral(propTypeName),
|
|
74054
|
+
AST11.tsTypeAnnotation(
|
|
74055
|
+
AST11.tsLiteralType(AST11.booleanLiteral(true))
|
|
74056
|
+
)
|
|
74057
|
+
)
|
|
74058
|
+
])
|
|
74059
|
+
)
|
|
74060
|
+
)
|
|
74061
|
+
)
|
|
74062
|
+
])
|
|
74063
|
+
)
|
|
74064
|
+
),
|
|
74065
|
+
AST11.exportNamedDeclaration(
|
|
74066
|
+
AST11.tsTypeAliasDeclaration(
|
|
74067
|
+
AST11.identifier(shapeTypeName),
|
|
74068
|
+
inlineType({
|
|
74069
|
+
config: config2,
|
|
74070
|
+
filepath,
|
|
74071
|
+
rootType: type,
|
|
74072
|
+
selections,
|
|
74073
|
+
root: true,
|
|
74074
|
+
allowReadonly: true,
|
|
74075
|
+
body,
|
|
74076
|
+
visitedTypes,
|
|
74077
|
+
missingScalars,
|
|
74078
|
+
includeFragments: true
|
|
74079
|
+
})
|
|
74080
|
+
)
|
|
74081
|
+
)
|
|
74082
|
+
);
|
|
74083
|
+
}
|
|
74084
|
+
}
|
|
74085
|
+
|
|
74086
|
+
// src/codegen/generators/typescript/imperativeTypeDef.ts
|
|
74087
|
+
var graphql19 = __toESM(require_graphql2(), 1);
|
|
74088
|
+
var recast12 = __toESM(require_main2(), 1);
|
|
74089
|
+
var AST12 = recast12.types.builders;
|
|
74090
|
+
async function imperativeCacheTypef(config2, docs) {
|
|
74091
|
+
const returnType = (doc) => config2.plugins.find((plugin) => plugin.graphql_tag_return)?.graphql_tag_return?.({
|
|
74092
|
+
config: config2,
|
|
74093
|
+
doc,
|
|
74094
|
+
ensure_import({ identifier, module }) {
|
|
74095
|
+
ensureImports({
|
|
74096
|
+
config: config2,
|
|
74097
|
+
body,
|
|
74098
|
+
sourceModule: module,
|
|
74099
|
+
import: [identifier]
|
|
74100
|
+
});
|
|
74101
|
+
}
|
|
74102
|
+
}) ?? "any";
|
|
74103
|
+
const target = path_exports.join(config2.runtimeDirectory, "generated.d.ts");
|
|
74104
|
+
const body = [];
|
|
74105
|
+
const declaration = AST12.tsTypeAliasDeclaration(
|
|
74106
|
+
AST12.identifier(CacheTypeDefName),
|
|
74107
|
+
AST12.tsTypeLiteral([
|
|
74108
|
+
AST12.tsPropertySignature(
|
|
74109
|
+
AST12.identifier("types"),
|
|
74110
|
+
AST12.tsTypeAnnotation(typeDefinitions(config2, body, docs, returnType))
|
|
74111
|
+
),
|
|
74112
|
+
AST12.tsPropertySignature(
|
|
74113
|
+
AST12.identifier("lists"),
|
|
74114
|
+
AST12.tsTypeAnnotation(listDefinitions(config2, docs))
|
|
74115
|
+
),
|
|
74116
|
+
AST12.tsPropertySignature(
|
|
74117
|
+
AST12.identifier("queries"),
|
|
74118
|
+
AST12.tsTypeAnnotation(queryDefinitions(config2, body, docs, returnType))
|
|
74119
|
+
)
|
|
74120
|
+
])
|
|
74121
|
+
);
|
|
74122
|
+
declaration.declare = true;
|
|
74123
|
+
const importRecord = AST12.importDeclaration(
|
|
74124
|
+
[AST12.importSpecifier(AST12.identifier("Record"))],
|
|
74125
|
+
AST12.stringLiteral("./public/record")
|
|
74126
|
+
);
|
|
74127
|
+
importRecord.importKind = "type";
|
|
74128
|
+
await fs_exports.writeFile(
|
|
74129
|
+
target,
|
|
74130
|
+
recast12.prettyPrint(
|
|
74131
|
+
AST12.program([importRecord, ...body, AST12.exportNamedDeclaration(declaration)])
|
|
74132
|
+
).code
|
|
74133
|
+
);
|
|
74134
|
+
}
|
|
74135
|
+
function typeDefinitions(config2, body, docs, returnType) {
|
|
74136
|
+
const operationTypes = [config2.schema.getMutationType(), config2.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
|
|
74137
|
+
const visitedTypes = /* @__PURE__ */ new Set();
|
|
74138
|
+
const types16 = Object.values(config2.schema.getTypeMap()).filter(
|
|
74139
|
+
(type) => !graphql19.isAbstractType(type) && !graphql19.isScalarType(type) && !graphql19.isEnumType(type) && !graphql19.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
|
|
74140
|
+
);
|
|
74141
|
+
const fragmentMap = fragmentListMap(
|
|
74142
|
+
config2,
|
|
74143
|
+
types16.map((type) => type.name),
|
|
74144
|
+
body,
|
|
74145
|
+
docs,
|
|
74146
|
+
returnType
|
|
74147
|
+
);
|
|
74148
|
+
return AST12.tsTypeLiteral(
|
|
74149
|
+
types16.map((type) => {
|
|
74150
|
+
let typeName = type.name;
|
|
74151
|
+
if (config2.schema.getQueryType() && config2.schema.getQueryType()?.name === type.name) {
|
|
74152
|
+
typeName = "__ROOT__";
|
|
74153
|
+
}
|
|
74154
|
+
let idFields = AST12.tsNeverKeyword();
|
|
74155
|
+
const keys = keyFieldsForType(config2.configFile, type.name);
|
|
74156
|
+
if (graphql19.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
|
|
74157
|
+
idFields = AST12.tsTypeLiteral(
|
|
74158
|
+
keys.map((key) => {
|
|
74159
|
+
const fieldType = type.getFields()[key];
|
|
74160
|
+
const unwrapped = unwrapType(config2, fieldType.type);
|
|
74161
|
+
return AST12.tsPropertySignature(
|
|
74162
|
+
AST12.identifier(key),
|
|
74163
|
+
AST12.tsTypeAnnotation(
|
|
74164
|
+
scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
|
|
74165
|
+
)
|
|
74166
|
+
);
|
|
74167
|
+
})
|
|
74168
|
+
);
|
|
74169
|
+
} else if (typeName === "__ROOT__") {
|
|
74170
|
+
idFields = AST12.tsTypeLiteral([]);
|
|
74171
|
+
}
|
|
74172
|
+
let fields = AST12.tsTypeLiteral([]);
|
|
74173
|
+
if (graphql19.isObjectType(type)) {
|
|
74174
|
+
fields = AST12.tsTypeLiteral(
|
|
74175
|
+
Object.entries(type.getFields()).map(
|
|
74176
|
+
([key, fieldType]) => {
|
|
74177
|
+
const unwrapped = unwrapType(config2, fieldType.type);
|
|
74178
|
+
let typeOptions = AST12.tsUnionType([]);
|
|
74179
|
+
if (graphql19.isScalarType(unwrapped.type)) {
|
|
74180
|
+
typeOptions.types.push(
|
|
74181
|
+
scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
|
|
74182
|
+
);
|
|
74183
|
+
} else if (graphql19.isEnumType(unwrapped.type)) {
|
|
74184
|
+
typeOptions.types.push(
|
|
74185
|
+
AST12.tsTypeReference(AST12.identifier(unwrapped.type.name))
|
|
74186
|
+
);
|
|
74187
|
+
} else if (!graphql19.isAbstractType(unwrapped.type)) {
|
|
74188
|
+
typeOptions.types.push(record(unwrapped.type.name));
|
|
74189
|
+
} else {
|
|
74190
|
+
typeOptions.types.push(
|
|
74191
|
+
...config2.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
|
|
74192
|
+
);
|
|
74193
|
+
}
|
|
74194
|
+
for (const wrapper of unwrapped.wrappers) {
|
|
74195
|
+
if (wrapper === "Nullable" /* Nullable */) {
|
|
74196
|
+
typeOptions = AST12.tsParenthesizedType(
|
|
74197
|
+
AST12.tsUnionType([typeOptions, AST12.tsNullKeyword()])
|
|
74198
|
+
);
|
|
74199
|
+
} else if (wrapper === "List" /* List */) {
|
|
74200
|
+
typeOptions = AST12.tsArrayType(
|
|
74201
|
+
AST12.tsParenthesizedType(typeOptions)
|
|
74202
|
+
);
|
|
74203
|
+
}
|
|
74204
|
+
}
|
|
74205
|
+
if (typeOptions.type === "TSParenthesizedType") {
|
|
74206
|
+
typeOptions = typeOptions.typeAnnotation;
|
|
74207
|
+
}
|
|
74208
|
+
let args = AST12.tsNeverKeyword();
|
|
74209
|
+
if (fieldType.args?.length > 0) {
|
|
74210
|
+
args = AST12.tsTypeLiteral(
|
|
74211
|
+
fieldType.args.map((arg) => {
|
|
74212
|
+
addReferencedInputTypes(
|
|
74213
|
+
config2,
|
|
74214
|
+
"",
|
|
74215
|
+
body,
|
|
74216
|
+
visitedTypes,
|
|
74217
|
+
/* @__PURE__ */ new Set(),
|
|
74218
|
+
arg.type
|
|
74219
|
+
);
|
|
74220
|
+
const prop = AST12.tsPropertySignature(
|
|
74221
|
+
AST12.identifier(arg.name),
|
|
74222
|
+
AST12.tsTypeAnnotation(
|
|
74223
|
+
tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
|
|
74224
|
+
)
|
|
74225
|
+
);
|
|
74226
|
+
const unwrapped2 = unwrapType(config2, arg.type);
|
|
74227
|
+
prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
|
|
74228
|
+
return prop;
|
|
74229
|
+
})
|
|
74230
|
+
);
|
|
74231
|
+
}
|
|
74232
|
+
return AST12.tsPropertySignature(
|
|
74233
|
+
AST12.identifier(key),
|
|
73893
74234
|
AST12.tsTypeAnnotation(
|
|
73894
74235
|
AST12.tsTypeLiteral([
|
|
73895
74236
|
AST12.tsPropertySignature(
|
|
73896
|
-
AST12.
|
|
73897
|
-
AST12.tsTypeAnnotation(
|
|
73898
|
-
|
|
73899
|
-
|
|
74237
|
+
AST12.identifier("type"),
|
|
74238
|
+
AST12.tsTypeAnnotation(typeOptions)
|
|
74239
|
+
),
|
|
74240
|
+
AST12.tsPropertySignature(
|
|
74241
|
+
AST12.identifier("args"),
|
|
74242
|
+
AST12.tsTypeAnnotation(args)
|
|
73900
74243
|
)
|
|
73901
74244
|
])
|
|
73902
74245
|
)
|
|
73903
|
-
)
|
|
74246
|
+
);
|
|
74247
|
+
}
|
|
74248
|
+
)
|
|
74249
|
+
);
|
|
74250
|
+
}
|
|
74251
|
+
return AST12.tsPropertySignature(
|
|
74252
|
+
AST12.identifier(typeName),
|
|
74253
|
+
AST12.tsTypeAnnotation(
|
|
74254
|
+
AST12.tsTypeLiteral([
|
|
74255
|
+
AST12.tsPropertySignature(
|
|
74256
|
+
AST12.identifier("idFields"),
|
|
74257
|
+
AST12.tsTypeAnnotation(idFields)
|
|
74258
|
+
),
|
|
74259
|
+
AST12.tsPropertySignature(
|
|
74260
|
+
AST12.identifier("fields"),
|
|
74261
|
+
AST12.tsTypeAnnotation(fields)
|
|
74262
|
+
),
|
|
74263
|
+
AST12.tsPropertySignature(
|
|
74264
|
+
AST12.identifier("fragments"),
|
|
74265
|
+
AST12.tsTypeAnnotation(fragmentMap[typeName] ?? AST12.tsTupleType([]))
|
|
73904
74266
|
)
|
|
73905
74267
|
])
|
|
73906
74268
|
)
|
|
74269
|
+
);
|
|
74270
|
+
})
|
|
74271
|
+
);
|
|
74272
|
+
}
|
|
74273
|
+
function listDefinitions(config2, docs) {
|
|
74274
|
+
const lists = [];
|
|
74275
|
+
const visitedLists = /* @__PURE__ */ new Set();
|
|
74276
|
+
for (const doc of docs) {
|
|
74277
|
+
graphql19.visit(doc.document, {
|
|
74278
|
+
Directive(node, key, parent, path2, ancestors) {
|
|
74279
|
+
if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
|
|
74280
|
+
return;
|
|
74281
|
+
}
|
|
74282
|
+
const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
|
|
74283
|
+
const nameValue = nameArg?.value?.value || "";
|
|
74284
|
+
if (!nameValue || visitedLists.has(nameValue)) {
|
|
74285
|
+
return;
|
|
74286
|
+
}
|
|
74287
|
+
visitedLists.add(nameValue);
|
|
74288
|
+
const parentType = parentTypeFromAncestors(
|
|
74289
|
+
config2.schema,
|
|
74290
|
+
doc.filename,
|
|
74291
|
+
ancestors.slice(0, -1)
|
|
74292
|
+
);
|
|
74293
|
+
const targetField = ancestors[ancestors.length - 1];
|
|
74294
|
+
const targetFieldDefinition = parentType.getFields()[targetField.name.value];
|
|
74295
|
+
const { type: listType } = unwrapType(config2, targetFieldDefinition.type);
|
|
74296
|
+
const possibleTypes = [];
|
|
74297
|
+
if (graphql19.isAbstractType(listType)) {
|
|
74298
|
+
possibleTypes.push(
|
|
74299
|
+
...config2.schema.getPossibleTypes(listType).map((possible) => possible.name)
|
|
74300
|
+
);
|
|
74301
|
+
} else {
|
|
74302
|
+
possibleTypes.push(listType.name);
|
|
74303
|
+
}
|
|
74304
|
+
lists.push(
|
|
74305
|
+
AST12.tsPropertySignature(
|
|
74306
|
+
AST12.identifier(nameValue),
|
|
74307
|
+
AST12.tsTypeAnnotation(
|
|
74308
|
+
AST12.tsTypeLiteral([
|
|
74309
|
+
AST12.tsPropertySignature(
|
|
74310
|
+
AST12.identifier("types"),
|
|
74311
|
+
AST12.tsTypeAnnotation(
|
|
74312
|
+
AST12.tsUnionType(
|
|
74313
|
+
possibleTypes.map(
|
|
74314
|
+
(possible) => AST12.tsLiteralType(AST12.stringLiteral(possible))
|
|
74315
|
+
)
|
|
74316
|
+
)
|
|
74317
|
+
)
|
|
74318
|
+
),
|
|
74319
|
+
AST12.tsPropertySignature(
|
|
74320
|
+
AST12.identifier("filters"),
|
|
74321
|
+
AST12.tsTypeAnnotation(
|
|
74322
|
+
targetFieldDefinition.args.length === 0 ? AST12.tsNeverKeyword() : AST12.tsTypeLiteral(
|
|
74323
|
+
targetFieldDefinition.args.map((arg) => {
|
|
74324
|
+
const argDef = AST12.tsPropertySignature(
|
|
74325
|
+
AST12.identifier(arg.name),
|
|
74326
|
+
AST12.tsTypeAnnotation(
|
|
74327
|
+
tsTypeReference(
|
|
74328
|
+
config2,
|
|
74329
|
+
/* @__PURE__ */ new Set(),
|
|
74330
|
+
arg
|
|
74331
|
+
)
|
|
74332
|
+
)
|
|
74333
|
+
);
|
|
74334
|
+
argDef.optional = true;
|
|
74335
|
+
return argDef;
|
|
74336
|
+
})
|
|
74337
|
+
)
|
|
74338
|
+
)
|
|
74339
|
+
)
|
|
74340
|
+
])
|
|
74341
|
+
)
|
|
74342
|
+
)
|
|
74343
|
+
);
|
|
74344
|
+
}
|
|
74345
|
+
});
|
|
74346
|
+
}
|
|
74347
|
+
return AST12.tsTypeLiteral(lists);
|
|
74348
|
+
}
|
|
74349
|
+
function queryDefinitions(config2, body, docs, returnType) {
|
|
74350
|
+
return AST12.tsTupleType(
|
|
74351
|
+
docs.reduce((prev, doc) => {
|
|
74352
|
+
if (doc.kind !== "HoudiniQuery" /* Query */ || !doc.generateStore) {
|
|
74353
|
+
return prev;
|
|
74354
|
+
}
|
|
74355
|
+
const definition = doc.document.definitions.find(
|
|
74356
|
+
(def) => def.kind === "OperationDefinition" && def.operation === "query"
|
|
74357
|
+
);
|
|
74358
|
+
if (!definition) {
|
|
74359
|
+
return prev;
|
|
74360
|
+
}
|
|
74361
|
+
const runtimeType = returnType(doc);
|
|
74362
|
+
const [shapeType, inputType] = ensureImports({
|
|
74363
|
+
config: config2,
|
|
74364
|
+
body,
|
|
74365
|
+
sourceModule: path_exports.relative(
|
|
74366
|
+
config2.runtimeDirectory,
|
|
74367
|
+
config2.artifactImportPath(doc.name)
|
|
74368
|
+
),
|
|
74369
|
+
import: [`${doc.name}$result`, `${doc.name}$input`]
|
|
74370
|
+
});
|
|
74371
|
+
return prev.concat(
|
|
74372
|
+
AST12.tsTupleType([
|
|
74373
|
+
AST12.tsTypeReference(AST12.identifier(runtimeType)),
|
|
74374
|
+
AST12.tsTypeReference(AST12.identifier(shapeType)),
|
|
74375
|
+
AST12.tsTypeReference(AST12.identifier(inputType))
|
|
74376
|
+
])
|
|
74377
|
+
);
|
|
74378
|
+
}, [])
|
|
74379
|
+
);
|
|
74380
|
+
}
|
|
74381
|
+
function fragmentListMap(config2, concreteTypes, body, docs, return_type) {
|
|
74382
|
+
return docs.reduce((prev, doc) => {
|
|
74383
|
+
if (doc.kind !== "HoudiniFragment" /* Fragment */) {
|
|
74384
|
+
return prev;
|
|
74385
|
+
}
|
|
74386
|
+
const definition = doc.document.definitions.find(
|
|
74387
|
+
(def) => def.kind === "FragmentDefinition" && def.name.value === doc.name
|
|
74388
|
+
);
|
|
74389
|
+
if (!definition || !concreteTypes.includes(definition.typeCondition.name.value)) {
|
|
74390
|
+
return prev;
|
|
74391
|
+
}
|
|
74392
|
+
const typeName = definition.typeCondition.name.value;
|
|
74393
|
+
const previousValue = prev[typeName]?.elementTypes ?? [];
|
|
74394
|
+
const tagResult = return_type(doc);
|
|
74395
|
+
const [shapeType] = ensureImports({
|
|
74396
|
+
config: config2,
|
|
74397
|
+
body,
|
|
74398
|
+
sourceModule: path_exports.relative(
|
|
74399
|
+
config2.runtimeDirectory,
|
|
74400
|
+
config2.artifactImportPath(doc.name)
|
|
73907
74401
|
),
|
|
73908
|
-
|
|
73909
|
-
|
|
73910
|
-
|
|
73911
|
-
|
|
74402
|
+
import: [`${definition.name.value}$data`]
|
|
74403
|
+
});
|
|
74404
|
+
let inputType = AST12.tsNeverKeyword();
|
|
74405
|
+
let directive = definition.directives?.find(
|
|
74406
|
+
(directive2) => directive2.name.value === config2.argumentsDirective
|
|
74407
|
+
);
|
|
74408
|
+
if (directive) {
|
|
74409
|
+
inputType = AST12.tsTypeReference(
|
|
74410
|
+
AST12.identifier(
|
|
74411
|
+
ensureImports({
|
|
73912
74412
|
config: config2,
|
|
73913
|
-
filepath,
|
|
73914
|
-
rootType: type,
|
|
73915
|
-
selections,
|
|
73916
|
-
root: true,
|
|
73917
|
-
allowReadonly: true,
|
|
73918
74413
|
body,
|
|
73919
|
-
|
|
73920
|
-
|
|
73921
|
-
|
|
73922
|
-
|
|
74414
|
+
sourceModule: path_exports.relative(
|
|
74415
|
+
config2.runtimeDirectory,
|
|
74416
|
+
config2.artifactImportPath(doc.name)
|
|
74417
|
+
),
|
|
74418
|
+
import: [`${definition.name.value}$input`]
|
|
74419
|
+
})[0]
|
|
74420
|
+
)
|
|
74421
|
+
);
|
|
74422
|
+
}
|
|
74423
|
+
return {
|
|
74424
|
+
...prev,
|
|
74425
|
+
[typeName]: AST12.tsTupleType(
|
|
74426
|
+
previousValue.concat(
|
|
74427
|
+
AST12.tsTupleType([
|
|
74428
|
+
AST12.tsTypeReference(AST12.identifier(tagResult)),
|
|
74429
|
+
AST12.tsTypeReference(AST12.identifier(shapeType)),
|
|
74430
|
+
inputType
|
|
74431
|
+
])
|
|
73923
74432
|
)
|
|
73924
74433
|
)
|
|
73925
|
-
|
|
73926
|
-
}
|
|
74434
|
+
};
|
|
74435
|
+
}, {});
|
|
74436
|
+
}
|
|
74437
|
+
var CacheTypeDefName = "CacheTypeDef";
|
|
74438
|
+
function record(name2) {
|
|
74439
|
+
return AST12.tsTypeReference(
|
|
74440
|
+
AST12.identifier("Record"),
|
|
74441
|
+
AST12.tsTypeParameterInstantiation([
|
|
74442
|
+
AST12.tsTypeReference(AST12.identifier(CacheTypeDefName)),
|
|
74443
|
+
AST12.tsLiteralType(AST12.stringLiteral(name2))
|
|
74444
|
+
])
|
|
74445
|
+
);
|
|
74446
|
+
}
|
|
74447
|
+
|
|
74448
|
+
// src/codegen/generators/typescript/index.ts
|
|
74449
|
+
async function typescriptGenerator(config2, docs) {
|
|
74450
|
+
await Promise.all([
|
|
74451
|
+
generateDocumentTypes(config2, docs),
|
|
74452
|
+
imperativeCacheTypef(config2, docs)
|
|
74453
|
+
]);
|
|
73927
74454
|
}
|
|
73928
74455
|
|
|
73929
74456
|
// src/codegen/generators/persistedQueries/index.ts
|
|
73930
|
-
var
|
|
74457
|
+
var graphql20 = __toESM(require_graphql2(), 1);
|
|
73931
74458
|
async function persistOutputGenerator(config2, docs) {
|
|
73932
74459
|
if (typeof config2.persistedQueryPath !== "string" || config2.persistedQueryPath.length === 0)
|
|
73933
74460
|
return;
|
|
@@ -73939,8 +74466,8 @@ async function persistOutputGenerator(config2, docs) {
|
|
|
73939
74466
|
if (!generateArtifact) {
|
|
73940
74467
|
return acc;
|
|
73941
74468
|
}
|
|
73942
|
-
let rawString =
|
|
73943
|
-
|
|
74469
|
+
let rawString = graphql20.print(
|
|
74470
|
+
graphql20.visit(document, {
|
|
73944
74471
|
Directive(node) {
|
|
73945
74472
|
if (config2.isInternalDirective(node)) {
|
|
73946
74473
|
return null;
|
|
@@ -73949,7 +74476,7 @@ async function persistOutputGenerator(config2, docs) {
|
|
|
73949
74476
|
})
|
|
73950
74477
|
);
|
|
73951
74478
|
const operations = document.definitions.filter(
|
|
73952
|
-
({ kind }) => kind ===
|
|
74479
|
+
({ kind }) => kind === graphql20.Kind.OPERATION_DEFINITION
|
|
73953
74480
|
);
|
|
73954
74481
|
if (operations.length > 0 && operations[0].kind === "OperationDefinition") {
|
|
73955
74482
|
acc[hashDocument(rawString)] = rawString;
|
|
@@ -73962,11 +74489,11 @@ async function persistOutputGenerator(config2, docs) {
|
|
|
73962
74489
|
}
|
|
73963
74490
|
|
|
73964
74491
|
// src/codegen/generators/definitions/enums.ts
|
|
73965
|
-
var
|
|
74492
|
+
var graphql21 = __toESM(require_graphql2(), 1);
|
|
73966
74493
|
var recast13 = __toESM(require_main2(), 1);
|
|
73967
74494
|
var AST13 = recast13.types.builders;
|
|
73968
74495
|
async function definitionsGenerator(config2) {
|
|
73969
|
-
const enums =
|
|
74496
|
+
const enums = graphql21.parse(graphql21.printSchema(config2.schema)).definitions.filter(
|
|
73970
74497
|
(definition) => definition.kind === "EnumTypeDefinition"
|
|
73971
74498
|
).filter((def) => !config2.isInternalEnum(def));
|
|
73972
74499
|
const runtimeDefinitions = recast13.print(
|
|
@@ -74040,107 +74567,24 @@ async function writeIndexFile2(config2, docs) {
|
|
|
74040
74567
|
export_default_as,
|
|
74041
74568
|
export_star_from,
|
|
74042
74569
|
plugin_root: config2.pluginDirectory(plugin.name),
|
|
74043
|
-
typedef: false,
|
|
74044
|
-
documents: docs
|
|
74045
|
-
});
|
|
74046
|
-
}
|
|
74047
|
-
if (plugin.include_runtime) {
|
|
74048
|
-
body += export_star_from({
|
|
74049
|
-
module: relative2(config2.pluginRuntimeDirectory(plugin.name))
|
|
74050
|
-
});
|
|
74051
|
-
}
|
|
74052
|
-
if (!plugin.index_file) {
|
|
74053
|
-
continue;
|
|
74054
|
-
}
|
|
74055
|
-
}
|
|
74056
|
-
await fs_exports.writeFile(path_exports.join(config2.rootDir, "index.js"), body);
|
|
74057
|
-
}
|
|
74058
|
-
|
|
74059
|
-
// src/codegen/transforms/composeQueries.ts
|
|
74060
|
-
var import_graphql30 = __toESM(require_graphql2(), 1);
|
|
74061
|
-
async function includeFragmentDefinitions(config2, documents) {
|
|
74062
|
-
const fragments = collectFragments(config2, documents);
|
|
74063
|
-
for (const [index, { name: name2, document, filename }] of documents.entries()) {
|
|
74064
|
-
const operation = document.definitions.find(
|
|
74065
|
-
({ kind }) => kind === import_graphql30.Kind.OPERATION_DEFINITION
|
|
74066
|
-
);
|
|
74067
|
-
if (!operation) {
|
|
74068
|
-
continue;
|
|
74069
|
-
}
|
|
74070
|
-
const allFragments = flattenFragments(
|
|
74071
|
-
filename,
|
|
74072
|
-
{ requiredFragments: findRequiredFragments(operation.selectionSet) },
|
|
74073
|
-
fragments
|
|
74074
|
-
);
|
|
74075
|
-
documents[index].document = {
|
|
74076
|
-
...document,
|
|
74077
|
-
definitions: [
|
|
74078
|
-
operation,
|
|
74079
|
-
...allFragments.map((fragmentName) => fragments[fragmentName].definition)
|
|
74080
|
-
]
|
|
74081
|
-
};
|
|
74082
|
-
}
|
|
74083
|
-
}
|
|
74084
|
-
function collectFragments(config2, docs) {
|
|
74085
|
-
return docs.reduce((acc, doc) => {
|
|
74086
|
-
const definitions = doc.document.definitions.reduce(
|
|
74087
|
-
(prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
|
|
74088
|
-
...prev,
|
|
74089
|
-
[definition.name.value]: {
|
|
74090
|
-
definition,
|
|
74091
|
-
requiredFragments: findRequiredFragments(definition.selectionSet),
|
|
74092
|
-
document: doc
|
|
74093
|
-
}
|
|
74094
|
-
},
|
|
74095
|
-
{}
|
|
74096
|
-
);
|
|
74097
|
-
return {
|
|
74098
|
-
...acc,
|
|
74099
|
-
...definitions
|
|
74100
|
-
};
|
|
74101
|
-
}, {});
|
|
74102
|
-
}
|
|
74103
|
-
function findRequiredFragments(selectionSet) {
|
|
74104
|
-
if (selectionSet.selections.length === 0) {
|
|
74105
|
-
return [];
|
|
74106
|
-
}
|
|
74107
|
-
const referencedFragments = [];
|
|
74108
|
-
for (const selection2 of selectionSet.selections) {
|
|
74109
|
-
if (selection2.kind === import_graphql30.Kind.FRAGMENT_SPREAD) {
|
|
74110
|
-
referencedFragments.push(selection2.name.value);
|
|
74111
|
-
} else if (selection2.selectionSet) {
|
|
74112
|
-
referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
|
|
74113
|
-
}
|
|
74114
|
-
}
|
|
74115
|
-
return referencedFragments;
|
|
74116
|
-
}
|
|
74117
|
-
function flattenFragments(filepath, operation, fragments) {
|
|
74118
|
-
const frags = /* @__PURE__ */ new Set();
|
|
74119
|
-
const remaining = [...operation.requiredFragments];
|
|
74120
|
-
while (remaining.length > 0) {
|
|
74121
|
-
const nextFragment = remaining.shift();
|
|
74122
|
-
if (!nextFragment) {
|
|
74123
|
-
continue;
|
|
74124
|
-
}
|
|
74125
|
-
if (!frags.has(nextFragment)) {
|
|
74126
|
-
frags.add(nextFragment);
|
|
74127
|
-
} else {
|
|
74128
|
-
continue;
|
|
74570
|
+
typedef: false,
|
|
74571
|
+
documents: docs
|
|
74572
|
+
});
|
|
74129
74573
|
}
|
|
74130
|
-
|
|
74131
|
-
|
|
74132
|
-
|
|
74133
|
-
filepath,
|
|
74134
|
-
message: "compose: could not find definition for fragment " + nextFragment
|
|
74574
|
+
if (plugin.include_runtime) {
|
|
74575
|
+
body += export_star_from({
|
|
74576
|
+
module: relative2(config2.pluginRuntimeDirectory(plugin.name))
|
|
74135
74577
|
});
|
|
74136
74578
|
}
|
|
74137
|
-
|
|
74579
|
+
if (!plugin.index_file) {
|
|
74580
|
+
continue;
|
|
74581
|
+
}
|
|
74138
74582
|
}
|
|
74139
|
-
|
|
74583
|
+
await fs_exports.writeFile(path_exports.join(config2.rootDir, "index.js"), body);
|
|
74140
74584
|
}
|
|
74141
74585
|
|
|
74142
74586
|
// src/codegen/transforms/schema.ts
|
|
74143
|
-
var
|
|
74587
|
+
var graphql22 = __toESM(require_graphql2(), 1);
|
|
74144
74588
|
async function graphqlExtensions(config2, documents) {
|
|
74145
74589
|
const internalSchema = `
|
|
74146
74590
|
enum CachePolicy {
|
|
@@ -74174,407 +74618,147 @@ directive @${config2.listAppendDirective} on FRAGMENT_SPREAD
|
|
|
74174
74618
|
|
|
74175
74619
|
"""
|
|
74176
74620
|
@${config2.listAllListsDirective} is used to tell the runtime to add the result to all list
|
|
74177
|
-
"""
|
|
74178
|
-
directive @${config2.listAllListsDirective} on FRAGMENT_SPREAD
|
|
74179
|
-
|
|
74180
|
-
"""
|
|
74181
|
-
@${config2.listParentDirective} is used to provide a parentID without specifying position or in situations
|
|
74182
|
-
where it doesn't make sense (eg when deleting a node.)
|
|
74183
|
-
"""
|
|
74184
|
-
directive @${config2.listParentDirective}(value: ID!) on FRAGMENT_SPREAD
|
|
74185
|
-
|
|
74186
|
-
"""
|
|
74187
|
-
@${config2.whenDirective} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
|
|
74188
|
-
"""
|
|
74189
|
-
directive @${config2.whenDirective} on FRAGMENT_SPREAD
|
|
74190
|
-
|
|
74191
|
-
"""
|
|
74192
|
-
@${config2.whenNotDirective} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
|
|
74193
|
-
"""
|
|
74194
|
-
directive @${config2.whenNotDirective} on FRAGMENT_SPREAD
|
|
74195
|
-
|
|
74196
|
-
"""
|
|
74197
|
-
@${config2.argumentsDirective} is used to define the arguments of a fragment
|
|
74198
|
-
"""
|
|
74199
|
-
directive @${config2.argumentsDirective} on FRAGMENT_DEFINITION
|
|
74200
|
-
|
|
74201
|
-
"""
|
|
74202
|
-
@${config2.cacheDirective} is used to specify cache rules for a query
|
|
74203
|
-
"""
|
|
74204
|
-
directive @${config2.cacheDirective}(${config2.cachePolicyArg}: CachePolicy, ${config2.cachePartialArg}: Boolean) on QUERY
|
|
74205
|
-
|
|
74206
|
-
"""
|
|
74207
|
-
@${config2.
|
|
74208
|
-
"""
|
|
74209
|
-
directive @${config2.
|
|
74210
|
-
|
|
74211
|
-
"""
|
|
74212
|
-
@${config2.maskEnableDirective} to enable masking on fragment (overwriting the global conf)
|
|
74213
|
-
"""
|
|
74214
|
-
directive @${config2.maskEnableDirective} on FRAGMENT_SPREAD
|
|
74215
|
-
|
|
74216
|
-
"""
|
|
74217
|
-
@${config2.maskDisableDirective} to disable masking on fragment (overwriting the global conf)
|
|
74218
|
-
"""
|
|
74219
|
-
directive @${config2.maskDisableDirective} on FRAGMENT_SPREAD
|
|
74220
|
-
`;
|
|
74221
|
-
let currentSchema =
|
|
74222
|
-
if (!currentSchema.includes(`directive @${config2.listDirective}`)) {
|
|
74223
|
-
currentSchema += internalSchema;
|
|
74224
|
-
}
|
|
74225
|
-
config2.newSchema += internalSchema;
|
|
74226
|
-
config2.schema =
|
|
74227
|
-
}
|
|
74228
|
-
|
|
74229
|
-
// src/codegen/transforms/typename.ts
|
|
74230
|
-
var
|
|
74231
|
-
async function addTypename(config2, documents) {
|
|
74232
|
-
for (const doc of documents) {
|
|
74233
|
-
doc.document =
|
|
74234
|
-
Field(node, key, parent, path2, ancestors) {
|
|
74235
|
-
if (!node.selectionSet) {
|
|
74236
|
-
return;
|
|
74237
|
-
}
|
|
74238
|
-
const type = parentTypeFromAncestors(
|
|
74239
|
-
config2.schema,
|
|
74240
|
-
doc.filename,
|
|
74241
|
-
ancestors.slice(0, -1)
|
|
74242
|
-
);
|
|
74243
|
-
const field = type.getFields()[node.name.value];
|
|
74244
|
-
const fieldType = unwrapType(config2, field.type).type;
|
|
74245
|
-
if (graphql22.isInterfaceType(fieldType) || graphql22.isUnionType(fieldType)) {
|
|
74246
|
-
return {
|
|
74247
|
-
...node,
|
|
74248
|
-
selectionSet: {
|
|
74249
|
-
...node.selectionSet,
|
|
74250
|
-
selections: [
|
|
74251
|
-
...node.selectionSet.selections,
|
|
74252
|
-
{
|
|
74253
|
-
kind: graphql22.Kind.FIELD,
|
|
74254
|
-
name: {
|
|
74255
|
-
kind: graphql22.Kind.NAME,
|
|
74256
|
-
value: "__typename"
|
|
74257
|
-
}
|
|
74258
|
-
}
|
|
74259
|
-
]
|
|
74260
|
-
}
|
|
74261
|
-
};
|
|
74262
|
-
}
|
|
74263
|
-
}
|
|
74264
|
-
});
|
|
74265
|
-
}
|
|
74266
|
-
}
|
|
74267
|
-
|
|
74268
|
-
// src/codegen/transforms/addID.ts
|
|
74269
|
-
var graphql23 = __toESM(require_graphql2(), 1);
|
|
74270
|
-
async function addID(config2, documents) {
|
|
74271
|
-
for (const doc of documents) {
|
|
74272
|
-
doc.document = graphql23.visit(doc.document, {
|
|
74273
|
-
Field(node, key, parent, path2, ancestors) {
|
|
74274
|
-
if (!node.selectionSet) {
|
|
74275
|
-
return;
|
|
74276
|
-
}
|
|
74277
|
-
const type = parentTypeFromAncestors(
|
|
74278
|
-
config2.schema,
|
|
74279
|
-
doc.filename,
|
|
74280
|
-
ancestors.slice(0, -1)
|
|
74281
|
-
);
|
|
74282
|
-
const field = type.getFields()[node.name.value];
|
|
74283
|
-
const fieldType = unwrapType(config2, field.type).type;
|
|
74284
|
-
if (node.selectionSet?.selections.length > 0) {
|
|
74285
|
-
if (!graphql23.isObjectType(fieldType) && !graphql23.isInterfaceType(fieldType)) {
|
|
74286
|
-
return;
|
|
74287
|
-
}
|
|
74288
|
-
const keyFields = config2.keyFieldsForType(fieldType.name);
|
|
74289
|
-
if (keyFields.find((key2) => !fieldType.getFields()[key2])) {
|
|
74290
|
-
return;
|
|
74291
|
-
}
|
|
74292
|
-
const selections = [...node.selectionSet.selections];
|
|
74293
|
-
for (const keyField of keyFields) {
|
|
74294
|
-
if (node.selectionSet.selections.find(
|
|
74295
|
-
(selection2) => selection2.kind === "Field" && !selection2.alias && selection2.name.value === keyField
|
|
74296
|
-
)) {
|
|
74297
|
-
continue;
|
|
74298
|
-
}
|
|
74299
|
-
selections.push({
|
|
74300
|
-
kind: graphql23.Kind.FIELD,
|
|
74301
|
-
name: {
|
|
74302
|
-
kind: graphql23.Kind.NAME,
|
|
74303
|
-
value: keyField
|
|
74304
|
-
}
|
|
74305
|
-
});
|
|
74306
|
-
}
|
|
74307
|
-
return {
|
|
74308
|
-
...node,
|
|
74309
|
-
selectionSet: {
|
|
74310
|
-
...node.selectionSet,
|
|
74311
|
-
selections
|
|
74312
|
-
}
|
|
74313
|
-
};
|
|
74314
|
-
}
|
|
74315
|
-
}
|
|
74316
|
-
});
|
|
74317
|
-
}
|
|
74318
|
-
}
|
|
74319
|
-
|
|
74320
|
-
// src/codegen/transforms/fragmentVariables.ts
|
|
74321
|
-
var graphql24 = __toESM(require_graphql2(), 1);
|
|
74322
|
-
var GraphqlKinds2 = graphql24.Kind;
|
|
74323
|
-
async function fragmentVariables(config2, documents) {
|
|
74324
|
-
const fragments = collectFragments(config2, documents);
|
|
74325
|
-
const generatedFragments = {};
|
|
74326
|
-
const visitedFragments = /* @__PURE__ */ new Set();
|
|
74327
|
-
for (const doc2 of documents) {
|
|
74328
|
-
const operation = doc2.document.definitions.find(
|
|
74329
|
-
({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
|
|
74330
|
-
);
|
|
74331
|
-
if (!operation) {
|
|
74332
|
-
continue;
|
|
74333
|
-
}
|
|
74334
|
-
doc2.document = inlineFragmentArgs({
|
|
74335
|
-
config: config2,
|
|
74336
|
-
filepath: doc2.filename,
|
|
74337
|
-
fragmentDefinitions: fragments,
|
|
74338
|
-
document: doc2.document,
|
|
74339
|
-
generatedFragments,
|
|
74340
|
-
visitedFragments,
|
|
74341
|
-
scope: null
|
|
74342
|
-
});
|
|
74343
|
-
}
|
|
74344
|
-
const doc = {
|
|
74345
|
-
kind: graphql24.Kind.DOCUMENT,
|
|
74346
|
-
definitions: Object.values(generatedFragments)
|
|
74347
|
-
};
|
|
74348
|
-
documents.push({
|
|
74349
|
-
name: "generated::fragmentVariables",
|
|
74350
|
-
kind: "HoudiniFragment" /* Fragment */,
|
|
74351
|
-
document: doc,
|
|
74352
|
-
originalDocument: doc,
|
|
74353
|
-
generateStore: false,
|
|
74354
|
-
generateArtifact: false,
|
|
74355
|
-
filename: "generated::fragmentVariables",
|
|
74356
|
-
originalString: ""
|
|
74357
|
-
});
|
|
74358
|
-
}
|
|
74359
|
-
function inlineFragmentArgs({
|
|
74360
|
-
config: config2,
|
|
74361
|
-
filepath,
|
|
74362
|
-
fragmentDefinitions,
|
|
74363
|
-
document,
|
|
74364
|
-
generatedFragments,
|
|
74365
|
-
visitedFragments,
|
|
74366
|
-
scope,
|
|
74367
|
-
newName
|
|
74368
|
-
}) {
|
|
74369
|
-
if (!scope) {
|
|
74370
|
-
scope = operationScope(
|
|
74371
|
-
document.definitions.find(
|
|
74372
|
-
({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
|
|
74373
|
-
)
|
|
74374
|
-
);
|
|
74375
|
-
}
|
|
74376
|
-
const definitionArgs = fragmentArguments(
|
|
74377
|
-
config2,
|
|
74378
|
-
filepath,
|
|
74379
|
-
document
|
|
74380
|
-
).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
|
|
74381
|
-
const result = graphql24.visit(document, {
|
|
74382
|
-
FragmentSpread(node) {
|
|
74383
|
-
const { definition } = fragmentDefinitions[node.name.value];
|
|
74384
|
-
let { args, hash } = collectWithArguments(config2, filepath, node, scope);
|
|
74385
|
-
const newFragmentName = `${node.name.value}${hash}`;
|
|
74386
|
-
if (!visitedFragments.has(newFragmentName)) {
|
|
74387
|
-
visitedFragments.add(newFragmentName);
|
|
74388
|
-
const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
|
|
74389
|
-
if (args) {
|
|
74390
|
-
for (const [field, value] of Object.entries(defaultArguments || {})) {
|
|
74391
|
-
if (!args[field]) {
|
|
74392
|
-
args[field] = value;
|
|
74393
|
-
}
|
|
74394
|
-
}
|
|
74395
|
-
generatedFragments[newFragmentName] = inlineFragmentArgs({
|
|
74396
|
-
config: config2,
|
|
74397
|
-
filepath,
|
|
74398
|
-
fragmentDefinitions,
|
|
74399
|
-
document: fragmentDefinitions[node.name.value].definition,
|
|
74400
|
-
generatedFragments,
|
|
74401
|
-
visitedFragments,
|
|
74402
|
-
scope: args,
|
|
74403
|
-
newName: newFragmentName
|
|
74404
|
-
});
|
|
74405
|
-
} else {
|
|
74406
|
-
const doc = fragmentDefinitions[node.name.value].document;
|
|
74407
|
-
const definitionIndex = doc.document.definitions.findIndex(
|
|
74408
|
-
(definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
|
|
74409
|
-
);
|
|
74410
|
-
const localDefinitions = [...doc.document.definitions];
|
|
74411
|
-
localDefinitions.splice(definitionIndex, 1);
|
|
74412
|
-
localDefinitions.push(
|
|
74413
|
-
inlineFragmentArgs({
|
|
74414
|
-
config: config2,
|
|
74415
|
-
filepath,
|
|
74416
|
-
fragmentDefinitions,
|
|
74417
|
-
document: fragmentDefinitions[node.name.value].definition,
|
|
74418
|
-
generatedFragments,
|
|
74419
|
-
visitedFragments,
|
|
74420
|
-
scope: defaultArguments,
|
|
74421
|
-
newName: ""
|
|
74422
|
-
})
|
|
74423
|
-
);
|
|
74424
|
-
doc.document = {
|
|
74425
|
-
...doc.document,
|
|
74426
|
-
definitions: localDefinitions
|
|
74427
|
-
};
|
|
74621
|
+
"""
|
|
74622
|
+
directive @${config2.listAllListsDirective} on FRAGMENT_SPREAD
|
|
74623
|
+
|
|
74624
|
+
"""
|
|
74625
|
+
@${config2.listParentDirective} is used to provide a parentID without specifying position or in situations
|
|
74626
|
+
where it doesn't make sense (eg when deleting a node.)
|
|
74627
|
+
"""
|
|
74628
|
+
directive @${config2.listParentDirective}(value: ID!) on FRAGMENT_SPREAD
|
|
74629
|
+
|
|
74630
|
+
"""
|
|
74631
|
+
@${config2.whenDirective} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
|
|
74632
|
+
"""
|
|
74633
|
+
directive @${config2.whenDirective} on FRAGMENT_SPREAD
|
|
74634
|
+
|
|
74635
|
+
"""
|
|
74636
|
+
@${config2.whenNotDirective} is used to provide a conditional or in situations where it doesn't make sense (eg when removing or deleting a node.)
|
|
74637
|
+
"""
|
|
74638
|
+
directive @${config2.whenNotDirective} on FRAGMENT_SPREAD
|
|
74639
|
+
|
|
74640
|
+
"""
|
|
74641
|
+
@${config2.argumentsDirective} is used to define the arguments of a fragment
|
|
74642
|
+
"""
|
|
74643
|
+
directive @${config2.argumentsDirective} on FRAGMENT_DEFINITION
|
|
74644
|
+
|
|
74645
|
+
"""
|
|
74646
|
+
@${config2.cacheDirective} is used to specify cache rules for a query
|
|
74647
|
+
"""
|
|
74648
|
+
directive @${config2.cacheDirective}(${config2.cachePolicyArg}: CachePolicy, ${config2.cachePartialArg}: Boolean) on QUERY
|
|
74649
|
+
|
|
74650
|
+
"""
|
|
74651
|
+
@${config2.loadDirective} is used to disable automatic fetch (no load, no auto fetch in component), you will have to do it manually.
|
|
74652
|
+
"""
|
|
74653
|
+
directive @${config2.loadDirective} on QUERY
|
|
74654
|
+
|
|
74655
|
+
"""
|
|
74656
|
+
@${config2.maskEnableDirective} to enable masking on fragment (overwriting the global conf)
|
|
74657
|
+
"""
|
|
74658
|
+
directive @${config2.maskEnableDirective} on FRAGMENT_SPREAD
|
|
74659
|
+
|
|
74660
|
+
"""
|
|
74661
|
+
@${config2.maskDisableDirective} to disable masking on fragment (overwriting the global conf)
|
|
74662
|
+
"""
|
|
74663
|
+
directive @${config2.maskDisableDirective} on FRAGMENT_SPREAD
|
|
74664
|
+
`;
|
|
74665
|
+
let currentSchema = graphql22.printSchema(config2.schema);
|
|
74666
|
+
if (!currentSchema.includes(`directive @${config2.listDirective}`)) {
|
|
74667
|
+
currentSchema += internalSchema;
|
|
74668
|
+
}
|
|
74669
|
+
config2.newSchema += internalSchema;
|
|
74670
|
+
config2.schema = graphql22.buildSchema(currentSchema);
|
|
74671
|
+
}
|
|
74672
|
+
|
|
74673
|
+
// src/codegen/transforms/typename.ts
|
|
74674
|
+
var graphql23 = __toESM(require_graphql2(), 1);
|
|
74675
|
+
async function addTypename(config2, documents) {
|
|
74676
|
+
for (const doc of documents) {
|
|
74677
|
+
doc.document = graphql23.visit(doc.document, {
|
|
74678
|
+
Field(node, key, parent, path2, ancestors) {
|
|
74679
|
+
if (!node.selectionSet) {
|
|
74680
|
+
return;
|
|
74428
74681
|
}
|
|
74429
|
-
|
|
74682
|
+
const type = parentTypeFromAncestors(
|
|
74683
|
+
config2.schema,
|
|
74684
|
+
doc.filename,
|
|
74685
|
+
ancestors.slice(0, -1)
|
|
74686
|
+
);
|
|
74687
|
+
const field = type.getFields()[node.name.value];
|
|
74688
|
+
const fieldType = unwrapType(config2, field.type).type;
|
|
74689
|
+
if (graphql23.isInterfaceType(fieldType) || graphql23.isUnionType(fieldType)) {
|
|
74430
74690
|
return {
|
|
74431
74691
|
...node,
|
|
74432
|
-
|
|
74433
|
-
|
|
74434
|
-
|
|
74692
|
+
selectionSet: {
|
|
74693
|
+
...node.selectionSet,
|
|
74694
|
+
selections: [
|
|
74695
|
+
...node.selectionSet.selections,
|
|
74696
|
+
{
|
|
74697
|
+
kind: graphql23.Kind.FIELD,
|
|
74698
|
+
name: {
|
|
74699
|
+
kind: graphql23.Kind.NAME,
|
|
74700
|
+
value: "__typename"
|
|
74701
|
+
}
|
|
74702
|
+
}
|
|
74703
|
+
]
|
|
74435
74704
|
}
|
|
74436
74705
|
};
|
|
74437
74706
|
}
|
|
74438
74707
|
}
|
|
74439
|
-
}
|
|
74440
|
-
Argument(node) {
|
|
74441
|
-
const value = node.value;
|
|
74442
|
-
if (value.kind !== "Variable") {
|
|
74443
|
-
return;
|
|
74444
|
-
}
|
|
74445
|
-
if (!scope) {
|
|
74446
|
-
throw new HoudiniError({
|
|
74447
|
-
filepath,
|
|
74448
|
-
message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
|
|
74449
|
-
});
|
|
74450
|
-
}
|
|
74451
|
-
const newValue = scope[value.name.value];
|
|
74452
|
-
if (newValue) {
|
|
74453
|
-
return {
|
|
74454
|
-
...node,
|
|
74455
|
-
value: newValue
|
|
74456
|
-
};
|
|
74457
|
-
}
|
|
74458
|
-
if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
|
|
74459
|
-
throw new HoudiniError({
|
|
74460
|
-
filepath,
|
|
74461
|
-
message: "Missing value for required arg: " + value.name.value
|
|
74462
|
-
});
|
|
74463
|
-
}
|
|
74464
|
-
return null;
|
|
74465
|
-
}
|
|
74466
|
-
});
|
|
74467
|
-
if (newName) {
|
|
74468
|
-
result.name = {
|
|
74469
|
-
kind: graphql24.Kind.NAME,
|
|
74470
|
-
value: newName
|
|
74471
|
-
};
|
|
74472
|
-
}
|
|
74473
|
-
return result;
|
|
74474
|
-
}
|
|
74475
|
-
function withArguments(config2, node) {
|
|
74476
|
-
const withDirectives = node.directives?.filter(
|
|
74477
|
-
(directive) => directive.name.value === config2.withDirective
|
|
74478
|
-
);
|
|
74479
|
-
if (!withDirectives || withDirectives.length === 0) {
|
|
74480
|
-
return [];
|
|
74708
|
+
});
|
|
74481
74709
|
}
|
|
74482
|
-
return withDirectives.flatMap((directive) => directive.arguments || []);
|
|
74483
74710
|
}
|
|
74484
|
-
|
|
74485
|
-
|
|
74486
|
-
|
|
74487
|
-
|
|
74488
|
-
|
|
74489
|
-
|
|
74490
|
-
|
|
74491
|
-
|
|
74492
|
-
|
|
74493
|
-
if (arg.value.kind !== "ObjectValue") {
|
|
74494
|
-
throw new HoudiniError({
|
|
74495
|
-
filepath,
|
|
74496
|
-
message: "values of @argument must be objects"
|
|
74497
|
-
});
|
|
74498
|
-
}
|
|
74499
|
-
const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
|
|
74500
|
-
if (!typeArg || typeArg.kind !== "StringValue") {
|
|
74501
|
-
return [];
|
|
74502
|
-
}
|
|
74503
|
-
let type = typeArg.value;
|
|
74504
|
-
let name2 = arg.name.value;
|
|
74505
|
-
let required = false;
|
|
74506
|
-
let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
|
|
74507
|
-
if (type[type.length - 1] === "!") {
|
|
74508
|
-
type = type.slice(0, -1);
|
|
74509
|
-
required = true;
|
|
74510
|
-
defaultValue = null;
|
|
74511
|
-
}
|
|
74512
|
-
return [
|
|
74513
|
-
{
|
|
74514
|
-
name: name2,
|
|
74515
|
-
type,
|
|
74516
|
-
required,
|
|
74517
|
-
defaultValue
|
|
74711
|
+
|
|
74712
|
+
// src/codegen/transforms/addID.ts
|
|
74713
|
+
var graphql24 = __toESM(require_graphql2(), 1);
|
|
74714
|
+
async function addID(config2, documents) {
|
|
74715
|
+
for (const doc of documents) {
|
|
74716
|
+
doc.document = graphql24.visit(doc.document, {
|
|
74717
|
+
Field(node, key, parent, path2, ancestors) {
|
|
74718
|
+
if (!node.selectionSet) {
|
|
74719
|
+
return;
|
|
74518
74720
|
}
|
|
74519
|
-
|
|
74520
|
-
|
|
74521
|
-
|
|
74522
|
-
|
|
74523
|
-
|
|
74524
|
-
|
|
74525
|
-
|
|
74526
|
-
|
|
74527
|
-
|
|
74528
|
-
|
|
74529
|
-
|
|
74530
|
-
|
|
74531
|
-
|
|
74532
|
-
|
|
74533
|
-
|
|
74534
|
-
|
|
74535
|
-
|
|
74536
|
-
|
|
74537
|
-
|
|
74538
|
-
|
|
74539
|
-
|
|
74540
|
-
|
|
74541
|
-
|
|
74542
|
-
|
|
74543
|
-
|
|
74544
|
-
|
|
74545
|
-
|
|
74546
|
-
|
|
74547
|
-
|
|
74548
|
-
|
|
74549
|
-
|
|
74550
|
-
|
|
74551
|
-
|
|
74552
|
-
|
|
74553
|
-
|
|
74554
|
-
|
|
74555
|
-
|
|
74556
|
-
loc: void 0
|
|
74557
|
-
};
|
|
74558
|
-
}
|
|
74559
|
-
return {
|
|
74560
|
-
args,
|
|
74561
|
-
hash: "_" + murmurHash(JSON.stringify(args))
|
|
74562
|
-
};
|
|
74563
|
-
}
|
|
74564
|
-
function operationScope(operation) {
|
|
74565
|
-
return operation.variableDefinitions?.reduce(
|
|
74566
|
-
(scope, definition) => ({
|
|
74567
|
-
...scope,
|
|
74568
|
-
[definition.variable.name.value]: {
|
|
74569
|
-
kind: "Variable",
|
|
74570
|
-
name: {
|
|
74571
|
-
kind: "Name",
|
|
74572
|
-
value: definition.variable.name.value
|
|
74721
|
+
const type = parentTypeFromAncestors(
|
|
74722
|
+
config2.schema,
|
|
74723
|
+
doc.filename,
|
|
74724
|
+
ancestors.slice(0, -1)
|
|
74725
|
+
);
|
|
74726
|
+
const field = type.getFields()[node.name.value];
|
|
74727
|
+
const fieldType = unwrapType(config2, field.type).type;
|
|
74728
|
+
if (node.selectionSet?.selections.length > 0) {
|
|
74729
|
+
if (!graphql24.isObjectType(fieldType) && !graphql24.isInterfaceType(fieldType)) {
|
|
74730
|
+
return;
|
|
74731
|
+
}
|
|
74732
|
+
const keyFields = config2.keyFieldsForType(fieldType.name);
|
|
74733
|
+
if (keyFields.find((key2) => !fieldType.getFields()[key2])) {
|
|
74734
|
+
return;
|
|
74735
|
+
}
|
|
74736
|
+
const selections = [...node.selectionSet.selections];
|
|
74737
|
+
for (const keyField of keyFields) {
|
|
74738
|
+
if (node.selectionSet.selections.find(
|
|
74739
|
+
(selection2) => selection2.kind === "Field" && !selection2.alias && selection2.name.value === keyField
|
|
74740
|
+
)) {
|
|
74741
|
+
continue;
|
|
74742
|
+
}
|
|
74743
|
+
selections.push({
|
|
74744
|
+
kind: graphql24.Kind.FIELD,
|
|
74745
|
+
name: {
|
|
74746
|
+
kind: graphql24.Kind.NAME,
|
|
74747
|
+
value: keyField
|
|
74748
|
+
}
|
|
74749
|
+
});
|
|
74750
|
+
}
|
|
74751
|
+
return {
|
|
74752
|
+
...node,
|
|
74753
|
+
selectionSet: {
|
|
74754
|
+
...node.selectionSet,
|
|
74755
|
+
selections
|
|
74756
|
+
}
|
|
74757
|
+
};
|
|
74573
74758
|
}
|
|
74574
74759
|
}
|
|
74575
|
-
})
|
|
74576
|
-
|
|
74577
|
-
) || {};
|
|
74760
|
+
});
|
|
74761
|
+
}
|
|
74578
74762
|
}
|
|
74579
74763
|
|
|
74580
74764
|
// src/codegen/validators/typeCheck.ts
|
|
@@ -75927,7 +76111,9 @@ var writeConfigFile = async ({
|
|
|
75927
76111
|
}) => {
|
|
75928
76112
|
const config2 = {};
|
|
75929
76113
|
if (url !== null) {
|
|
75930
|
-
config2.
|
|
76114
|
+
config2.watchSchema = {
|
|
76115
|
+
url
|
|
76116
|
+
};
|
|
75931
76117
|
}
|
|
75932
76118
|
if (schemaPath !== "./schema.graphql") {
|
|
75933
76119
|
config2.schemaPath = schemaPath;
|
|
@@ -76093,8 +76279,8 @@ async function updatePackageJSON(targetPath) {
|
|
|
76093
76279
|
}
|
|
76094
76280
|
packageJSON.devDependencies = {
|
|
76095
76281
|
...packageJSON.devDependencies,
|
|
76096
|
-
houdini: "^1.0.0-next.
|
|
76097
|
-
"houdini-svelte": "^1.0.0-next.
|
|
76282
|
+
houdini: "^1.0.0-next.4",
|
|
76283
|
+
"houdini-svelte": "^1.0.0-next.4",
|
|
76098
76284
|
graphql: "^15.8.0"
|
|
76099
76285
|
};
|
|
76100
76286
|
await fs_exports.writeFile(packagePath, JSON.stringify(packageJSON, null, 4));
|