houdini 1.0.0-next.2 → 1.0.0-next.3
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 +1380 -1190
- package/build/cmd-esm/index.js +1380 -1190
- 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 +1225 -1037
- package/build/codegen-esm/index.js +1225 -1037
- 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/lists.d.ts +1 -0
- 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/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/lists.d.ts +1 -0
- package/build/runtime-cjs/cache/lists.js +3 -0
- 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/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/lists.d.ts +1 -0
- package/build/runtime-esm/cache/lists.js +3 -0
- 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/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 +1233 -1046
- package/build/test-esm/index.js +1233 -1046
- package/build/vite-cjs/index.js +1234 -1046
- package/build/vite-esm/index.js +1234 -1046
- package/package.json +1 -1
package/build/test-esm/index.js
CHANGED
|
@@ -54344,8 +54344,7 @@ var Config = class {
|
|
|
54344
54344
|
types: types14 = {},
|
|
54345
54345
|
logLevel,
|
|
54346
54346
|
defaultFragmentMasking = "enable",
|
|
54347
|
-
|
|
54348
|
-
schemaPollHeaders = {},
|
|
54347
|
+
watchSchema,
|
|
54349
54348
|
projectDir
|
|
54350
54349
|
} = this.configFile;
|
|
54351
54350
|
if (typeof schema === "string") {
|
|
@@ -54378,8 +54377,8 @@ var Config = class {
|
|
|
54378
54377
|
this.logLevel = (logLevel || LogLevel.Summary).toLowerCase();
|
|
54379
54378
|
this.defaultFragmentMasking = defaultFragmentMasking;
|
|
54380
54379
|
this.routesDir = join(this.projectRoot, "src", "routes");
|
|
54381
|
-
this.schemaPollInterval =
|
|
54382
|
-
this.schemaPollHeaders =
|
|
54380
|
+
this.schemaPollInterval = watchSchema?.interval ?? 2e3;
|
|
54381
|
+
this.schemaPollHeaders = watchSchema?.headers ?? {};
|
|
54383
54382
|
this.rootDir = join(this.projectRoot, "$houdini");
|
|
54384
54383
|
if (defaultKeys) {
|
|
54385
54384
|
this.defaultKeys = defaultKeys;
|
|
@@ -54392,11 +54391,12 @@ var Config = class {
|
|
|
54392
54391
|
}
|
|
54393
54392
|
}
|
|
54394
54393
|
async apiURL() {
|
|
54395
|
-
|
|
54394
|
+
const apiURL = this.configFile.watchSchema?.url;
|
|
54395
|
+
if (!apiURL) {
|
|
54396
54396
|
return "";
|
|
54397
54397
|
}
|
|
54398
54398
|
const env = await this.getEnv();
|
|
54399
|
-
return this.processEnvValues(env,
|
|
54399
|
+
return this.processEnvValues(env, apiURL);
|
|
54400
54400
|
}
|
|
54401
54401
|
get include() {
|
|
54402
54402
|
if (this.configFile.include) {
|
|
@@ -54600,8 +54600,8 @@ var Config = class {
|
|
|
54600
54600
|
pluginDirectory(name2) {
|
|
54601
54601
|
return join(this.pluginRootDirectory, name2);
|
|
54602
54602
|
}
|
|
54603
|
-
get
|
|
54604
|
-
return "
|
|
54603
|
+
get loadDirective() {
|
|
54604
|
+
return "load";
|
|
54605
54605
|
}
|
|
54606
54606
|
get maskEnableDirective() {
|
|
54607
54607
|
return "mask_enable";
|
|
@@ -54718,7 +54718,7 @@ var Config = class {
|
|
|
54718
54718
|
this.withDirective,
|
|
54719
54719
|
this.paginateDirective,
|
|
54720
54720
|
this.cacheDirective,
|
|
54721
|
-
this.
|
|
54721
|
+
this.loadDirective,
|
|
54722
54722
|
this.maskEnableDirective,
|
|
54723
54723
|
this.maskDisableDirective
|
|
54724
54724
|
].includes(name2.value) || this.isDeleteDirective(name2.value);
|
|
@@ -54989,7 +54989,7 @@ async function cleanupFiles(pathFolder, listOfObj) {
|
|
|
54989
54989
|
}
|
|
54990
54990
|
|
|
54991
54991
|
// src/codegen/generators/artifacts/index.ts
|
|
54992
|
-
var
|
|
54992
|
+
var graphql12 = __toESM(require_graphql2(), 1);
|
|
54993
54993
|
var recast5 = __toESM(require_main2(), 1);
|
|
54994
54994
|
|
|
54995
54995
|
// src/codegen/utils/commonjs.ts
|
|
@@ -55247,159 +55247,534 @@ function murmurHash(str) {
|
|
|
55247
55247
|
return s;
|
|
55248
55248
|
}
|
|
55249
55249
|
|
|
55250
|
-
// src/codegen/
|
|
55251
|
-
async function writeIndexFile(config2, docs) {
|
|
55252
|
-
const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
|
|
55253
|
-
let body = config2.module === "esm" ? docsToGenerate.reduce(
|
|
55254
|
-
(content, doc) => content + `
|
|
55255
|
-
export { default as ${doc.name}} from './${doc.name}'`,
|
|
55256
|
-
""
|
|
55257
|
-
) : docsToGenerate.reduce(
|
|
55258
|
-
(content, doc) => content + `
|
|
55259
|
-
${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
|
|
55260
|
-
cjsIndexFilePreamble
|
|
55261
|
-
);
|
|
55262
|
-
await fs_exports.writeFile(path_exports.join(config2.artifactDirectory, "index.js"), body);
|
|
55263
|
-
}
|
|
55264
|
-
|
|
55265
|
-
// src/codegen/generators/artifacts/inputs.ts
|
|
55250
|
+
// src/codegen/transforms/fragmentVariables.ts
|
|
55266
55251
|
var graphql3 = __toESM(require_graphql2(), 1);
|
|
55267
|
-
var recast3 = __toESM(require_main2(), 1);
|
|
55268
|
-
var AST3 = recast3.types.builders;
|
|
55269
|
-
function inputObject(config2, inputs) {
|
|
55270
|
-
const visitedTypes = /* @__PURE__ */ new Set();
|
|
55271
|
-
const inputObj = {
|
|
55272
|
-
fields: inputs.reduce((fields, input) => {
|
|
55273
|
-
const { type } = unwrapType(config2, input.type);
|
|
55274
|
-
return {
|
|
55275
|
-
...fields,
|
|
55276
|
-
[input.variable.name.value]: type.name
|
|
55277
|
-
};
|
|
55278
|
-
}, {}),
|
|
55279
|
-
types: {}
|
|
55280
|
-
};
|
|
55281
|
-
for (const input of inputs) {
|
|
55282
|
-
walkInputs(config2, visitedTypes, inputObj, input.type);
|
|
55283
|
-
}
|
|
55284
|
-
return inputObj;
|
|
55285
|
-
}
|
|
55286
|
-
function walkInputs(config2, visitedTypes, inputObj, rootType) {
|
|
55287
|
-
const { type } = unwrapType(config2, rootType);
|
|
55288
|
-
if (visitedTypes.has(type.name)) {
|
|
55289
|
-
return;
|
|
55290
|
-
}
|
|
55291
|
-
if (graphql3.isEnumType(type) || graphql3.isScalarType(type)) {
|
|
55292
|
-
return;
|
|
55293
|
-
}
|
|
55294
|
-
if (graphql3.isUnionType(type)) {
|
|
55295
|
-
return;
|
|
55296
|
-
}
|
|
55297
|
-
visitedTypes.add(type.name);
|
|
55298
|
-
inputObj.types[type.name] = Object.values(type.getFields()).reduce(
|
|
55299
|
-
(typeFields, field) => {
|
|
55300
|
-
const { type: fieldType } = unwrapType(config2, field.type);
|
|
55301
|
-
walkInputs(config2, visitedTypes, inputObj, fieldType);
|
|
55302
|
-
return {
|
|
55303
|
-
...typeFields,
|
|
55304
|
-
[field.name]: fieldType.toString()
|
|
55305
|
-
};
|
|
55306
|
-
},
|
|
55307
|
-
{}
|
|
55308
|
-
);
|
|
55309
|
-
}
|
|
55310
55252
|
|
|
55311
|
-
// src/codegen/
|
|
55312
|
-
var
|
|
55313
|
-
|
|
55314
|
-
|
|
55315
|
-
|
|
55316
|
-
|
|
55317
|
-
|
|
55318
|
-
|
|
55319
|
-
|
|
55320
|
-
|
|
55253
|
+
// src/codegen/transforms/composeQueries.ts
|
|
55254
|
+
var import_graphql = __toESM(require_graphql2(), 1);
|
|
55255
|
+
async function includeFragmentDefinitions(config2, documents) {
|
|
55256
|
+
const fragments = collectFragments(config2, documents);
|
|
55257
|
+
for (const [index, { name: name2, document, filename }] of documents.entries()) {
|
|
55258
|
+
const operation = document.definitions.find(
|
|
55259
|
+
({ kind }) => kind === import_graphql.Kind.OPERATION_DEFINITION
|
|
55260
|
+
);
|
|
55261
|
+
if (!operation) {
|
|
55262
|
+
continue;
|
|
55263
|
+
}
|
|
55264
|
+
const allFragments = flattenFragments(
|
|
55265
|
+
filename,
|
|
55266
|
+
{ requiredFragments: findRequiredFragments(operation.selectionSet) },
|
|
55267
|
+
fragments
|
|
55268
|
+
);
|
|
55269
|
+
documents[index].document = {
|
|
55270
|
+
...document,
|
|
55271
|
+
definitions: [
|
|
55272
|
+
operation,
|
|
55273
|
+
...allFragments.map((fragmentName) => fragments[fragmentName].definition)
|
|
55274
|
+
]
|
|
55275
|
+
};
|
|
55321
55276
|
}
|
|
55322
|
-
|
|
55323
|
-
|
|
55324
|
-
|
|
55325
|
-
|
|
55326
|
-
)
|
|
55277
|
+
}
|
|
55278
|
+
function collectFragments(config2, docs) {
|
|
55279
|
+
return docs.reduce((acc, doc) => {
|
|
55280
|
+
const definitions = doc.document.definitions.reduce(
|
|
55281
|
+
(prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
|
|
55282
|
+
...prev,
|
|
55283
|
+
[definition.name.value]: {
|
|
55284
|
+
definition,
|
|
55285
|
+
requiredFragments: findRequiredFragments(definition.selectionSet),
|
|
55286
|
+
document: doc
|
|
55287
|
+
}
|
|
55288
|
+
},
|
|
55289
|
+
{}
|
|
55327
55290
|
);
|
|
55291
|
+
return {
|
|
55292
|
+
...acc,
|
|
55293
|
+
...definitions
|
|
55294
|
+
};
|
|
55295
|
+
}, {});
|
|
55296
|
+
}
|
|
55297
|
+
function findRequiredFragments(selectionSet) {
|
|
55298
|
+
if (selectionSet.selections.length === 0) {
|
|
55299
|
+
return [];
|
|
55328
55300
|
}
|
|
55329
|
-
|
|
55330
|
-
|
|
55331
|
-
|
|
55332
|
-
|
|
55333
|
-
|
|
55334
|
-
);
|
|
55301
|
+
const referencedFragments = [];
|
|
55302
|
+
for (const selection2 of selectionSet.selections) {
|
|
55303
|
+
if (selection2.kind === import_graphql.Kind.FRAGMENT_SPREAD) {
|
|
55304
|
+
referencedFragments.push(selection2.name.value);
|
|
55305
|
+
} else if (selection2.selectionSet) {
|
|
55306
|
+
referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
|
|
55335
55307
|
}
|
|
55336
|
-
return AST4.stringLiteral(value);
|
|
55337
55308
|
}
|
|
55338
|
-
return
|
|
55309
|
+
return referencedFragments;
|
|
55339
55310
|
}
|
|
55340
|
-
function
|
|
55341
|
-
|
|
55342
|
-
|
|
55343
|
-
|
|
55344
|
-
|
|
55311
|
+
function flattenFragments(filepath, operation, fragments) {
|
|
55312
|
+
const frags = /* @__PURE__ */ new Set();
|
|
55313
|
+
const remaining = [...operation.requiredFragments];
|
|
55314
|
+
while (remaining.length > 0) {
|
|
55315
|
+
const nextFragment = remaining.shift();
|
|
55316
|
+
if (!nextFragment) {
|
|
55317
|
+
continue;
|
|
55345
55318
|
}
|
|
55346
|
-
|
|
55347
|
-
|
|
55348
|
-
|
|
55349
|
-
|
|
55350
|
-
|
|
55351
|
-
|
|
55352
|
-
|
|
55353
|
-
|
|
55354
|
-
|
|
55355
|
-
|
|
55356
|
-
}
|
|
55357
|
-
fields[key].push(value);
|
|
55319
|
+
if (!frags.has(nextFragment)) {
|
|
55320
|
+
frags.add(nextFragment);
|
|
55321
|
+
} else {
|
|
55322
|
+
continue;
|
|
55323
|
+
}
|
|
55324
|
+
const targetFragment = fragments[nextFragment];
|
|
55325
|
+
if (!targetFragment) {
|
|
55326
|
+
throw new HoudiniError({
|
|
55327
|
+
filepath,
|
|
55328
|
+
message: "compose: could not find definition for fragment " + nextFragment
|
|
55329
|
+
});
|
|
55358
55330
|
}
|
|
55331
|
+
remaining.push(...targetFragment.requiredFragments);
|
|
55359
55332
|
}
|
|
55360
|
-
return
|
|
55361
|
-
Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
|
|
55362
|
-
);
|
|
55333
|
+
return [...frags];
|
|
55363
55334
|
}
|
|
55364
|
-
|
|
55365
|
-
|
|
55366
|
-
|
|
55367
|
-
|
|
55368
|
-
|
|
55369
|
-
|
|
55370
|
-
|
|
55371
|
-
|
|
55372
|
-
|
|
55373
|
-
|
|
55374
|
-
|
|
55375
|
-
|
|
55376
|
-
|
|
55377
|
-
|
|
55378
|
-
|
|
55379
|
-
|
|
55380
|
-
|
|
55381
|
-
|
|
55335
|
+
|
|
55336
|
+
// src/codegen/transforms/fragmentVariables.ts
|
|
55337
|
+
var GraphqlKinds2 = graphql3.Kind;
|
|
55338
|
+
async function fragmentVariables(config2, documents) {
|
|
55339
|
+
const fragments = collectFragments(config2, documents);
|
|
55340
|
+
const generatedFragments = {};
|
|
55341
|
+
const visitedFragments = /* @__PURE__ */ new Set();
|
|
55342
|
+
for (const doc2 of documents) {
|
|
55343
|
+
const operation = doc2.document.definitions.find(
|
|
55344
|
+
({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
|
|
55345
|
+
);
|
|
55346
|
+
if (!operation) {
|
|
55347
|
+
continue;
|
|
55348
|
+
}
|
|
55349
|
+
doc2.document = inlineFragmentArgs({
|
|
55350
|
+
config: config2,
|
|
55351
|
+
filepath: doc2.filename,
|
|
55352
|
+
fragmentDefinitions: fragments,
|
|
55353
|
+
document: doc2.document,
|
|
55354
|
+
generatedFragments,
|
|
55355
|
+
visitedFragments,
|
|
55356
|
+
scope: null
|
|
55357
|
+
});
|
|
55382
55358
|
}
|
|
55383
|
-
|
|
55359
|
+
const doc = {
|
|
55360
|
+
kind: graphql3.Kind.DOCUMENT,
|
|
55361
|
+
definitions: Object.values(generatedFragments)
|
|
55362
|
+
};
|
|
55363
|
+
documents.push({
|
|
55364
|
+
name: "generated::fragmentVariables",
|
|
55365
|
+
kind: "HoudiniFragment" /* Fragment */,
|
|
55366
|
+
document: doc,
|
|
55367
|
+
originalDocument: doc,
|
|
55368
|
+
generateStore: false,
|
|
55369
|
+
generateArtifact: false,
|
|
55370
|
+
filename: "generated::fragmentVariables",
|
|
55371
|
+
originalString: ""
|
|
55372
|
+
});
|
|
55384
55373
|
}
|
|
55385
|
-
|
|
55386
|
-
|
|
55387
|
-
|
|
55388
|
-
|
|
55389
|
-
|
|
55374
|
+
function inlineFragmentArgs({
|
|
55375
|
+
config: config2,
|
|
55376
|
+
filepath,
|
|
55377
|
+
fragmentDefinitions,
|
|
55378
|
+
document,
|
|
55379
|
+
generatedFragments,
|
|
55380
|
+
visitedFragments,
|
|
55381
|
+
scope,
|
|
55382
|
+
newName
|
|
55383
|
+
}) {
|
|
55384
|
+
if (!scope) {
|
|
55385
|
+
scope = operationScope(
|
|
55386
|
+
document.definitions.find(
|
|
55387
|
+
({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
|
|
55388
|
+
)
|
|
55389
|
+
);
|
|
55390
55390
|
}
|
|
55391
|
-
const
|
|
55392
|
-
|
|
55393
|
-
|
|
55394
|
-
|
|
55395
|
-
|
|
55396
|
-
|
|
55397
|
-
|
|
55398
|
-
|
|
55399
|
-
|
|
55400
|
-
}
|
|
55401
|
-
|
|
55402
|
-
|
|
55391
|
+
const definitionArgs = fragmentArguments(
|
|
55392
|
+
config2,
|
|
55393
|
+
filepath,
|
|
55394
|
+
document
|
|
55395
|
+
).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
|
|
55396
|
+
const result = graphql3.visit(document, {
|
|
55397
|
+
FragmentSpread(node) {
|
|
55398
|
+
const { definition } = fragmentDefinitions[node.name.value];
|
|
55399
|
+
let { args, hash } = collectWithArguments(config2, filepath, node, scope);
|
|
55400
|
+
const newFragmentName = `${node.name.value}${hash}`;
|
|
55401
|
+
if (!visitedFragments.has(newFragmentName)) {
|
|
55402
|
+
visitedFragments.add(newFragmentName);
|
|
55403
|
+
const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
|
|
55404
|
+
if (args) {
|
|
55405
|
+
for (const [field, value] of Object.entries(defaultArguments || {})) {
|
|
55406
|
+
if (!args[field]) {
|
|
55407
|
+
args[field] = value;
|
|
55408
|
+
}
|
|
55409
|
+
}
|
|
55410
|
+
generatedFragments[newFragmentName] = inlineFragmentArgs({
|
|
55411
|
+
config: config2,
|
|
55412
|
+
filepath,
|
|
55413
|
+
fragmentDefinitions,
|
|
55414
|
+
document: fragmentDefinitions[node.name.value].definition,
|
|
55415
|
+
generatedFragments,
|
|
55416
|
+
visitedFragments,
|
|
55417
|
+
scope: args,
|
|
55418
|
+
newName: newFragmentName
|
|
55419
|
+
});
|
|
55420
|
+
} else {
|
|
55421
|
+
const doc = fragmentDefinitions[node.name.value].document;
|
|
55422
|
+
const definitionIndex = doc.document.definitions.findIndex(
|
|
55423
|
+
(definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
|
|
55424
|
+
);
|
|
55425
|
+
const localDefinitions = [...doc.document.definitions];
|
|
55426
|
+
localDefinitions.splice(definitionIndex, 1);
|
|
55427
|
+
localDefinitions.push(
|
|
55428
|
+
inlineFragmentArgs({
|
|
55429
|
+
config: config2,
|
|
55430
|
+
filepath,
|
|
55431
|
+
fragmentDefinitions,
|
|
55432
|
+
document: fragmentDefinitions[node.name.value].definition,
|
|
55433
|
+
generatedFragments,
|
|
55434
|
+
visitedFragments,
|
|
55435
|
+
scope: defaultArguments,
|
|
55436
|
+
newName: ""
|
|
55437
|
+
})
|
|
55438
|
+
);
|
|
55439
|
+
doc.document = {
|
|
55440
|
+
...doc.document,
|
|
55441
|
+
definitions: localDefinitions
|
|
55442
|
+
};
|
|
55443
|
+
}
|
|
55444
|
+
if (node.name.value !== newFragmentName) {
|
|
55445
|
+
return {
|
|
55446
|
+
...node,
|
|
55447
|
+
name: {
|
|
55448
|
+
kind: "Name",
|
|
55449
|
+
value: newFragmentName
|
|
55450
|
+
}
|
|
55451
|
+
};
|
|
55452
|
+
}
|
|
55453
|
+
}
|
|
55454
|
+
},
|
|
55455
|
+
Argument(node) {
|
|
55456
|
+
const value = node.value;
|
|
55457
|
+
if (value.kind !== "Variable") {
|
|
55458
|
+
return;
|
|
55459
|
+
}
|
|
55460
|
+
if (!scope) {
|
|
55461
|
+
throw new HoudiniError({
|
|
55462
|
+
filepath,
|
|
55463
|
+
message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
|
|
55464
|
+
});
|
|
55465
|
+
}
|
|
55466
|
+
const newValue = scope[value.name.value];
|
|
55467
|
+
if (newValue) {
|
|
55468
|
+
return {
|
|
55469
|
+
...node,
|
|
55470
|
+
value: newValue
|
|
55471
|
+
};
|
|
55472
|
+
}
|
|
55473
|
+
if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
|
|
55474
|
+
throw new HoudiniError({
|
|
55475
|
+
filepath,
|
|
55476
|
+
message: "Missing value for required arg: " + value.name.value
|
|
55477
|
+
});
|
|
55478
|
+
}
|
|
55479
|
+
return null;
|
|
55480
|
+
}
|
|
55481
|
+
});
|
|
55482
|
+
if (newName) {
|
|
55483
|
+
result.name = {
|
|
55484
|
+
kind: graphql3.Kind.NAME,
|
|
55485
|
+
value: newName
|
|
55486
|
+
};
|
|
55487
|
+
}
|
|
55488
|
+
return result;
|
|
55489
|
+
}
|
|
55490
|
+
function withArguments(config2, node) {
|
|
55491
|
+
const withDirectives = node.directives?.filter(
|
|
55492
|
+
(directive) => directive.name.value === config2.withDirective
|
|
55493
|
+
);
|
|
55494
|
+
if (!withDirectives || withDirectives.length === 0) {
|
|
55495
|
+
return [];
|
|
55496
|
+
}
|
|
55497
|
+
return withDirectives.flatMap((directive) => directive.arguments || []);
|
|
55498
|
+
}
|
|
55499
|
+
function fragmentArguments(config2, filepath, definition) {
|
|
55500
|
+
const directives = definition.directives?.filter(
|
|
55501
|
+
(directive) => directive.name.value === config2.argumentsDirective
|
|
55502
|
+
);
|
|
55503
|
+
if (!directives || directives.length === 0) {
|
|
55504
|
+
return [];
|
|
55505
|
+
}
|
|
55506
|
+
return directives.flatMap(
|
|
55507
|
+
(directive) => directive.arguments?.flatMap((arg) => {
|
|
55508
|
+
if (arg.value.kind !== "ObjectValue") {
|
|
55509
|
+
throw new HoudiniError({
|
|
55510
|
+
filepath,
|
|
55511
|
+
message: "values of @argument must be objects"
|
|
55512
|
+
});
|
|
55513
|
+
}
|
|
55514
|
+
const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
|
|
55515
|
+
if (!typeArg || typeArg.kind !== "StringValue") {
|
|
55516
|
+
return [];
|
|
55517
|
+
}
|
|
55518
|
+
let type = typeArg.value;
|
|
55519
|
+
let name2 = arg.name.value;
|
|
55520
|
+
let required = false;
|
|
55521
|
+
let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
|
|
55522
|
+
if (type[type.length - 1] === "!") {
|
|
55523
|
+
type = type.slice(0, -1);
|
|
55524
|
+
required = true;
|
|
55525
|
+
defaultValue = null;
|
|
55526
|
+
}
|
|
55527
|
+
return [
|
|
55528
|
+
{
|
|
55529
|
+
name: name2,
|
|
55530
|
+
type,
|
|
55531
|
+
required,
|
|
55532
|
+
defaultValue
|
|
55533
|
+
}
|
|
55534
|
+
];
|
|
55535
|
+
}) || []
|
|
55536
|
+
);
|
|
55537
|
+
}
|
|
55538
|
+
function collectDefaultArgumentValues(config2, filepath, definition) {
|
|
55539
|
+
let result = {};
|
|
55540
|
+
for (const { name: name2, required, defaultValue } of fragmentArguments(
|
|
55541
|
+
config2,
|
|
55542
|
+
filepath,
|
|
55543
|
+
definition
|
|
55544
|
+
)) {
|
|
55545
|
+
if (required || !defaultValue) {
|
|
55546
|
+
continue;
|
|
55547
|
+
}
|
|
55548
|
+
result[name2] = defaultValue;
|
|
55549
|
+
}
|
|
55550
|
+
return result;
|
|
55551
|
+
}
|
|
55552
|
+
function collectWithArguments(config2, filepath, node, scope = {}) {
|
|
55553
|
+
const withArgs = withArguments(config2, node);
|
|
55554
|
+
if (withArgs.length === 0) {
|
|
55555
|
+
return { args: null, hash: "" };
|
|
55556
|
+
}
|
|
55557
|
+
let args = {};
|
|
55558
|
+
for (const arg of withArgs) {
|
|
55559
|
+
let value = arg.value;
|
|
55560
|
+
if (value.kind === GraphqlKinds2.VARIABLE) {
|
|
55561
|
+
if (!scope || !scope[value.name.value]) {
|
|
55562
|
+
throw new HoudiniError({
|
|
55563
|
+
filepath,
|
|
55564
|
+
message: "Encountered undefined variable: " + value.name.value
|
|
55565
|
+
});
|
|
55566
|
+
}
|
|
55567
|
+
value = scope[value.name.value];
|
|
55568
|
+
}
|
|
55569
|
+
args[arg.name.value] = {
|
|
55570
|
+
...value,
|
|
55571
|
+
loc: void 0
|
|
55572
|
+
};
|
|
55573
|
+
}
|
|
55574
|
+
return {
|
|
55575
|
+
args,
|
|
55576
|
+
hash: "_" + murmurHash(JSON.stringify(args))
|
|
55577
|
+
};
|
|
55578
|
+
}
|
|
55579
|
+
function operationScope(operation) {
|
|
55580
|
+
return operation.variableDefinitions?.reduce(
|
|
55581
|
+
(scope, definition) => ({
|
|
55582
|
+
...scope,
|
|
55583
|
+
[definition.variable.name.value]: {
|
|
55584
|
+
kind: "Variable",
|
|
55585
|
+
name: {
|
|
55586
|
+
kind: "Name",
|
|
55587
|
+
value: definition.variable.name.value
|
|
55588
|
+
}
|
|
55589
|
+
}
|
|
55590
|
+
}),
|
|
55591
|
+
{}
|
|
55592
|
+
) || {};
|
|
55593
|
+
}
|
|
55594
|
+
function fragmentArgumentsDefinitions(config2, filepath, definition) {
|
|
55595
|
+
const args = fragmentArguments(config2, filepath, definition);
|
|
55596
|
+
if (args.length === 0) {
|
|
55597
|
+
return [];
|
|
55598
|
+
}
|
|
55599
|
+
return args.map((arg) => {
|
|
55600
|
+
const innerType = {
|
|
55601
|
+
kind: "NamedType",
|
|
55602
|
+
name: {
|
|
55603
|
+
kind: "Name",
|
|
55604
|
+
value: arg.type
|
|
55605
|
+
}
|
|
55606
|
+
};
|
|
55607
|
+
return {
|
|
55608
|
+
kind: "VariableDefinition",
|
|
55609
|
+
type: arg.required ? innerType : {
|
|
55610
|
+
kind: "NonNullType",
|
|
55611
|
+
type: innerType
|
|
55612
|
+
},
|
|
55613
|
+
variable: {
|
|
55614
|
+
kind: "Variable",
|
|
55615
|
+
name: {
|
|
55616
|
+
kind: "Name",
|
|
55617
|
+
value: arg.name
|
|
55618
|
+
}
|
|
55619
|
+
},
|
|
55620
|
+
defaultValue: arg.defaultValue ?? void 0
|
|
55621
|
+
};
|
|
55622
|
+
});
|
|
55623
|
+
}
|
|
55624
|
+
|
|
55625
|
+
// src/codegen/generators/artifacts/indexFile.ts
|
|
55626
|
+
async function writeIndexFile(config2, docs) {
|
|
55627
|
+
const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
|
|
55628
|
+
let body = config2.module === "esm" ? docsToGenerate.reduce(
|
|
55629
|
+
(content, doc) => content + `
|
|
55630
|
+
export { default as ${doc.name}} from './${doc.name}'`,
|
|
55631
|
+
""
|
|
55632
|
+
) : docsToGenerate.reduce(
|
|
55633
|
+
(content, doc) => content + `
|
|
55634
|
+
${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
|
|
55635
|
+
cjsIndexFilePreamble
|
|
55636
|
+
);
|
|
55637
|
+
await fs_exports.writeFile(path_exports.join(config2.artifactDirectory, "index.js"), body);
|
|
55638
|
+
}
|
|
55639
|
+
|
|
55640
|
+
// src/codegen/generators/artifacts/inputs.ts
|
|
55641
|
+
var graphql4 = __toESM(require_graphql2(), 1);
|
|
55642
|
+
var recast3 = __toESM(require_main2(), 1);
|
|
55643
|
+
var AST3 = recast3.types.builders;
|
|
55644
|
+
function inputObject(config2, inputs) {
|
|
55645
|
+
const visitedTypes = /* @__PURE__ */ new Set();
|
|
55646
|
+
const inputObj = {
|
|
55647
|
+
fields: inputs.reduce((fields, input) => {
|
|
55648
|
+
const { type } = unwrapType(config2, input.type);
|
|
55649
|
+
return {
|
|
55650
|
+
...fields,
|
|
55651
|
+
[input.variable.name.value]: type.name
|
|
55652
|
+
};
|
|
55653
|
+
}, {}),
|
|
55654
|
+
types: {}
|
|
55655
|
+
};
|
|
55656
|
+
for (const input of inputs) {
|
|
55657
|
+
walkInputs(config2, visitedTypes, inputObj, input.type);
|
|
55658
|
+
}
|
|
55659
|
+
return inputObj;
|
|
55660
|
+
}
|
|
55661
|
+
function walkInputs(config2, visitedTypes, inputObj, rootType) {
|
|
55662
|
+
const { type } = unwrapType(config2, rootType);
|
|
55663
|
+
if (visitedTypes.has(type.name)) {
|
|
55664
|
+
return;
|
|
55665
|
+
}
|
|
55666
|
+
if (graphql4.isEnumType(type) || graphql4.isScalarType(type)) {
|
|
55667
|
+
return;
|
|
55668
|
+
}
|
|
55669
|
+
if (graphql4.isUnionType(type)) {
|
|
55670
|
+
return;
|
|
55671
|
+
}
|
|
55672
|
+
visitedTypes.add(type.name);
|
|
55673
|
+
inputObj.types[type.name] = Object.values(type.getFields()).reduce(
|
|
55674
|
+
(typeFields, field) => {
|
|
55675
|
+
const { type: fieldType } = unwrapType(config2, field.type);
|
|
55676
|
+
walkInputs(config2, visitedTypes, inputObj, fieldType);
|
|
55677
|
+
return {
|
|
55678
|
+
...typeFields,
|
|
55679
|
+
[field.name]: fieldType.toString()
|
|
55680
|
+
};
|
|
55681
|
+
},
|
|
55682
|
+
{}
|
|
55683
|
+
);
|
|
55684
|
+
}
|
|
55685
|
+
|
|
55686
|
+
// src/codegen/generators/artifacts/operations.ts
|
|
55687
|
+
var graphql6 = __toESM(require_graphql2(), 1);
|
|
55688
|
+
|
|
55689
|
+
// src/codegen/generators/artifacts/utils.ts
|
|
55690
|
+
var graphql5 = __toESM(require_graphql2(), 1);
|
|
55691
|
+
var recast4 = __toESM(require_main2(), 1);
|
|
55692
|
+
var AST4 = recast4.types.builders;
|
|
55693
|
+
function serializeValue(value) {
|
|
55694
|
+
if (Array.isArray(value)) {
|
|
55695
|
+
return AST4.arrayExpression(value.map(serializeValue));
|
|
55696
|
+
}
|
|
55697
|
+
if (typeof value === "object" && value !== null) {
|
|
55698
|
+
return AST4.objectExpression(
|
|
55699
|
+
Object.entries(value).filter(([, value2]) => typeof value2 !== "undefined").map(
|
|
55700
|
+
([key, value2]) => AST4.objectProperty(AST4.stringLiteral(key), serializeValue(value2))
|
|
55701
|
+
)
|
|
55702
|
+
);
|
|
55703
|
+
}
|
|
55704
|
+
if (typeof value === "string") {
|
|
55705
|
+
if (value.indexOf("\n") !== -1) {
|
|
55706
|
+
return AST4.templateLiteral(
|
|
55707
|
+
[AST4.templateElement({ raw: value, cooked: value }, true)],
|
|
55708
|
+
[]
|
|
55709
|
+
);
|
|
55710
|
+
}
|
|
55711
|
+
return AST4.stringLiteral(value);
|
|
55712
|
+
}
|
|
55713
|
+
return AST4.literal(value);
|
|
55714
|
+
}
|
|
55715
|
+
function deepMerge(filepath, ...targets) {
|
|
55716
|
+
if (typeof targets[0] !== "object") {
|
|
55717
|
+
const matches = targets.filter((val) => val !== targets[0]).length === 0;
|
|
55718
|
+
if (!matches) {
|
|
55719
|
+
throw new HoudiniError({ filepath, message: "could not merge: " + targets });
|
|
55720
|
+
}
|
|
55721
|
+
return targets[0];
|
|
55722
|
+
}
|
|
55723
|
+
if (Array.isArray(targets[0])) {
|
|
55724
|
+
return targets[0].concat(...targets.slice(1));
|
|
55725
|
+
}
|
|
55726
|
+
const fields = {};
|
|
55727
|
+
for (const target of targets) {
|
|
55728
|
+
for (const [key, value] of Object.entries(target)) {
|
|
55729
|
+
if (!fields[key]) {
|
|
55730
|
+
fields[key] = [];
|
|
55731
|
+
}
|
|
55732
|
+
fields[key].push(value);
|
|
55733
|
+
}
|
|
55734
|
+
}
|
|
55735
|
+
return Object.fromEntries(
|
|
55736
|
+
Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
|
|
55737
|
+
);
|
|
55738
|
+
}
|
|
55739
|
+
function convertValue(config2, val) {
|
|
55740
|
+
let value;
|
|
55741
|
+
let kind;
|
|
55742
|
+
if (val.kind === graphql5.Kind.INT) {
|
|
55743
|
+
value = parseInt(val.value, 10);
|
|
55744
|
+
kind = "Int";
|
|
55745
|
+
} else if (val.kind === graphql5.Kind.FLOAT) {
|
|
55746
|
+
value = parseFloat(val.value);
|
|
55747
|
+
kind = "Float";
|
|
55748
|
+
} else if (val.kind === graphql5.Kind.BOOLEAN) {
|
|
55749
|
+
value = val.value;
|
|
55750
|
+
kind = "Boolean";
|
|
55751
|
+
} else if (val.kind === graphql5.Kind.VARIABLE) {
|
|
55752
|
+
value = val.name.value;
|
|
55753
|
+
kind = "Variable";
|
|
55754
|
+
} else if (val.kind === graphql5.Kind.STRING) {
|
|
55755
|
+
value = val.value;
|
|
55756
|
+
kind = "String";
|
|
55757
|
+
}
|
|
55758
|
+
return { kind, value };
|
|
55759
|
+
}
|
|
55760
|
+
|
|
55761
|
+
// src/codegen/generators/artifacts/operations.ts
|
|
55762
|
+
function operationsByPath(config2, filepath, definition, filterTypes) {
|
|
55763
|
+
if (!definition) {
|
|
55764
|
+
return {};
|
|
55765
|
+
}
|
|
55766
|
+
const pathOperations = {};
|
|
55767
|
+
graphql6.visit(definition, {
|
|
55768
|
+
FragmentSpread(node, _, __, ___, ancestors) {
|
|
55769
|
+
if (!config2.isListFragment(node.name.value)) {
|
|
55770
|
+
return;
|
|
55771
|
+
}
|
|
55772
|
+
const path2 = ancestorKey(ancestors);
|
|
55773
|
+
if (!pathOperations[path2]) {
|
|
55774
|
+
pathOperations[path2] = [];
|
|
55775
|
+
}
|
|
55776
|
+
pathOperations[path2].push(
|
|
55777
|
+
operationObject({
|
|
55403
55778
|
config: config2,
|
|
55404
55779
|
filepath,
|
|
55405
55780
|
listName: config2.listNameFromFragment(node.name.value),
|
|
@@ -55548,7 +55923,7 @@ function ancestorKey(ancestors) {
|
|
|
55548
55923
|
}
|
|
55549
55924
|
|
|
55550
55925
|
// src/codegen/generators/artifacts/selection.ts
|
|
55551
|
-
var
|
|
55926
|
+
var graphql11 = __toESM(require_graphql2(), 1);
|
|
55552
55927
|
|
|
55553
55928
|
// ../../node_modules/.pnpm/@kitql+helper@0.5.0/node_modules/@kitql/helper/index.mjs
|
|
55554
55929
|
var config = {
|
|
@@ -55588,16 +55963,16 @@ function logYellow(str) {
|
|
|
55588
55963
|
}
|
|
55589
55964
|
|
|
55590
55965
|
// src/codegen/transforms/list.ts
|
|
55591
|
-
var
|
|
55966
|
+
var graphql9 = __toESM(require_graphql2(), 1);
|
|
55592
55967
|
|
|
55593
55968
|
// src/codegen/utils/objectIdentificationSelection.ts
|
|
55594
|
-
var
|
|
55969
|
+
var graphql7 = __toESM(require_graphql2(), 1);
|
|
55595
55970
|
var objectIdentificationSelection = (config2, type) => {
|
|
55596
55971
|
return config2.keyFieldsForType(type.name).map((key) => {
|
|
55597
55972
|
return {
|
|
55598
|
-
kind:
|
|
55973
|
+
kind: graphql7.Kind.FIELD,
|
|
55599
55974
|
name: {
|
|
55600
|
-
kind:
|
|
55975
|
+
kind: graphql7.Kind.NAME,
|
|
55601
55976
|
value: key
|
|
55602
55977
|
}
|
|
55603
55978
|
};
|
|
@@ -55605,7 +55980,7 @@ var objectIdentificationSelection = (config2, type) => {
|
|
|
55605
55980
|
};
|
|
55606
55981
|
|
|
55607
55982
|
// src/codegen/transforms/paginate.ts
|
|
55608
|
-
var
|
|
55983
|
+
var graphql8 = __toESM(require_graphql2(), 1);
|
|
55609
55984
|
async function paginate(config2, documents) {
|
|
55610
55985
|
const newDocs = [];
|
|
55611
55986
|
for (const doc of documents) {
|
|
@@ -55638,7 +56013,7 @@ async function paginate(config2, documents) {
|
|
|
55638
56013
|
};
|
|
55639
56014
|
let cursorType = "String";
|
|
55640
56015
|
let paginationPath = [];
|
|
55641
|
-
doc.document =
|
|
56016
|
+
doc.document = graphql8.visit(doc.document, {
|
|
55642
56017
|
Field(node, _, __, ___, ancestors) {
|
|
55643
56018
|
const paginateDirective = node.directives?.find(
|
|
55644
56019
|
(directive) => directive.name.value === config2.paginateDirective
|
|
@@ -55665,7 +56040,7 @@ async function paginate(config2, documents) {
|
|
|
55665
56040
|
flags.offset.enabled = offsetPagination;
|
|
55666
56041
|
flags.limit.enabled = offsetPagination;
|
|
55667
56042
|
paginationPath = ancestors.filter(
|
|
55668
|
-
(ancestor) => !Array.isArray(ancestor) && ancestor.kind ===
|
|
56043
|
+
(ancestor) => !Array.isArray(ancestor) && ancestor.kind === graphql8.Kind.FIELD
|
|
55669
56044
|
).concat(node).map((field) => field.alias?.value || field.name.value);
|
|
55670
56045
|
return {
|
|
55671
56046
|
...node,
|
|
@@ -55686,7 +56061,7 @@ async function paginate(config2, documents) {
|
|
|
55686
56061
|
refetchUpdate = "prepend" /* prepend */;
|
|
55687
56062
|
}
|
|
55688
56063
|
let fragment = "";
|
|
55689
|
-
doc.document =
|
|
56064
|
+
doc.document = graphql8.visit(doc.document, {
|
|
55690
56065
|
OperationDefinition(node) {
|
|
55691
56066
|
if (node.operation !== "query") {
|
|
55692
56067
|
throw new HoudiniError({
|
|
@@ -55740,9 +56115,9 @@ async function paginate(config2, documents) {
|
|
|
55740
56115
|
directives: [
|
|
55741
56116
|
...node.directives || [],
|
|
55742
56117
|
{
|
|
55743
|
-
kind:
|
|
56118
|
+
kind: graphql8.Kind.DIRECTIVE,
|
|
55744
56119
|
name: {
|
|
55745
|
-
kind:
|
|
56120
|
+
kind: graphql8.Kind.NAME,
|
|
55746
56121
|
value: config2.argumentsDirective
|
|
55747
56122
|
}
|
|
55748
56123
|
}
|
|
@@ -55805,16 +56180,16 @@ async function paginate(config2, documents) {
|
|
|
55805
56180
|
const paginationArgs = Object.entries(flags).filter(([_, { enabled }]) => enabled).map(([key, value]) => ({ name: key, ...value }));
|
|
55806
56181
|
const fragmentSpreadSelection = [
|
|
55807
56182
|
{
|
|
55808
|
-
kind:
|
|
56183
|
+
kind: graphql8.Kind.FRAGMENT_SPREAD,
|
|
55809
56184
|
name: {
|
|
55810
|
-
kind:
|
|
56185
|
+
kind: graphql8.Kind.NAME,
|
|
55811
56186
|
value: fragmentName
|
|
55812
56187
|
},
|
|
55813
56188
|
directives: [
|
|
55814
56189
|
{
|
|
55815
|
-
kind:
|
|
56190
|
+
kind: graphql8.Kind.DIRECTIVE,
|
|
55816
56191
|
name: {
|
|
55817
|
-
kind:
|
|
56192
|
+
kind: graphql8.Kind.NAME,
|
|
55818
56193
|
value: config2.withDirective
|
|
55819
56194
|
},
|
|
55820
56195
|
["arguments"]: paginationArgs.map(
|
|
@@ -55842,29 +56217,29 @@ async function paginate(config2, documents) {
|
|
|
55842
56217
|
});
|
|
55843
56218
|
const typeConfig = config2.typeConfig?.[fragment];
|
|
55844
56219
|
const queryDoc = {
|
|
55845
|
-
kind:
|
|
56220
|
+
kind: graphql8.Kind.DOCUMENT,
|
|
55846
56221
|
definitions: [
|
|
55847
56222
|
{
|
|
55848
|
-
kind:
|
|
56223
|
+
kind: graphql8.Kind.OPERATION_DEFINITION,
|
|
55849
56224
|
name: {
|
|
55850
|
-
kind:
|
|
56225
|
+
kind: graphql8.Kind.NAME,
|
|
55851
56226
|
value: refetchQueryName
|
|
55852
56227
|
},
|
|
55853
56228
|
operation: "query",
|
|
55854
56229
|
variableDefinitions: paginationArgs.map(
|
|
55855
56230
|
(arg) => ({
|
|
55856
|
-
kind:
|
|
56231
|
+
kind: graphql8.Kind.VARIABLE_DEFINITION,
|
|
55857
56232
|
type: {
|
|
55858
|
-
kind:
|
|
56233
|
+
kind: graphql8.Kind.NAMED_TYPE,
|
|
55859
56234
|
name: {
|
|
55860
|
-
kind:
|
|
56235
|
+
kind: graphql8.Kind.NAME,
|
|
55861
56236
|
value: arg.type
|
|
55862
56237
|
}
|
|
55863
56238
|
},
|
|
55864
56239
|
variable: {
|
|
55865
|
-
kind:
|
|
56240
|
+
kind: graphql8.Kind.VARIABLE,
|
|
55866
56241
|
name: {
|
|
55867
|
-
kind:
|
|
56242
|
+
kind: graphql8.Kind.NAME,
|
|
55868
56243
|
value: arg.name
|
|
55869
56244
|
}
|
|
55870
56245
|
},
|
|
@@ -55876,12 +56251,12 @@ async function paginate(config2, documents) {
|
|
|
55876
56251
|
).concat(
|
|
55877
56252
|
!nodeQuery ? [] : keys.map(
|
|
55878
56253
|
(key) => ({
|
|
55879
|
-
kind:
|
|
56254
|
+
kind: graphql8.Kind.VARIABLE_DEFINITION,
|
|
55880
56255
|
type: key.type,
|
|
55881
56256
|
variable: {
|
|
55882
|
-
kind:
|
|
56257
|
+
kind: graphql8.Kind.VARIABLE,
|
|
55883
56258
|
name: {
|
|
55884
|
-
kind:
|
|
56259
|
+
kind: graphql8.Kind.NAME,
|
|
55885
56260
|
value: key.name
|
|
55886
56261
|
}
|
|
55887
56262
|
}
|
|
@@ -55889,42 +56264,42 @@ async function paginate(config2, documents) {
|
|
|
55889
56264
|
)
|
|
55890
56265
|
),
|
|
55891
56266
|
selectionSet: {
|
|
55892
|
-
kind:
|
|
56267
|
+
kind: graphql8.Kind.SELECTION_SET,
|
|
55893
56268
|
selections: !nodeQuery ? fragmentSpreadSelection : [
|
|
55894
56269
|
{
|
|
55895
|
-
kind:
|
|
56270
|
+
kind: graphql8.Kind.FIELD,
|
|
55896
56271
|
name: {
|
|
55897
|
-
kind:
|
|
56272
|
+
kind: graphql8.Kind.NAME,
|
|
55898
56273
|
value: typeConfig?.resolve?.queryField || "node"
|
|
55899
56274
|
},
|
|
55900
56275
|
["arguments"]: keys.map((key) => ({
|
|
55901
|
-
kind:
|
|
56276
|
+
kind: graphql8.Kind.ARGUMENT,
|
|
55902
56277
|
name: {
|
|
55903
|
-
kind:
|
|
56278
|
+
kind: graphql8.Kind.NAME,
|
|
55904
56279
|
value: key.name
|
|
55905
56280
|
},
|
|
55906
56281
|
value: {
|
|
55907
|
-
kind:
|
|
56282
|
+
kind: graphql8.Kind.VARIABLE,
|
|
55908
56283
|
name: {
|
|
55909
|
-
kind:
|
|
56284
|
+
kind: graphql8.Kind.NAME,
|
|
55910
56285
|
value: key.name
|
|
55911
56286
|
}
|
|
55912
56287
|
}
|
|
55913
56288
|
})),
|
|
55914
56289
|
selectionSet: {
|
|
55915
|
-
kind:
|
|
56290
|
+
kind: graphql8.Kind.SELECTION_SET,
|
|
55916
56291
|
selections: [
|
|
55917
56292
|
{
|
|
55918
|
-
kind:
|
|
56293
|
+
kind: graphql8.Kind.FIELD,
|
|
55919
56294
|
name: {
|
|
55920
|
-
kind:
|
|
56295
|
+
kind: graphql8.Kind.NAME,
|
|
55921
56296
|
value: "__typename"
|
|
55922
56297
|
}
|
|
55923
56298
|
},
|
|
55924
56299
|
...(typeConfig?.keys || ["id"]).map((key) => ({
|
|
55925
|
-
kind:
|
|
56300
|
+
kind: graphql8.Kind.FIELD,
|
|
55926
56301
|
name: {
|
|
55927
|
-
kind:
|
|
56302
|
+
kind: graphql8.Kind.NAME,
|
|
55928
56303
|
value: key
|
|
55929
56304
|
}
|
|
55930
56305
|
})),
|
|
@@ -55986,15 +56361,15 @@ function replaceArgumentsWithVariables(args, flags) {
|
|
|
55986
56361
|
}
|
|
55987
56362
|
function variableAsArgument(name2, variable) {
|
|
55988
56363
|
return {
|
|
55989
|
-
kind:
|
|
56364
|
+
kind: graphql8.Kind.ARGUMENT,
|
|
55990
56365
|
name: {
|
|
55991
|
-
kind:
|
|
56366
|
+
kind: graphql8.Kind.NAME,
|
|
55992
56367
|
value: name2
|
|
55993
56368
|
},
|
|
55994
56369
|
value: {
|
|
55995
|
-
kind:
|
|
56370
|
+
kind: graphql8.Kind.VARIABLE,
|
|
55996
56371
|
name: {
|
|
55997
|
-
kind:
|
|
56372
|
+
kind: graphql8.Kind.NAME,
|
|
55998
56373
|
value: variable ?? name2
|
|
55999
56374
|
}
|
|
56000
56375
|
}
|
|
@@ -56002,18 +56377,18 @@ function variableAsArgument(name2, variable) {
|
|
|
56002
56377
|
}
|
|
56003
56378
|
function staticVariableDefinition(name2, type, defaultValue, variableName) {
|
|
56004
56379
|
return {
|
|
56005
|
-
kind:
|
|
56380
|
+
kind: graphql8.Kind.VARIABLE_DEFINITION,
|
|
56006
56381
|
type: {
|
|
56007
|
-
kind:
|
|
56382
|
+
kind: graphql8.Kind.NAMED_TYPE,
|
|
56008
56383
|
name: {
|
|
56009
|
-
kind:
|
|
56384
|
+
kind: graphql8.Kind.NAME,
|
|
56010
56385
|
value: type
|
|
56011
56386
|
}
|
|
56012
56387
|
},
|
|
56013
56388
|
variable: {
|
|
56014
|
-
kind:
|
|
56389
|
+
kind: graphql8.Kind.VARIABLE,
|
|
56015
56390
|
name: {
|
|
56016
|
-
kind:
|
|
56391
|
+
kind: graphql8.Kind.NAME,
|
|
56017
56392
|
value: variableName ?? name2
|
|
56018
56393
|
}
|
|
56019
56394
|
},
|
|
@@ -56025,9 +56400,9 @@ function staticVariableDefinition(name2, type, defaultValue, variableName) {
|
|
|
56025
56400
|
}
|
|
56026
56401
|
function argumentNode(name2, value) {
|
|
56027
56402
|
return {
|
|
56028
|
-
kind:
|
|
56403
|
+
kind: graphql8.Kind.ARGUMENT,
|
|
56029
56404
|
name: {
|
|
56030
|
-
kind:
|
|
56405
|
+
kind: graphql8.Kind.NAME,
|
|
56031
56406
|
value: name2
|
|
56032
56407
|
},
|
|
56033
56408
|
value: objectNode(value)
|
|
@@ -56035,16 +56410,16 @@ function argumentNode(name2, value) {
|
|
|
56035
56410
|
}
|
|
56036
56411
|
function objectNode([type, defaultValue]) {
|
|
56037
56412
|
const node = {
|
|
56038
|
-
kind:
|
|
56413
|
+
kind: graphql8.Kind.OBJECT,
|
|
56039
56414
|
fields: [
|
|
56040
56415
|
{
|
|
56041
|
-
kind:
|
|
56416
|
+
kind: graphql8.Kind.OBJECT_FIELD,
|
|
56042
56417
|
name: {
|
|
56043
|
-
kind:
|
|
56418
|
+
kind: graphql8.Kind.NAME,
|
|
56044
56419
|
value: "type"
|
|
56045
56420
|
},
|
|
56046
56421
|
value: {
|
|
56047
|
-
kind:
|
|
56422
|
+
kind: graphql8.Kind.STRING,
|
|
56048
56423
|
value: type
|
|
56049
56424
|
}
|
|
56050
56425
|
}
|
|
@@ -56052,8 +56427,8 @@ function objectNode([type, defaultValue]) {
|
|
|
56052
56427
|
};
|
|
56053
56428
|
if (defaultValue) {
|
|
56054
56429
|
node.fields.push({
|
|
56055
|
-
kind:
|
|
56056
|
-
name: { kind:
|
|
56430
|
+
kind: graphql8.Kind.OBJECT_FIELD,
|
|
56431
|
+
name: { kind: graphql8.Kind.NAME, value: "default" },
|
|
56057
56432
|
value: {
|
|
56058
56433
|
kind: typeof defaultValue === "number" ? "IntValue" : "StringValue",
|
|
56059
56434
|
value: defaultValue.toString()
|
|
@@ -56064,34 +56439,34 @@ function objectNode([type, defaultValue]) {
|
|
|
56064
56439
|
}
|
|
56065
56440
|
var pageInfoSelection = [
|
|
56066
56441
|
{
|
|
56067
|
-
kind:
|
|
56442
|
+
kind: graphql8.Kind.FIELD,
|
|
56068
56443
|
name: {
|
|
56069
|
-
kind:
|
|
56444
|
+
kind: graphql8.Kind.NAME,
|
|
56070
56445
|
value: "edges"
|
|
56071
56446
|
},
|
|
56072
56447
|
selectionSet: {
|
|
56073
|
-
kind:
|
|
56448
|
+
kind: graphql8.Kind.SELECTION_SET,
|
|
56074
56449
|
selections: [
|
|
56075
56450
|
{
|
|
56076
|
-
kind:
|
|
56451
|
+
kind: graphql8.Kind.FIELD,
|
|
56077
56452
|
name: {
|
|
56078
|
-
kind:
|
|
56453
|
+
kind: graphql8.Kind.NAME,
|
|
56079
56454
|
value: "cursor"
|
|
56080
56455
|
}
|
|
56081
56456
|
},
|
|
56082
56457
|
{
|
|
56083
|
-
kind:
|
|
56458
|
+
kind: graphql8.Kind.FIELD,
|
|
56084
56459
|
name: {
|
|
56085
|
-
kind:
|
|
56460
|
+
kind: graphql8.Kind.NAME,
|
|
56086
56461
|
value: "node"
|
|
56087
56462
|
},
|
|
56088
56463
|
selectionSet: {
|
|
56089
|
-
kind:
|
|
56464
|
+
kind: graphql8.Kind.SELECTION_SET,
|
|
56090
56465
|
selections: [
|
|
56091
56466
|
{
|
|
56092
|
-
kind:
|
|
56467
|
+
kind: graphql8.Kind.FIELD,
|
|
56093
56468
|
name: {
|
|
56094
|
-
kind:
|
|
56469
|
+
kind: graphql8.Kind.NAME,
|
|
56095
56470
|
value: "__typename"
|
|
56096
56471
|
}
|
|
56097
56472
|
}
|
|
@@ -56102,39 +56477,39 @@ var pageInfoSelection = [
|
|
|
56102
56477
|
}
|
|
56103
56478
|
},
|
|
56104
56479
|
{
|
|
56105
|
-
kind:
|
|
56480
|
+
kind: graphql8.Kind.FIELD,
|
|
56106
56481
|
name: {
|
|
56107
|
-
kind:
|
|
56482
|
+
kind: graphql8.Kind.NAME,
|
|
56108
56483
|
value: "pageInfo"
|
|
56109
56484
|
},
|
|
56110
56485
|
selectionSet: {
|
|
56111
|
-
kind:
|
|
56486
|
+
kind: graphql8.Kind.SELECTION_SET,
|
|
56112
56487
|
selections: [
|
|
56113
56488
|
{
|
|
56114
|
-
kind:
|
|
56489
|
+
kind: graphql8.Kind.FIELD,
|
|
56115
56490
|
name: {
|
|
56116
|
-
kind:
|
|
56491
|
+
kind: graphql8.Kind.NAME,
|
|
56117
56492
|
value: "hasPreviousPage"
|
|
56118
56493
|
}
|
|
56119
56494
|
},
|
|
56120
56495
|
{
|
|
56121
|
-
kind:
|
|
56496
|
+
kind: graphql8.Kind.FIELD,
|
|
56122
56497
|
name: {
|
|
56123
|
-
kind:
|
|
56498
|
+
kind: graphql8.Kind.NAME,
|
|
56124
56499
|
value: "hasNextPage"
|
|
56125
56500
|
}
|
|
56126
56501
|
},
|
|
56127
56502
|
{
|
|
56128
|
-
kind:
|
|
56503
|
+
kind: graphql8.Kind.FIELD,
|
|
56129
56504
|
name: {
|
|
56130
|
-
kind:
|
|
56505
|
+
kind: graphql8.Kind.NAME,
|
|
56131
56506
|
value: "startCursor"
|
|
56132
56507
|
}
|
|
56133
56508
|
},
|
|
56134
56509
|
{
|
|
56135
|
-
kind:
|
|
56510
|
+
kind: graphql8.Kind.FIELD,
|
|
56136
56511
|
name: {
|
|
56137
|
-
kind:
|
|
56512
|
+
kind: graphql8.Kind.NAME,
|
|
56138
56513
|
value: "endCursor"
|
|
56139
56514
|
}
|
|
56140
56515
|
}
|
|
@@ -56148,15 +56523,15 @@ async function addListFragments(config2, documents) {
|
|
|
56148
56523
|
const lists = {};
|
|
56149
56524
|
const errors = [];
|
|
56150
56525
|
for (const doc of documents) {
|
|
56151
|
-
doc.document =
|
|
56526
|
+
doc.document = graphql9.visit(doc.document, {
|
|
56152
56527
|
Directive(node, key, parent, path2, ancestors) {
|
|
56153
56528
|
if ([config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
|
|
56154
56529
|
const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
|
|
56155
56530
|
let error = {
|
|
56156
|
-
...new
|
|
56531
|
+
...new graphql9.GraphQLError(
|
|
56157
56532
|
"",
|
|
56158
56533
|
node,
|
|
56159
|
-
new
|
|
56534
|
+
new graphql9.Source(""),
|
|
56160
56535
|
node.loc ? [node.loc.start, node.loc.end] : null,
|
|
56161
56536
|
path2
|
|
56162
56537
|
),
|
|
@@ -56208,7 +56583,7 @@ async function addListFragments(config2, documents) {
|
|
|
56208
56583
|
{
|
|
56209
56584
|
kind: "Argument",
|
|
56210
56585
|
name: {
|
|
56211
|
-
kind:
|
|
56586
|
+
kind: graphql9.Kind.NAME,
|
|
56212
56587
|
value: "connection"
|
|
56213
56588
|
},
|
|
56214
56589
|
value: {
|
|
@@ -56258,7 +56633,7 @@ async function addListFragments(config2, documents) {
|
|
|
56258
56633
|
const validDeletes = [
|
|
56259
56634
|
...new Set(
|
|
56260
56635
|
Object.values(lists).map(({ type }) => {
|
|
56261
|
-
if (!(type instanceof
|
|
56636
|
+
if (!(type instanceof graphql9.GraphQLObjectType)) {
|
|
56262
56637
|
return "";
|
|
56263
56638
|
}
|
|
56264
56639
|
if (config2.keyFieldsForType(type.name).length !== 1) {
|
|
@@ -56272,7 +56647,7 @@ async function addListFragments(config2, documents) {
|
|
|
56272
56647
|
return;
|
|
56273
56648
|
}
|
|
56274
56649
|
const generatedDoc = {
|
|
56275
|
-
kind:
|
|
56650
|
+
kind: graphql9.Kind.DOCUMENT,
|
|
56276
56651
|
definitions: Object.entries(lists).flatMap(
|
|
56277
56652
|
([name2, { selection: selection2, type }]) => {
|
|
56278
56653
|
const schemaType = config2.schema.getType(type.name);
|
|
@@ -56280,7 +56655,7 @@ async function addListFragments(config2, documents) {
|
|
|
56280
56655
|
throw new HoudiniError({ message: "Lists must have a selection" });
|
|
56281
56656
|
}
|
|
56282
56657
|
const fragmentSelection = {
|
|
56283
|
-
kind:
|
|
56658
|
+
kind: graphql9.Kind.SELECTION_SET,
|
|
56284
56659
|
selections: [...selection2.selections]
|
|
56285
56660
|
};
|
|
56286
56661
|
if (schemaType && fragmentSelection && !fragmentSelection?.selections.find(
|
|
@@ -56295,14 +56670,14 @@ async function addListFragments(config2, documents) {
|
|
|
56295
56670
|
{
|
|
56296
56671
|
name: {
|
|
56297
56672
|
value: config2.listInsertFragment(name2),
|
|
56298
|
-
kind:
|
|
56673
|
+
kind: graphql9.Kind.NAME
|
|
56299
56674
|
},
|
|
56300
|
-
kind:
|
|
56675
|
+
kind: graphql9.Kind.FRAGMENT_DEFINITION,
|
|
56301
56676
|
selectionSet: fragmentSelection,
|
|
56302
56677
|
typeCondition: {
|
|
56303
|
-
kind:
|
|
56678
|
+
kind: graphql9.Kind.NAMED_TYPE,
|
|
56304
56679
|
name: {
|
|
56305
|
-
kind:
|
|
56680
|
+
kind: graphql9.Kind.NAME,
|
|
56306
56681
|
value: type.name
|
|
56307
56682
|
}
|
|
56308
56683
|
}
|
|
@@ -56310,32 +56685,32 @@ async function addListFragments(config2, documents) {
|
|
|
56310
56685
|
{
|
|
56311
56686
|
name: {
|
|
56312
56687
|
value: config2.listToggleFragment(name2),
|
|
56313
|
-
kind:
|
|
56688
|
+
kind: graphql9.Kind.NAME
|
|
56314
56689
|
},
|
|
56315
|
-
kind:
|
|
56690
|
+
kind: graphql9.Kind.FRAGMENT_DEFINITION,
|
|
56316
56691
|
selectionSet: fragmentSelection,
|
|
56317
56692
|
typeCondition: {
|
|
56318
|
-
kind:
|
|
56693
|
+
kind: graphql9.Kind.NAMED_TYPE,
|
|
56319
56694
|
name: {
|
|
56320
|
-
kind:
|
|
56695
|
+
kind: graphql9.Kind.NAME,
|
|
56321
56696
|
value: type.name
|
|
56322
56697
|
}
|
|
56323
56698
|
}
|
|
56324
56699
|
},
|
|
56325
56700
|
{
|
|
56326
|
-
kind:
|
|
56701
|
+
kind: graphql9.Kind.FRAGMENT_DEFINITION,
|
|
56327
56702
|
name: {
|
|
56328
56703
|
value: config2.listRemoveFragment(name2),
|
|
56329
|
-
kind:
|
|
56704
|
+
kind: graphql9.Kind.NAME
|
|
56330
56705
|
},
|
|
56331
56706
|
selectionSet: {
|
|
56332
|
-
kind:
|
|
56707
|
+
kind: graphql9.Kind.SELECTION_SET,
|
|
56333
56708
|
selections: [...objectIdentificationSelection(config2, type)]
|
|
56334
56709
|
},
|
|
56335
56710
|
typeCondition: {
|
|
56336
|
-
kind:
|
|
56711
|
+
kind: graphql9.Kind.NAMED_TYPE,
|
|
56337
56712
|
name: {
|
|
56338
|
-
kind:
|
|
56713
|
+
kind: graphql9.Kind.NAME,
|
|
56339
56714
|
value: type.name
|
|
56340
56715
|
}
|
|
56341
56716
|
}
|
|
@@ -56344,14 +56719,14 @@ async function addListFragments(config2, documents) {
|
|
|
56344
56719
|
}
|
|
56345
56720
|
).concat(
|
|
56346
56721
|
...validDeletes.map((typeName) => ({
|
|
56347
|
-
kind:
|
|
56722
|
+
kind: graphql9.Kind.DIRECTIVE_DEFINITION,
|
|
56348
56723
|
name: {
|
|
56349
|
-
kind:
|
|
56724
|
+
kind: graphql9.Kind.NAME,
|
|
56350
56725
|
value: config2.listDeleteDirective(typeName)
|
|
56351
56726
|
},
|
|
56352
56727
|
locations: [
|
|
56353
56728
|
{
|
|
56354
|
-
kind:
|
|
56729
|
+
kind: graphql9.Kind.NAME,
|
|
56355
56730
|
value: "FIELD"
|
|
56356
56731
|
}
|
|
56357
56732
|
],
|
|
@@ -56359,8 +56734,8 @@ async function addListFragments(config2, documents) {
|
|
|
56359
56734
|
}))
|
|
56360
56735
|
)
|
|
56361
56736
|
};
|
|
56362
|
-
config2.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(
|
|
56363
|
-
config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(
|
|
56737
|
+
config2.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(graphql9.print).join("\n\n");
|
|
56738
|
+
config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql9.print).join("\n\n");
|
|
56364
56739
|
documents.push({
|
|
56365
56740
|
name: "generated::lists",
|
|
56366
56741
|
kind: "HoudiniFragment" /* Fragment */,
|
|
@@ -56445,11 +56820,11 @@ var nodeNotDefinedMessage = (config2) => `Looks like you are trying to use the $
|
|
|
56445
56820
|
For more information, visit this link: ${siteURL}/guides/pagination`;
|
|
56446
56821
|
|
|
56447
56822
|
// src/codegen/generators/artifacts/fieldKey.ts
|
|
56448
|
-
var
|
|
56823
|
+
var graphql10 = __toESM(require_graphql2(), 1);
|
|
56449
56824
|
function fieldKey(config2, field) {
|
|
56450
56825
|
const attributeName = field.alias?.value || field.name.value;
|
|
56451
|
-
const printed =
|
|
56452
|
-
const secondParse =
|
|
56826
|
+
const printed = graphql10.print(field);
|
|
56827
|
+
const secondParse = graphql10.parse(`{${printed}}`).definitions[0].selectionSet.selections[0];
|
|
56453
56828
|
const paginated = !!field.directives?.find(
|
|
56454
56829
|
(directive) => directive.name.value === config2.paginateDirective
|
|
56455
56830
|
);
|
|
@@ -56544,8 +56919,8 @@ function selection({
|
|
|
56544
56919
|
const typeConditionName = field.typeCondition.name.value;
|
|
56545
56920
|
const typeCondition = config2.schema.getType(typeConditionName);
|
|
56546
56921
|
const possibleTypes = [];
|
|
56547
|
-
if (!
|
|
56548
|
-
} else if (
|
|
56922
|
+
if (!graphql11.isAbstractType(typeCondition)) {
|
|
56923
|
+
} else if (graphql11.isAbstractType(parentType)) {
|
|
56549
56924
|
const possibleParentTypes = config2.schema.getPossibleTypes(parentType).map((type) => type.name);
|
|
56550
56925
|
for (const possible of config2.schema.getPossibleTypes(typeCondition)) {
|
|
56551
56926
|
if (possibleParentTypes.includes(possible.name)) {
|
|
@@ -56593,7 +56968,7 @@ function selection({
|
|
|
56593
56968
|
} else {
|
|
56594
56969
|
let typeRef = type.getFields()[field.name.value].type;
|
|
56595
56970
|
fieldType = getRootType(typeRef);
|
|
56596
|
-
nullable = !
|
|
56971
|
+
nullable = !graphql11.isNonNullType(typeRef);
|
|
56597
56972
|
}
|
|
56598
56973
|
const typeName = fieldType.toString();
|
|
56599
56974
|
const pathSoFar = path2.concat(attributeName);
|
|
@@ -56658,7 +57033,7 @@ function selection({
|
|
|
56658
57033
|
{}
|
|
56659
57034
|
);
|
|
56660
57035
|
}
|
|
56661
|
-
if (
|
|
57036
|
+
if (graphql11.isInterfaceType(fieldType) || graphql11.isUnionType(fieldType)) {
|
|
56662
57037
|
fieldObj.abstract = true;
|
|
56663
57038
|
}
|
|
56664
57039
|
object.fields = {
|
|
@@ -56715,7 +57090,7 @@ function artifactGenerator(stats) {
|
|
|
56715
57090
|
return async function(config2, docs) {
|
|
56716
57091
|
const filterTypes = {};
|
|
56717
57092
|
for (const doc of docs) {
|
|
56718
|
-
|
|
57093
|
+
graphql12.visit(doc.document, {
|
|
56719
57094
|
Directive(node, _, __, ___, ancestors) {
|
|
56720
57095
|
if (node.name.value !== config2.listDirective) {
|
|
56721
57096
|
return;
|
|
@@ -56774,7 +57149,7 @@ function artifactGenerator(stats) {
|
|
|
56774
57149
|
return;
|
|
56775
57150
|
}
|
|
56776
57151
|
const usedVariableNames = /* @__PURE__ */ new Set();
|
|
56777
|
-
let documentWithoutInternalDirectives =
|
|
57152
|
+
let documentWithoutInternalDirectives = graphql12.visit(document, {
|
|
56778
57153
|
Directive(node) {
|
|
56779
57154
|
if (config2.isInternalDirective(node)) {
|
|
56780
57155
|
return null;
|
|
@@ -56787,7 +57162,7 @@ function artifactGenerator(stats) {
|
|
|
56787
57162
|
}
|
|
56788
57163
|
}
|
|
56789
57164
|
});
|
|
56790
|
-
let documentWithoutExtraVariables =
|
|
57165
|
+
let documentWithoutExtraVariables = graphql12.visit(
|
|
56791
57166
|
documentWithoutInternalDirectives,
|
|
56792
57167
|
{
|
|
56793
57168
|
VariableDefinition(variableDefinitionNode) {
|
|
@@ -56798,13 +57173,13 @@ function artifactGenerator(stats) {
|
|
|
56798
57173
|
}
|
|
56799
57174
|
}
|
|
56800
57175
|
);
|
|
56801
|
-
let rawString =
|
|
57176
|
+
let rawString = graphql12.print(documentWithoutExtraVariables);
|
|
56802
57177
|
let docKind = doc.kind;
|
|
56803
57178
|
const operations = document.definitions.filter(
|
|
56804
|
-
({ kind }) => kind ===
|
|
57179
|
+
({ kind }) => kind === graphql12.Kind.OPERATION_DEFINITION
|
|
56805
57180
|
);
|
|
56806
57181
|
const fragments = document.definitions.filter(
|
|
56807
|
-
({ kind }) => kind ===
|
|
57182
|
+
({ kind }) => kind === graphql12.Kind.FRAGMENT_DEFINITION
|
|
56808
57183
|
);
|
|
56809
57184
|
let rootType = "";
|
|
56810
57185
|
let selectionSet;
|
|
@@ -56837,7 +57212,13 @@ function artifactGenerator(stats) {
|
|
|
56837
57212
|
rootType = matchingFragment.typeCondition.name.value;
|
|
56838
57213
|
selectionSet = matchingFragment.selectionSet;
|
|
56839
57214
|
}
|
|
56840
|
-
|
|
57215
|
+
let inputs = operations[0]?.variableDefinitions;
|
|
57216
|
+
let directive = fragments[0]?.directives?.find(
|
|
57217
|
+
(directive2) => directive2.name.value === config2.argumentsDirective
|
|
57218
|
+
);
|
|
57219
|
+
if (docKind === "HoudiniFragment" /* Fragment */ && directive) {
|
|
57220
|
+
inputs = fragmentArgumentsDefinitions(config2, doc.filename, fragments[0]);
|
|
57221
|
+
}
|
|
56841
57222
|
const mergedSelection = flattenSelections({
|
|
56842
57223
|
config: config2,
|
|
56843
57224
|
filepath: doc.filename,
|
|
@@ -56898,7 +57279,7 @@ function artifactGenerator(stats) {
|
|
|
56898
57279
|
}
|
|
56899
57280
|
if (docKind === "HoudiniQuery") {
|
|
56900
57281
|
const cacheDirective = operations[0].directives?.find(
|
|
56901
|
-
(
|
|
57282
|
+
(directive2) => directive2.name.value === config2.cacheDirective
|
|
56902
57283
|
);
|
|
56903
57284
|
if (cacheDirective) {
|
|
56904
57285
|
const args = cacheDirective.arguments?.reduce(
|
|
@@ -57114,19 +57495,19 @@ async function generatePluginRuntime(config2, plugin) {
|
|
|
57114
57495
|
);
|
|
57115
57496
|
}
|
|
57116
57497
|
|
|
57117
|
-
// src/codegen/generators/typescript/
|
|
57118
|
-
var
|
|
57498
|
+
// src/codegen/generators/typescript/documentTypes.ts
|
|
57499
|
+
var recast11 = __toESM(require_main2(), 1);
|
|
57119
57500
|
|
|
57120
57501
|
// src/codegen/generators/typescript/addReferencedInputTypes.ts
|
|
57121
|
-
var
|
|
57502
|
+
var graphql15 = __toESM(require_graphql2(), 1);
|
|
57122
57503
|
var recast9 = __toESM(require_main2(), 1);
|
|
57123
57504
|
|
|
57124
57505
|
// src/codegen/generators/typescript/typeReference.ts
|
|
57125
|
-
var
|
|
57506
|
+
var graphql14 = __toESM(require_graphql2(), 1);
|
|
57126
57507
|
var recast8 = __toESM(require_main2(), 1);
|
|
57127
57508
|
|
|
57128
57509
|
// src/codegen/generators/typescript/types.ts
|
|
57129
|
-
var
|
|
57510
|
+
var graphql13 = __toESM(require_graphql2(), 1);
|
|
57130
57511
|
var recast7 = __toESM(require_main2(), 1);
|
|
57131
57512
|
var AST7 = recast7.types.builders;
|
|
57132
57513
|
function readonlyProperty(prop, enable = true) {
|
|
@@ -57157,336 +57538,89 @@ function scalarPropertyValue(config2, missingScalars, target) {
|
|
|
57157
57538
|
return AST7.tsBooleanKeyword();
|
|
57158
57539
|
}
|
|
57159
57540
|
case "ID": {
|
|
57160
|
-
return AST7.tsStringKeyword();
|
|
57161
|
-
}
|
|
57162
|
-
default: {
|
|
57163
|
-
if (
|
|
57164
|
-
return scalarPropertyValue(
|
|
57165
|
-
config2,
|
|
57166
|
-
missingScalars,
|
|
57167
|
-
target.ofType
|
|
57168
|
-
);
|
|
57169
|
-
}
|
|
57170
|
-
if (config2.scalars?.[target.name]) {
|
|
57171
|
-
return AST7.tsTypeReference(AST7.identifier(config2.scalars?.[target.name].type));
|
|
57172
|
-
}
|
|
57173
|
-
missingScalars.add(target.name);
|
|
57174
|
-
return AST7.tsAnyKeyword();
|
|
57175
|
-
}
|
|
57176
|
-
}
|
|
57177
|
-
}
|
|
57178
|
-
|
|
57179
|
-
// src/codegen/generators/typescript/typeReference.ts
|
|
57180
|
-
var AST8 = recast8.types.builders;
|
|
57181
|
-
function tsTypeReference(config2, missingScalars, definition) {
|
|
57182
|
-
const { type, wrappers } = unwrapType(config2, definition.type);
|
|
57183
|
-
let result;
|
|
57184
|
-
if (graphql13.isScalarType(type)) {
|
|
57185
|
-
result = scalarPropertyValue(config2, missingScalars, type);
|
|
57186
|
-
} else {
|
|
57187
|
-
result = AST8.tsTypeReference(AST8.identifier(type.name));
|
|
57188
|
-
}
|
|
57189
|
-
for (const toWrap of wrappers) {
|
|
57190
|
-
if (toWrap === "NonNull" /* NonNull */) {
|
|
57191
|
-
continue;
|
|
57192
|
-
} else if (toWrap === "Nullable" /* Nullable */) {
|
|
57193
|
-
result = nullableField(result, true);
|
|
57194
|
-
} else if (toWrap === "List" /* List */) {
|
|
57195
|
-
result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
|
|
57196
|
-
}
|
|
57197
|
-
}
|
|
57198
|
-
return result;
|
|
57199
|
-
}
|
|
57200
|
-
|
|
57201
|
-
// src/codegen/generators/typescript/addReferencedInputTypes.ts
|
|
57202
|
-
var AST9 = recast9.types.builders;
|
|
57203
|
-
function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, rootType) {
|
|
57204
|
-
const { type } = unwrapType(config2, rootType);
|
|
57205
|
-
if (graphql14.isScalarType(type)) {
|
|
57206
|
-
return;
|
|
57207
|
-
}
|
|
57208
|
-
if (visitedTypes.has(type.name)) {
|
|
57209
|
-
return;
|
|
57210
|
-
}
|
|
57211
|
-
if (graphql14.isUnionType(type)) {
|
|
57212
|
-
throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
|
|
57213
|
-
}
|
|
57214
|
-
visitedTypes.add(type.name);
|
|
57215
|
-
if (graphql14.isEnumType(type)) {
|
|
57216
|
-
ensureImports({
|
|
57217
|
-
config: config2,
|
|
57218
|
-
body,
|
|
57219
|
-
import: [type.name],
|
|
57220
|
-
sourceModule: "$houdini/graphql/enums",
|
|
57221
|
-
importKind: "type"
|
|
57222
|
-
});
|
|
57223
|
-
return;
|
|
57224
|
-
}
|
|
57225
|
-
const members = [];
|
|
57226
|
-
for (const field of Object.values(type.getFields())) {
|
|
57227
|
-
addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, field.type);
|
|
57228
|
-
members.push(
|
|
57229
|
-
AST9.tsPropertySignature(
|
|
57230
|
-
AST9.identifier(field.name),
|
|
57231
|
-
AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
|
|
57232
|
-
graphql14.isNullableType(field.type)
|
|
57233
|
-
)
|
|
57234
|
-
);
|
|
57235
|
-
}
|
|
57236
|
-
body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
|
|
57237
|
-
}
|
|
57238
|
-
|
|
57239
|
-
// src/codegen/generators/typescript/imperativeCache.ts
|
|
57240
|
-
var graphql15 = __toESM(require_graphql2(), 1);
|
|
57241
|
-
var recast10 = __toESM(require_main2(), 1);
|
|
57242
|
-
var AST10 = recast10.types.builders;
|
|
57243
|
-
async function imperativeCacheTypef(config2, docs) {
|
|
57244
|
-
const target = path_exports.join(config2.runtimeDirectory, "generated.d.ts");
|
|
57245
|
-
const body = [];
|
|
57246
|
-
const declaration = AST10.tsTypeAliasDeclaration(
|
|
57247
|
-
AST10.identifier(CacheTypeDefName),
|
|
57248
|
-
AST10.tsTypeLiteral([
|
|
57249
|
-
AST10.tsPropertySignature(
|
|
57250
|
-
AST10.identifier("types"),
|
|
57251
|
-
AST10.tsTypeAnnotation(typeDefinitions(config2, body))
|
|
57252
|
-
),
|
|
57253
|
-
AST10.tsPropertySignature(
|
|
57254
|
-
AST10.identifier("lists"),
|
|
57255
|
-
AST10.tsTypeAnnotation(listDefinitions(config2, docs))
|
|
57256
|
-
)
|
|
57257
|
-
])
|
|
57258
|
-
);
|
|
57259
|
-
declaration.declare = true;
|
|
57260
|
-
const importRecord = AST10.importDeclaration(
|
|
57261
|
-
[AST10.importSpecifier(AST10.identifier("Record"))],
|
|
57262
|
-
AST10.stringLiteral("./public/record")
|
|
57263
|
-
);
|
|
57264
|
-
importRecord.importKind = "type";
|
|
57265
|
-
await fs_exports.writeFile(
|
|
57266
|
-
target,
|
|
57267
|
-
recast10.prettyPrint(
|
|
57268
|
-
AST10.program([importRecord, ...body, AST10.exportNamedDeclaration(declaration)])
|
|
57269
|
-
).code
|
|
57270
|
-
);
|
|
57271
|
-
}
|
|
57272
|
-
function typeDefinitions(config2, body) {
|
|
57273
|
-
const operationTypes = [config2.schema.getMutationType(), config2.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
|
|
57274
|
-
const visitedTypes = /* @__PURE__ */ new Set();
|
|
57275
|
-
const types14 = Object.values(config2.schema.getTypeMap()).filter(
|
|
57276
|
-
(type) => !graphql15.isAbstractType(type) && !graphql15.isScalarType(type) && !graphql15.isEnumType(type) && !graphql15.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
|
|
57277
|
-
);
|
|
57278
|
-
return AST10.tsTypeLiteral(
|
|
57279
|
-
types14.map((type) => {
|
|
57280
|
-
let typeName = type.name;
|
|
57281
|
-
if (config2.schema.getQueryType() && config2.schema.getQueryType()?.name === type.name) {
|
|
57282
|
-
typeName = "__ROOT__";
|
|
57283
|
-
}
|
|
57284
|
-
let idFields = AST10.tsNeverKeyword();
|
|
57285
|
-
const keys = keyFieldsForType(config2.configFile, type.name);
|
|
57286
|
-
if (graphql15.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
|
|
57287
|
-
idFields = AST10.tsTypeLiteral(
|
|
57288
|
-
keys.map((key) => {
|
|
57289
|
-
const fieldType = type.getFields()[key];
|
|
57290
|
-
const unwrapped = unwrapType(config2, fieldType.type);
|
|
57291
|
-
return AST10.tsPropertySignature(
|
|
57292
|
-
AST10.identifier(key),
|
|
57293
|
-
AST10.tsTypeAnnotation(
|
|
57294
|
-
scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
|
|
57295
|
-
)
|
|
57296
|
-
);
|
|
57297
|
-
})
|
|
57298
|
-
);
|
|
57299
|
-
} else if (typeName === "__ROOT__") {
|
|
57300
|
-
idFields = AST10.tsTypeLiteral([]);
|
|
57301
|
-
}
|
|
57302
|
-
let fields = AST10.tsTypeLiteral([]);
|
|
57303
|
-
if (graphql15.isObjectType(type)) {
|
|
57304
|
-
fields = AST10.tsTypeLiteral(
|
|
57305
|
-
Object.entries(type.getFields()).map(
|
|
57306
|
-
([key, fieldType]) => {
|
|
57307
|
-
const unwrapped = unwrapType(config2, fieldType.type);
|
|
57308
|
-
let typeOptions = AST10.tsUnionType([]);
|
|
57309
|
-
if (graphql15.isScalarType(unwrapped.type)) {
|
|
57310
|
-
typeOptions.types.push(
|
|
57311
|
-
scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
|
|
57312
|
-
);
|
|
57313
|
-
} else if (graphql15.isEnumType(unwrapped.type)) {
|
|
57314
|
-
typeOptions.types.push(
|
|
57315
|
-
AST10.tsTypeReference(AST10.identifier(unwrapped.type.name))
|
|
57316
|
-
);
|
|
57317
|
-
} else if (!graphql15.isAbstractType(unwrapped.type)) {
|
|
57318
|
-
typeOptions.types.push(record(unwrapped.type.name));
|
|
57319
|
-
} else {
|
|
57320
|
-
typeOptions.types.push(
|
|
57321
|
-
...config2.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
|
|
57322
|
-
);
|
|
57323
|
-
}
|
|
57324
|
-
for (const wrapper of unwrapped.wrappers) {
|
|
57325
|
-
if (wrapper === "Nullable" /* Nullable */) {
|
|
57326
|
-
typeOptions = AST10.tsParenthesizedType(
|
|
57327
|
-
AST10.tsUnionType([typeOptions, AST10.tsNullKeyword()])
|
|
57328
|
-
);
|
|
57329
|
-
} else if (wrapper === "List" /* List */) {
|
|
57330
|
-
typeOptions = AST10.tsArrayType(
|
|
57331
|
-
AST10.tsParenthesizedType(typeOptions)
|
|
57332
|
-
);
|
|
57333
|
-
}
|
|
57334
|
-
}
|
|
57335
|
-
if (typeOptions.type === "TSParenthesizedType") {
|
|
57336
|
-
typeOptions = typeOptions.typeAnnotation;
|
|
57337
|
-
}
|
|
57338
|
-
let args = AST10.tsNeverKeyword();
|
|
57339
|
-
if (fieldType.args?.length > 0) {
|
|
57340
|
-
args = AST10.tsTypeLiteral(
|
|
57341
|
-
fieldType.args.map((arg) => {
|
|
57342
|
-
addReferencedInputTypes(
|
|
57343
|
-
config2,
|
|
57344
|
-
"",
|
|
57345
|
-
body,
|
|
57346
|
-
visitedTypes,
|
|
57347
|
-
/* @__PURE__ */ new Set(),
|
|
57348
|
-
arg.type
|
|
57349
|
-
);
|
|
57350
|
-
const prop = AST10.tsPropertySignature(
|
|
57351
|
-
AST10.identifier(arg.name),
|
|
57352
|
-
AST10.tsTypeAnnotation(
|
|
57353
|
-
tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
|
|
57354
|
-
)
|
|
57355
|
-
);
|
|
57356
|
-
const unwrapped2 = unwrapType(config2, arg.type);
|
|
57357
|
-
prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
|
|
57358
|
-
return prop;
|
|
57359
|
-
})
|
|
57360
|
-
);
|
|
57361
|
-
}
|
|
57362
|
-
return AST10.tsPropertySignature(
|
|
57363
|
-
AST10.identifier(key),
|
|
57364
|
-
AST10.tsTypeAnnotation(
|
|
57365
|
-
AST10.tsTypeLiteral([
|
|
57366
|
-
AST10.tsPropertySignature(
|
|
57367
|
-
AST10.identifier("type"),
|
|
57368
|
-
AST10.tsTypeAnnotation(typeOptions)
|
|
57369
|
-
),
|
|
57370
|
-
AST10.tsPropertySignature(
|
|
57371
|
-
AST10.identifier("args"),
|
|
57372
|
-
AST10.tsTypeAnnotation(args)
|
|
57373
|
-
)
|
|
57374
|
-
])
|
|
57375
|
-
)
|
|
57376
|
-
);
|
|
57377
|
-
}
|
|
57378
|
-
)
|
|
57541
|
+
return AST7.tsStringKeyword();
|
|
57542
|
+
}
|
|
57543
|
+
default: {
|
|
57544
|
+
if (graphql13.isNonNullType(target) && "ofType" in target) {
|
|
57545
|
+
return scalarPropertyValue(
|
|
57546
|
+
config2,
|
|
57547
|
+
missingScalars,
|
|
57548
|
+
target.ofType
|
|
57379
57549
|
);
|
|
57380
57550
|
}
|
|
57381
|
-
|
|
57382
|
-
|
|
57383
|
-
AST10.tsTypeAnnotation(
|
|
57384
|
-
AST10.tsTypeLiteral([
|
|
57385
|
-
AST10.tsPropertySignature(
|
|
57386
|
-
AST10.identifier("idFields"),
|
|
57387
|
-
AST10.tsTypeAnnotation(idFields)
|
|
57388
|
-
),
|
|
57389
|
-
AST10.tsPropertySignature(
|
|
57390
|
-
AST10.identifier("fields"),
|
|
57391
|
-
AST10.tsTypeAnnotation(fields)
|
|
57392
|
-
)
|
|
57393
|
-
])
|
|
57394
|
-
)
|
|
57395
|
-
);
|
|
57396
|
-
})
|
|
57397
|
-
);
|
|
57398
|
-
}
|
|
57399
|
-
function listDefinitions(config2, docs) {
|
|
57400
|
-
const lists = [];
|
|
57401
|
-
const visitedLists = /* @__PURE__ */ new Set();
|
|
57402
|
-
for (const doc of docs) {
|
|
57403
|
-
graphql15.visit(doc.document, {
|
|
57404
|
-
Directive(node, key, parent, path2, ancestors) {
|
|
57405
|
-
if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
|
|
57406
|
-
return;
|
|
57407
|
-
}
|
|
57408
|
-
const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
|
|
57409
|
-
const nameValue = nameArg?.value?.value || "";
|
|
57410
|
-
if (!nameValue || visitedLists.has(nameValue)) {
|
|
57411
|
-
return;
|
|
57412
|
-
}
|
|
57413
|
-
visitedLists.add(nameValue);
|
|
57414
|
-
const parentType = parentTypeFromAncestors(
|
|
57415
|
-
config2.schema,
|
|
57416
|
-
doc.filename,
|
|
57417
|
-
ancestors.slice(0, -1)
|
|
57418
|
-
);
|
|
57419
|
-
const targetField = ancestors[ancestors.length - 1];
|
|
57420
|
-
const targetFieldDefinition = parentType.getFields()[targetField.name.value];
|
|
57421
|
-
const { type: listType } = unwrapType(config2, targetFieldDefinition.type);
|
|
57422
|
-
const possibleTypes = [];
|
|
57423
|
-
if (graphql15.isAbstractType(listType)) {
|
|
57424
|
-
possibleTypes.push(
|
|
57425
|
-
...config2.schema.getPossibleTypes(listType).map((possible) => possible.name)
|
|
57426
|
-
);
|
|
57427
|
-
} else {
|
|
57428
|
-
possibleTypes.push(listType.name);
|
|
57429
|
-
}
|
|
57430
|
-
lists.push(
|
|
57431
|
-
AST10.tsPropertySignature(
|
|
57432
|
-
AST10.identifier(nameValue),
|
|
57433
|
-
AST10.tsTypeAnnotation(
|
|
57434
|
-
AST10.tsTypeLiteral([
|
|
57435
|
-
AST10.tsPropertySignature(
|
|
57436
|
-
AST10.identifier("types"),
|
|
57437
|
-
AST10.tsTypeAnnotation(
|
|
57438
|
-
AST10.tsUnionType(
|
|
57439
|
-
possibleTypes.map(
|
|
57440
|
-
(possible) => AST10.tsLiteralType(AST10.stringLiteral(possible))
|
|
57441
|
-
)
|
|
57442
|
-
)
|
|
57443
|
-
)
|
|
57444
|
-
),
|
|
57445
|
-
AST10.tsPropertySignature(
|
|
57446
|
-
AST10.identifier("filters"),
|
|
57447
|
-
AST10.tsTypeAnnotation(
|
|
57448
|
-
targetFieldDefinition.args.length === 0 ? AST10.tsNeverKeyword() : AST10.tsTypeLiteral(
|
|
57449
|
-
targetFieldDefinition.args.map((arg) => {
|
|
57450
|
-
const argDef = AST10.tsPropertySignature(
|
|
57451
|
-
AST10.identifier(arg.name),
|
|
57452
|
-
AST10.tsTypeAnnotation(
|
|
57453
|
-
tsTypeReference(
|
|
57454
|
-
config2,
|
|
57455
|
-
/* @__PURE__ */ new Set(),
|
|
57456
|
-
arg
|
|
57457
|
-
)
|
|
57458
|
-
)
|
|
57459
|
-
);
|
|
57460
|
-
argDef.optional = true;
|
|
57461
|
-
return argDef;
|
|
57462
|
-
})
|
|
57463
|
-
)
|
|
57464
|
-
)
|
|
57465
|
-
)
|
|
57466
|
-
])
|
|
57467
|
-
)
|
|
57468
|
-
)
|
|
57469
|
-
);
|
|
57551
|
+
if (config2.scalars?.[target.name]) {
|
|
57552
|
+
return AST7.tsTypeReference(AST7.identifier(config2.scalars?.[target.name].type));
|
|
57470
57553
|
}
|
|
57471
|
-
|
|
57554
|
+
missingScalars.add(target.name);
|
|
57555
|
+
return AST7.tsAnyKeyword();
|
|
57556
|
+
}
|
|
57472
57557
|
}
|
|
57473
|
-
return AST10.tsTypeLiteral(lists);
|
|
57474
57558
|
}
|
|
57475
|
-
|
|
57476
|
-
|
|
57477
|
-
|
|
57478
|
-
|
|
57479
|
-
|
|
57480
|
-
|
|
57481
|
-
|
|
57482
|
-
|
|
57483
|
-
|
|
57559
|
+
|
|
57560
|
+
// src/codegen/generators/typescript/typeReference.ts
|
|
57561
|
+
var AST8 = recast8.types.builders;
|
|
57562
|
+
function tsTypeReference(config2, missingScalars, definition) {
|
|
57563
|
+
const { type, wrappers } = unwrapType(config2, definition.type);
|
|
57564
|
+
let result;
|
|
57565
|
+
if (graphql14.isScalarType(type)) {
|
|
57566
|
+
result = scalarPropertyValue(config2, missingScalars, type);
|
|
57567
|
+
} else {
|
|
57568
|
+
result = AST8.tsTypeReference(AST8.identifier(type.name));
|
|
57569
|
+
}
|
|
57570
|
+
for (const toWrap of wrappers) {
|
|
57571
|
+
if (toWrap === "NonNull" /* NonNull */) {
|
|
57572
|
+
continue;
|
|
57573
|
+
} else if (toWrap === "Nullable" /* Nullable */) {
|
|
57574
|
+
result = nullableField(result, true);
|
|
57575
|
+
} else if (toWrap === "List" /* List */) {
|
|
57576
|
+
result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
|
|
57577
|
+
}
|
|
57578
|
+
}
|
|
57579
|
+
return result;
|
|
57580
|
+
}
|
|
57581
|
+
|
|
57582
|
+
// src/codegen/generators/typescript/addReferencedInputTypes.ts
|
|
57583
|
+
var AST9 = recast9.types.builders;
|
|
57584
|
+
function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, rootType) {
|
|
57585
|
+
const { type } = unwrapType(config2, rootType);
|
|
57586
|
+
if (graphql15.isScalarType(type)) {
|
|
57587
|
+
return;
|
|
57588
|
+
}
|
|
57589
|
+
if (visitedTypes.has(type.name)) {
|
|
57590
|
+
return;
|
|
57591
|
+
}
|
|
57592
|
+
if (graphql15.isUnionType(type)) {
|
|
57593
|
+
throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
|
|
57594
|
+
}
|
|
57595
|
+
visitedTypes.add(type.name);
|
|
57596
|
+
if (graphql15.isEnumType(type)) {
|
|
57597
|
+
ensureImports({
|
|
57598
|
+
config: config2,
|
|
57599
|
+
body,
|
|
57600
|
+
import: [type.name],
|
|
57601
|
+
sourceModule: "$houdini/graphql/enums",
|
|
57602
|
+
importKind: "type"
|
|
57603
|
+
});
|
|
57604
|
+
return;
|
|
57605
|
+
}
|
|
57606
|
+
const members = [];
|
|
57607
|
+
for (const field of Object.values(type.getFields())) {
|
|
57608
|
+
addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, field.type);
|
|
57609
|
+
members.push(
|
|
57610
|
+
AST9.tsPropertySignature(
|
|
57611
|
+
AST9.identifier(field.name),
|
|
57612
|
+
AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
|
|
57613
|
+
graphql15.isNullableType(field.type)
|
|
57614
|
+
)
|
|
57615
|
+
);
|
|
57616
|
+
}
|
|
57617
|
+
body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
|
|
57484
57618
|
}
|
|
57485
57619
|
|
|
57486
57620
|
// src/codegen/generators/typescript/inlineType.ts
|
|
57487
57621
|
var graphql16 = __toESM(require_graphql2(), 1);
|
|
57488
|
-
var
|
|
57489
|
-
var
|
|
57622
|
+
var recast10 = __toESM(require_main2(), 1);
|
|
57623
|
+
var AST10 = recast10.types.builders;
|
|
57490
57624
|
var fragmentKey = "$fragments";
|
|
57491
57625
|
function inlineType({
|
|
57492
57626
|
config: config2,
|
|
@@ -57515,7 +57649,7 @@ function inlineType({
|
|
|
57515
57649
|
});
|
|
57516
57650
|
visitedTypes.add(type.name);
|
|
57517
57651
|
}
|
|
57518
|
-
result =
|
|
57652
|
+
result = AST10.tsTypeReference(AST10.identifier(type.name));
|
|
57519
57653
|
} else if (selections) {
|
|
57520
57654
|
const rootObj = type;
|
|
57521
57655
|
const inlineFragments = {};
|
|
@@ -57566,7 +57700,7 @@ function inlineType({
|
|
|
57566
57700
|
selectedFields.push(selection2);
|
|
57567
57701
|
}
|
|
57568
57702
|
}
|
|
57569
|
-
result =
|
|
57703
|
+
result = AST10.tsTypeLiteral([
|
|
57570
57704
|
...(selectedFields || []).filter(
|
|
57571
57705
|
(field) => field.kind === "Field"
|
|
57572
57706
|
).map((selection2) => {
|
|
@@ -57586,9 +57720,9 @@ function inlineType({
|
|
|
57586
57720
|
allOptional
|
|
57587
57721
|
});
|
|
57588
57722
|
const prop = readonlyProperty(
|
|
57589
|
-
|
|
57590
|
-
|
|
57591
|
-
|
|
57723
|
+
AST10.tsPropertySignature(
|
|
57724
|
+
AST10.identifier(attributeName),
|
|
57725
|
+
AST10.tsTypeAnnotation(attributeType)
|
|
57592
57726
|
),
|
|
57593
57727
|
allowReadonly
|
|
57594
57728
|
);
|
|
@@ -57602,15 +57736,15 @@ function inlineType({
|
|
|
57602
57736
|
if (includeFragments && fragmentSpreads && fragmentSpreads.length) {
|
|
57603
57737
|
result.members.push(
|
|
57604
57738
|
readonlyProperty(
|
|
57605
|
-
|
|
57606
|
-
|
|
57607
|
-
|
|
57608
|
-
|
|
57739
|
+
AST10.tsPropertySignature(
|
|
57740
|
+
AST10.identifier(fragmentKey),
|
|
57741
|
+
AST10.tsTypeAnnotation(
|
|
57742
|
+
AST10.tsTypeLiteral(
|
|
57609
57743
|
(fragmentSpreads || []).map(
|
|
57610
|
-
(fragmentSpread) =>
|
|
57611
|
-
|
|
57612
|
-
|
|
57613
|
-
|
|
57744
|
+
(fragmentSpread) => AST10.tsPropertySignature(
|
|
57745
|
+
AST10.identifier(fragmentSpread.name.value),
|
|
57746
|
+
AST10.tsTypeAnnotation(
|
|
57747
|
+
AST10.tsLiteralType(AST10.booleanLiteral(true))
|
|
57614
57748
|
)
|
|
57615
57749
|
)
|
|
57616
57750
|
)
|
|
@@ -57656,9 +57790,9 @@ function inlineType({
|
|
|
57656
57790
|
}
|
|
57657
57791
|
objectType.members.push(
|
|
57658
57792
|
readonlyProperty(
|
|
57659
|
-
|
|
57660
|
-
|
|
57661
|
-
|
|
57793
|
+
AST10.tsPropertySignature(
|
|
57794
|
+
AST10.identifier("__typename"),
|
|
57795
|
+
AST10.tsTypeAnnotation(AST10.tsLiteralType(AST10.stringLiteral(typeName)))
|
|
57662
57796
|
),
|
|
57663
57797
|
allowReadonly
|
|
57664
57798
|
)
|
|
@@ -57669,8 +57803,8 @@ function inlineType({
|
|
|
57669
57803
|
if (Object.keys(inlineFragmentSelections).length > 0) {
|
|
57670
57804
|
let selectionTypes = Object.entries(inlineFragmentSelections).map(
|
|
57671
57805
|
([typeName, { type: type2, tsType }]) => {
|
|
57672
|
-
return
|
|
57673
|
-
|
|
57806
|
+
return AST10.tsParenthesizedType(
|
|
57807
|
+
AST10.tsIntersectionType(
|
|
57674
57808
|
[tsType].flatMap((type3) => {
|
|
57675
57809
|
if (type3.type === "TSUnionType") {
|
|
57676
57810
|
return type3.types.filter(
|
|
@@ -57683,9 +57817,9 @@ function inlineType({
|
|
|
57683
57817
|
);
|
|
57684
57818
|
}
|
|
57685
57819
|
);
|
|
57686
|
-
result =
|
|
57820
|
+
result = AST10.tsIntersectionType([
|
|
57687
57821
|
result,
|
|
57688
|
-
|
|
57822
|
+
AST10.tsParenthesizedType(AST10.tsUnionType(selectionTypes))
|
|
57689
57823
|
]);
|
|
57690
57824
|
}
|
|
57691
57825
|
} else {
|
|
@@ -57697,7 +57831,7 @@ function inlineType({
|
|
|
57697
57831
|
} else if (toWrap === "NonNull" /* NonNull */) {
|
|
57698
57832
|
continue;
|
|
57699
57833
|
} else if (toWrap === "List" /* List */) {
|
|
57700
|
-
result =
|
|
57834
|
+
result = AST10.tsArrayType(AST10.tsParenthesizedType(result));
|
|
57701
57835
|
}
|
|
57702
57836
|
}
|
|
57703
57837
|
return result;
|
|
@@ -57741,9 +57875,9 @@ function selectionTypeInfo(schema, filepath, rootType, selection2) {
|
|
|
57741
57875
|
return { field, type: selectionType };
|
|
57742
57876
|
}
|
|
57743
57877
|
|
|
57744
|
-
// src/codegen/generators/typescript/
|
|
57745
|
-
var
|
|
57746
|
-
async function
|
|
57878
|
+
// src/codegen/generators/typescript/documentTypes.ts
|
|
57879
|
+
var AST11 = recast11.types.builders;
|
|
57880
|
+
async function generateDocumentTypes(config2, docs) {
|
|
57747
57881
|
const typePaths = [];
|
|
57748
57882
|
const fragmentDefinitions = {};
|
|
57749
57883
|
for (const document of docs) {
|
|
@@ -57760,7 +57894,7 @@ async function typescriptGenerator(config2, docs) {
|
|
|
57760
57894
|
return;
|
|
57761
57895
|
}
|
|
57762
57896
|
const typeDefPath = config2.artifactTypePath(originalDocument);
|
|
57763
|
-
const program =
|
|
57897
|
+
const program = AST11.program([]);
|
|
57764
57898
|
const visitedTypes = /* @__PURE__ */ new Set();
|
|
57765
57899
|
let definition = originalDocument.definitions.find(
|
|
57766
57900
|
(def) => (def.kind === "OperationDefinition" || def.kind === "FragmentDefinition") && def.name?.value === name2
|
|
@@ -57793,21 +57927,21 @@ async function typescriptGenerator(config2, docs) {
|
|
|
57793
57927
|
missingScalars
|
|
57794
57928
|
);
|
|
57795
57929
|
}
|
|
57796
|
-
await fs_exports.writeFile(typeDefPath,
|
|
57930
|
+
await fs_exports.writeFile(typeDefPath, recast11.print(program).code);
|
|
57797
57931
|
typePaths.push(typeDefPath);
|
|
57798
57932
|
})
|
|
57799
57933
|
);
|
|
57800
|
-
const typeIndex =
|
|
57934
|
+
const typeIndex = AST11.program(
|
|
57801
57935
|
typePaths.sort((a, b) => a.localeCompare(b)).map((typePath) => {
|
|
57802
|
-
return
|
|
57803
|
-
|
|
57936
|
+
return AST11.exportAllDeclaration(
|
|
57937
|
+
AST11.literal(
|
|
57804
57938
|
"./" + path_exports.relative(path_exports.resolve(config2.typeIndexPath, ".."), typePath).replace(/\.[^/.]+\.[^/.]+$/, "")
|
|
57805
57939
|
),
|
|
57806
57940
|
null
|
|
57807
57941
|
);
|
|
57808
57942
|
}).concat([
|
|
57809
|
-
|
|
57810
|
-
|
|
57943
|
+
AST11.exportAllDeclaration(AST11.literal("./runtime"), null),
|
|
57944
|
+
AST11.exportAllDeclaration(AST11.literal("./graphql"), null)
|
|
57811
57945
|
])
|
|
57812
57946
|
);
|
|
57813
57947
|
const export_default_as = ({ module, as }) => `
|
|
@@ -57816,7 +57950,7 @@ export { default as ${as} } from "${module}"
|
|
|
57816
57950
|
const export_star_from = ({ module }) => `
|
|
57817
57951
|
export * from "${module}"
|
|
57818
57952
|
`;
|
|
57819
|
-
let indexContent =
|
|
57953
|
+
let indexContent = recast11.print(typeIndex).code;
|
|
57820
57954
|
for (const plugin of config2.plugins) {
|
|
57821
57955
|
if (!plugin.index_file) {
|
|
57822
57956
|
continue;
|
|
@@ -57837,7 +57971,6 @@ export * from "${module}"
|
|
|
57837
57971
|
}
|
|
57838
57972
|
}
|
|
57839
57973
|
await fs_exports.writeFile(config2.typeIndexPath, indexContent);
|
|
57840
|
-
await imperativeCacheTypef(config2, docs);
|
|
57841
57974
|
if (missingScalars.size > 0) {
|
|
57842
57975
|
console.warn(`\u26A0\uFE0F Missing definitions for the following scalars: ${[...missingScalars].join(
|
|
57843
57976
|
", "
|
|
@@ -57879,23 +58012,23 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
|
|
|
57879
58012
|
const optimisticTypeName = `${definition.name.value}$optimistic`;
|
|
57880
58013
|
const hasInputs = definition.variableDefinitions && definition.variableDefinitions.length > 0;
|
|
57881
58014
|
body.push(
|
|
57882
|
-
|
|
57883
|
-
|
|
57884
|
-
|
|
57885
|
-
|
|
58015
|
+
AST11.exportNamedDeclaration(
|
|
58016
|
+
AST11.tsTypeAliasDeclaration(
|
|
58017
|
+
AST11.identifier(definition.name.value),
|
|
58018
|
+
AST11.tsTypeLiteral([
|
|
57886
58019
|
readonlyProperty(
|
|
57887
|
-
|
|
57888
|
-
|
|
57889
|
-
|
|
58020
|
+
AST11.tsPropertySignature(
|
|
58021
|
+
AST11.stringLiteral("input"),
|
|
58022
|
+
AST11.tsTypeAnnotation(AST11.tsTypeReference(AST11.identifier(inputTypeName)))
|
|
57890
58023
|
)
|
|
57891
58024
|
),
|
|
57892
58025
|
readonlyProperty(
|
|
57893
|
-
|
|
57894
|
-
|
|
57895
|
-
|
|
57896
|
-
definition.operation === "mutation" ?
|
|
57897
|
-
|
|
57898
|
-
|
|
58026
|
+
AST11.tsPropertySignature(
|
|
58027
|
+
AST11.stringLiteral("result"),
|
|
58028
|
+
AST11.tsTypeAnnotation(
|
|
58029
|
+
definition.operation === "mutation" ? AST11.tsTypeReference(AST11.identifier(shapeTypeName)) : AST11.tsUnionType([
|
|
58030
|
+
AST11.tsTypeReference(AST11.identifier(shapeTypeName)),
|
|
58031
|
+
AST11.tsUndefinedKeyword()
|
|
57899
58032
|
])
|
|
57900
58033
|
)
|
|
57901
58034
|
)
|
|
@@ -57903,9 +58036,9 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
|
|
|
57903
58036
|
])
|
|
57904
58037
|
)
|
|
57905
58038
|
),
|
|
57906
|
-
|
|
57907
|
-
|
|
57908
|
-
|
|
58039
|
+
AST11.exportNamedDeclaration(
|
|
58040
|
+
AST11.tsTypeAliasDeclaration(
|
|
58041
|
+
AST11.identifier(shapeTypeName),
|
|
57909
58042
|
inlineType({
|
|
57910
58043
|
config: config2,
|
|
57911
58044
|
filepath,
|
|
@@ -57933,15 +58066,15 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
|
|
|
57933
58066
|
);
|
|
57934
58067
|
}
|
|
57935
58068
|
body.push(
|
|
57936
|
-
|
|
57937
|
-
|
|
57938
|
-
|
|
57939
|
-
|
|
58069
|
+
AST11.exportNamedDeclaration(
|
|
58070
|
+
AST11.tsTypeAliasDeclaration(
|
|
58071
|
+
AST11.identifier(inputTypeName),
|
|
58072
|
+
AST11.tsTypeLiteral(
|
|
57940
58073
|
(definition.variableDefinitions || []).map(
|
|
57941
58074
|
(definition2) => {
|
|
57942
|
-
return
|
|
57943
|
-
|
|
57944
|
-
|
|
58075
|
+
return AST11.tsPropertySignature(
|
|
58076
|
+
AST11.identifier(definition2.variable.name.value),
|
|
58077
|
+
AST11.tsTypeAnnotation(
|
|
57945
58078
|
tsTypeReference(config2, missingScalars, definition2)
|
|
57946
58079
|
),
|
|
57947
58080
|
definition2.type.kind !== "NonNullType"
|
|
@@ -57954,16 +58087,16 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
|
|
|
57954
58087
|
);
|
|
57955
58088
|
} else {
|
|
57956
58089
|
body.push(
|
|
57957
|
-
|
|
57958
|
-
|
|
58090
|
+
AST11.exportNamedDeclaration(
|
|
58091
|
+
AST11.tsTypeAliasDeclaration(AST11.identifier(inputTypeName), AST11.tsNullKeyword())
|
|
57959
58092
|
)
|
|
57960
58093
|
);
|
|
57961
58094
|
}
|
|
57962
58095
|
if (definition.operation === "mutation") {
|
|
57963
58096
|
body.push(
|
|
57964
|
-
|
|
57965
|
-
|
|
57966
|
-
|
|
58097
|
+
AST11.exportNamedDeclaration(
|
|
58098
|
+
AST11.tsTypeAliasDeclaration(
|
|
58099
|
+
AST11.identifier(optimisticTypeName),
|
|
57967
58100
|
inlineType({
|
|
57968
58101
|
config: config2,
|
|
57969
58102
|
filepath,
|
|
@@ -57989,65 +58122,463 @@ async function generateFragmentTypeDefs(config2, filepath, body, selections, def
|
|
|
57989
58122
|
}
|
|
57990
58123
|
const propTypeName = definition.name.value;
|
|
57991
58124
|
const shapeTypeName = `${definition.name.value}$data`;
|
|
58125
|
+
const inputTypeName = `${definition.name.value}$input`;
|
|
57992
58126
|
const type = config2.schema.getType(definition.typeCondition.name.value);
|
|
57993
58127
|
if (!type) {
|
|
57994
58128
|
throw new Error("Should not get here");
|
|
57995
58129
|
}
|
|
58130
|
+
let extraExports = [];
|
|
58131
|
+
let directive = definition.directives?.find(
|
|
58132
|
+
(directive2) => directive2.name.value === config2.argumentsDirective
|
|
58133
|
+
);
|
|
58134
|
+
if (directive) {
|
|
58135
|
+
extraExports.push(
|
|
58136
|
+
AST11.exportNamedDeclaration(
|
|
58137
|
+
AST11.tsTypeAliasDeclaration(
|
|
58138
|
+
AST11.identifier(inputTypeName),
|
|
58139
|
+
AST11.tsTypeLiteral(
|
|
58140
|
+
(fragmentArgumentsDefinitions(config2, filepath, definition) || []).map(
|
|
58141
|
+
(definition2) => {
|
|
58142
|
+
return AST11.tsPropertySignature(
|
|
58143
|
+
AST11.identifier(definition2.variable.name.value),
|
|
58144
|
+
AST11.tsTypeAnnotation(
|
|
58145
|
+
tsTypeReference(config2, missingScalars, definition2)
|
|
58146
|
+
),
|
|
58147
|
+
definition2.type.kind !== "NonNullType"
|
|
58148
|
+
);
|
|
58149
|
+
}
|
|
58150
|
+
)
|
|
58151
|
+
)
|
|
58152
|
+
)
|
|
58153
|
+
)
|
|
58154
|
+
);
|
|
58155
|
+
}
|
|
57996
58156
|
body.push(
|
|
57997
|
-
|
|
57998
|
-
|
|
57999
|
-
|
|
58000
|
-
|
|
58157
|
+
...extraExports,
|
|
58158
|
+
AST11.exportNamedDeclaration(
|
|
58159
|
+
AST11.tsTypeAliasDeclaration(
|
|
58160
|
+
AST11.identifier(propTypeName),
|
|
58161
|
+
AST11.tsTypeLiteral([
|
|
58001
58162
|
readonlyProperty(
|
|
58002
|
-
|
|
58003
|
-
|
|
58004
|
-
|
|
58005
|
-
|
|
58163
|
+
AST11.tsPropertySignature(
|
|
58164
|
+
AST11.stringLiteral("shape"),
|
|
58165
|
+
AST11.tsTypeAnnotation(
|
|
58166
|
+
AST11.tsTypeReference(AST11.identifier(shapeTypeName))
|
|
58006
58167
|
),
|
|
58007
58168
|
true
|
|
58008
58169
|
)
|
|
58009
58170
|
),
|
|
58010
58171
|
readonlyProperty(
|
|
58011
|
-
|
|
58012
|
-
|
|
58172
|
+
AST11.tsPropertySignature(
|
|
58173
|
+
AST11.stringLiteral(fragmentKey),
|
|
58174
|
+
AST11.tsTypeAnnotation(
|
|
58175
|
+
AST11.tsTypeLiteral([
|
|
58176
|
+
AST11.tsPropertySignature(
|
|
58177
|
+
AST11.stringLiteral(propTypeName),
|
|
58178
|
+
AST11.tsTypeAnnotation(
|
|
58179
|
+
AST11.tsLiteralType(AST11.booleanLiteral(true))
|
|
58180
|
+
)
|
|
58181
|
+
)
|
|
58182
|
+
])
|
|
58183
|
+
)
|
|
58184
|
+
)
|
|
58185
|
+
)
|
|
58186
|
+
])
|
|
58187
|
+
)
|
|
58188
|
+
),
|
|
58189
|
+
AST11.exportNamedDeclaration(
|
|
58190
|
+
AST11.tsTypeAliasDeclaration(
|
|
58191
|
+
AST11.identifier(shapeTypeName),
|
|
58192
|
+
inlineType({
|
|
58193
|
+
config: config2,
|
|
58194
|
+
filepath,
|
|
58195
|
+
rootType: type,
|
|
58196
|
+
selections,
|
|
58197
|
+
root: true,
|
|
58198
|
+
allowReadonly: true,
|
|
58199
|
+
body,
|
|
58200
|
+
visitedTypes,
|
|
58201
|
+
missingScalars,
|
|
58202
|
+
includeFragments: true
|
|
58203
|
+
})
|
|
58204
|
+
)
|
|
58205
|
+
)
|
|
58206
|
+
);
|
|
58207
|
+
}
|
|
58208
|
+
}
|
|
58209
|
+
|
|
58210
|
+
// src/codegen/generators/typescript/imperativeTypeDef.ts
|
|
58211
|
+
var graphql17 = __toESM(require_graphql2(), 1);
|
|
58212
|
+
var recast12 = __toESM(require_main2(), 1);
|
|
58213
|
+
var AST12 = recast12.types.builders;
|
|
58214
|
+
async function imperativeCacheTypef(config2, docs) {
|
|
58215
|
+
const returnType = (doc) => config2.plugins.find((plugin) => plugin.graphql_tag_return)?.graphql_tag_return?.({
|
|
58216
|
+
config: config2,
|
|
58217
|
+
doc,
|
|
58218
|
+
ensure_import({ identifier, module }) {
|
|
58219
|
+
ensureImports({
|
|
58220
|
+
config: config2,
|
|
58221
|
+
body,
|
|
58222
|
+
sourceModule: module,
|
|
58223
|
+
import: [identifier]
|
|
58224
|
+
});
|
|
58225
|
+
}
|
|
58226
|
+
}) ?? "any";
|
|
58227
|
+
const target = path_exports.join(config2.runtimeDirectory, "generated.d.ts");
|
|
58228
|
+
const body = [];
|
|
58229
|
+
const declaration = AST12.tsTypeAliasDeclaration(
|
|
58230
|
+
AST12.identifier(CacheTypeDefName),
|
|
58231
|
+
AST12.tsTypeLiteral([
|
|
58232
|
+
AST12.tsPropertySignature(
|
|
58233
|
+
AST12.identifier("types"),
|
|
58234
|
+
AST12.tsTypeAnnotation(typeDefinitions(config2, body, docs, returnType))
|
|
58235
|
+
),
|
|
58236
|
+
AST12.tsPropertySignature(
|
|
58237
|
+
AST12.identifier("lists"),
|
|
58238
|
+
AST12.tsTypeAnnotation(listDefinitions(config2, docs))
|
|
58239
|
+
),
|
|
58240
|
+
AST12.tsPropertySignature(
|
|
58241
|
+
AST12.identifier("queries"),
|
|
58242
|
+
AST12.tsTypeAnnotation(queryDefinitions(config2, body, docs, returnType))
|
|
58243
|
+
)
|
|
58244
|
+
])
|
|
58245
|
+
);
|
|
58246
|
+
declaration.declare = true;
|
|
58247
|
+
const importRecord = AST12.importDeclaration(
|
|
58248
|
+
[AST12.importSpecifier(AST12.identifier("Record"))],
|
|
58249
|
+
AST12.stringLiteral("./public/record")
|
|
58250
|
+
);
|
|
58251
|
+
importRecord.importKind = "type";
|
|
58252
|
+
await fs_exports.writeFile(
|
|
58253
|
+
target,
|
|
58254
|
+
recast12.prettyPrint(
|
|
58255
|
+
AST12.program([importRecord, ...body, AST12.exportNamedDeclaration(declaration)])
|
|
58256
|
+
).code
|
|
58257
|
+
);
|
|
58258
|
+
}
|
|
58259
|
+
function typeDefinitions(config2, body, docs, returnType) {
|
|
58260
|
+
const operationTypes = [config2.schema.getMutationType(), config2.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
|
|
58261
|
+
const visitedTypes = /* @__PURE__ */ new Set();
|
|
58262
|
+
const types14 = Object.values(config2.schema.getTypeMap()).filter(
|
|
58263
|
+
(type) => !graphql17.isAbstractType(type) && !graphql17.isScalarType(type) && !graphql17.isEnumType(type) && !graphql17.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
|
|
58264
|
+
);
|
|
58265
|
+
const fragmentMap = fragmentListMap(
|
|
58266
|
+
config2,
|
|
58267
|
+
types14.map((type) => type.name),
|
|
58268
|
+
body,
|
|
58269
|
+
docs,
|
|
58270
|
+
returnType
|
|
58271
|
+
);
|
|
58272
|
+
return AST12.tsTypeLiteral(
|
|
58273
|
+
types14.map((type) => {
|
|
58274
|
+
let typeName = type.name;
|
|
58275
|
+
if (config2.schema.getQueryType() && config2.schema.getQueryType()?.name === type.name) {
|
|
58276
|
+
typeName = "__ROOT__";
|
|
58277
|
+
}
|
|
58278
|
+
let idFields = AST12.tsNeverKeyword();
|
|
58279
|
+
const keys = keyFieldsForType(config2.configFile, type.name);
|
|
58280
|
+
if (graphql17.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
|
|
58281
|
+
idFields = AST12.tsTypeLiteral(
|
|
58282
|
+
keys.map((key) => {
|
|
58283
|
+
const fieldType = type.getFields()[key];
|
|
58284
|
+
const unwrapped = unwrapType(config2, fieldType.type);
|
|
58285
|
+
return AST12.tsPropertySignature(
|
|
58286
|
+
AST12.identifier(key),
|
|
58287
|
+
AST12.tsTypeAnnotation(
|
|
58288
|
+
scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
|
|
58289
|
+
)
|
|
58290
|
+
);
|
|
58291
|
+
})
|
|
58292
|
+
);
|
|
58293
|
+
} else if (typeName === "__ROOT__") {
|
|
58294
|
+
idFields = AST12.tsTypeLiteral([]);
|
|
58295
|
+
}
|
|
58296
|
+
let fields = AST12.tsTypeLiteral([]);
|
|
58297
|
+
if (graphql17.isObjectType(type)) {
|
|
58298
|
+
fields = AST12.tsTypeLiteral(
|
|
58299
|
+
Object.entries(type.getFields()).map(
|
|
58300
|
+
([key, fieldType]) => {
|
|
58301
|
+
const unwrapped = unwrapType(config2, fieldType.type);
|
|
58302
|
+
let typeOptions = AST12.tsUnionType([]);
|
|
58303
|
+
if (graphql17.isScalarType(unwrapped.type)) {
|
|
58304
|
+
typeOptions.types.push(
|
|
58305
|
+
scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
|
|
58306
|
+
);
|
|
58307
|
+
} else if (graphql17.isEnumType(unwrapped.type)) {
|
|
58308
|
+
typeOptions.types.push(
|
|
58309
|
+
AST12.tsTypeReference(AST12.identifier(unwrapped.type.name))
|
|
58310
|
+
);
|
|
58311
|
+
} else if (!graphql17.isAbstractType(unwrapped.type)) {
|
|
58312
|
+
typeOptions.types.push(record(unwrapped.type.name));
|
|
58313
|
+
} else {
|
|
58314
|
+
typeOptions.types.push(
|
|
58315
|
+
...config2.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
|
|
58316
|
+
);
|
|
58317
|
+
}
|
|
58318
|
+
for (const wrapper of unwrapped.wrappers) {
|
|
58319
|
+
if (wrapper === "Nullable" /* Nullable */) {
|
|
58320
|
+
typeOptions = AST12.tsParenthesizedType(
|
|
58321
|
+
AST12.tsUnionType([typeOptions, AST12.tsNullKeyword()])
|
|
58322
|
+
);
|
|
58323
|
+
} else if (wrapper === "List" /* List */) {
|
|
58324
|
+
typeOptions = AST12.tsArrayType(
|
|
58325
|
+
AST12.tsParenthesizedType(typeOptions)
|
|
58326
|
+
);
|
|
58327
|
+
}
|
|
58328
|
+
}
|
|
58329
|
+
if (typeOptions.type === "TSParenthesizedType") {
|
|
58330
|
+
typeOptions = typeOptions.typeAnnotation;
|
|
58331
|
+
}
|
|
58332
|
+
let args = AST12.tsNeverKeyword();
|
|
58333
|
+
if (fieldType.args?.length > 0) {
|
|
58334
|
+
args = AST12.tsTypeLiteral(
|
|
58335
|
+
fieldType.args.map((arg) => {
|
|
58336
|
+
addReferencedInputTypes(
|
|
58337
|
+
config2,
|
|
58338
|
+
"",
|
|
58339
|
+
body,
|
|
58340
|
+
visitedTypes,
|
|
58341
|
+
/* @__PURE__ */ new Set(),
|
|
58342
|
+
arg.type
|
|
58343
|
+
);
|
|
58344
|
+
const prop = AST12.tsPropertySignature(
|
|
58345
|
+
AST12.identifier(arg.name),
|
|
58346
|
+
AST12.tsTypeAnnotation(
|
|
58347
|
+
tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
|
|
58348
|
+
)
|
|
58349
|
+
);
|
|
58350
|
+
const unwrapped2 = unwrapType(config2, arg.type);
|
|
58351
|
+
prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
|
|
58352
|
+
return prop;
|
|
58353
|
+
})
|
|
58354
|
+
);
|
|
58355
|
+
}
|
|
58356
|
+
return AST12.tsPropertySignature(
|
|
58357
|
+
AST12.identifier(key),
|
|
58013
58358
|
AST12.tsTypeAnnotation(
|
|
58014
58359
|
AST12.tsTypeLiteral([
|
|
58015
58360
|
AST12.tsPropertySignature(
|
|
58016
|
-
AST12.
|
|
58017
|
-
AST12.tsTypeAnnotation(
|
|
58018
|
-
|
|
58019
|
-
|
|
58361
|
+
AST12.identifier("type"),
|
|
58362
|
+
AST12.tsTypeAnnotation(typeOptions)
|
|
58363
|
+
),
|
|
58364
|
+
AST12.tsPropertySignature(
|
|
58365
|
+
AST12.identifier("args"),
|
|
58366
|
+
AST12.tsTypeAnnotation(args)
|
|
58020
58367
|
)
|
|
58021
58368
|
])
|
|
58022
58369
|
)
|
|
58023
|
-
)
|
|
58370
|
+
);
|
|
58371
|
+
}
|
|
58372
|
+
)
|
|
58373
|
+
);
|
|
58374
|
+
}
|
|
58375
|
+
return AST12.tsPropertySignature(
|
|
58376
|
+
AST12.identifier(typeName),
|
|
58377
|
+
AST12.tsTypeAnnotation(
|
|
58378
|
+
AST12.tsTypeLiteral([
|
|
58379
|
+
AST12.tsPropertySignature(
|
|
58380
|
+
AST12.identifier("idFields"),
|
|
58381
|
+
AST12.tsTypeAnnotation(idFields)
|
|
58382
|
+
),
|
|
58383
|
+
AST12.tsPropertySignature(
|
|
58384
|
+
AST12.identifier("fields"),
|
|
58385
|
+
AST12.tsTypeAnnotation(fields)
|
|
58386
|
+
),
|
|
58387
|
+
AST12.tsPropertySignature(
|
|
58388
|
+
AST12.identifier("fragments"),
|
|
58389
|
+
AST12.tsTypeAnnotation(fragmentMap[typeName] ?? AST12.tsTupleType([]))
|
|
58024
58390
|
)
|
|
58025
58391
|
])
|
|
58026
58392
|
)
|
|
58393
|
+
);
|
|
58394
|
+
})
|
|
58395
|
+
);
|
|
58396
|
+
}
|
|
58397
|
+
function listDefinitions(config2, docs) {
|
|
58398
|
+
const lists = [];
|
|
58399
|
+
const visitedLists = /* @__PURE__ */ new Set();
|
|
58400
|
+
for (const doc of docs) {
|
|
58401
|
+
graphql17.visit(doc.document, {
|
|
58402
|
+
Directive(node, key, parent, path2, ancestors) {
|
|
58403
|
+
if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
|
|
58404
|
+
return;
|
|
58405
|
+
}
|
|
58406
|
+
const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
|
|
58407
|
+
const nameValue = nameArg?.value?.value || "";
|
|
58408
|
+
if (!nameValue || visitedLists.has(nameValue)) {
|
|
58409
|
+
return;
|
|
58410
|
+
}
|
|
58411
|
+
visitedLists.add(nameValue);
|
|
58412
|
+
const parentType = parentTypeFromAncestors(
|
|
58413
|
+
config2.schema,
|
|
58414
|
+
doc.filename,
|
|
58415
|
+
ancestors.slice(0, -1)
|
|
58416
|
+
);
|
|
58417
|
+
const targetField = ancestors[ancestors.length - 1];
|
|
58418
|
+
const targetFieldDefinition = parentType.getFields()[targetField.name.value];
|
|
58419
|
+
const { type: listType } = unwrapType(config2, targetFieldDefinition.type);
|
|
58420
|
+
const possibleTypes = [];
|
|
58421
|
+
if (graphql17.isAbstractType(listType)) {
|
|
58422
|
+
possibleTypes.push(
|
|
58423
|
+
...config2.schema.getPossibleTypes(listType).map((possible) => possible.name)
|
|
58424
|
+
);
|
|
58425
|
+
} else {
|
|
58426
|
+
possibleTypes.push(listType.name);
|
|
58427
|
+
}
|
|
58428
|
+
lists.push(
|
|
58429
|
+
AST12.tsPropertySignature(
|
|
58430
|
+
AST12.identifier(nameValue),
|
|
58431
|
+
AST12.tsTypeAnnotation(
|
|
58432
|
+
AST12.tsTypeLiteral([
|
|
58433
|
+
AST12.tsPropertySignature(
|
|
58434
|
+
AST12.identifier("types"),
|
|
58435
|
+
AST12.tsTypeAnnotation(
|
|
58436
|
+
AST12.tsUnionType(
|
|
58437
|
+
possibleTypes.map(
|
|
58438
|
+
(possible) => AST12.tsLiteralType(AST12.stringLiteral(possible))
|
|
58439
|
+
)
|
|
58440
|
+
)
|
|
58441
|
+
)
|
|
58442
|
+
),
|
|
58443
|
+
AST12.tsPropertySignature(
|
|
58444
|
+
AST12.identifier("filters"),
|
|
58445
|
+
AST12.tsTypeAnnotation(
|
|
58446
|
+
targetFieldDefinition.args.length === 0 ? AST12.tsNeverKeyword() : AST12.tsTypeLiteral(
|
|
58447
|
+
targetFieldDefinition.args.map((arg) => {
|
|
58448
|
+
const argDef = AST12.tsPropertySignature(
|
|
58449
|
+
AST12.identifier(arg.name),
|
|
58450
|
+
AST12.tsTypeAnnotation(
|
|
58451
|
+
tsTypeReference(
|
|
58452
|
+
config2,
|
|
58453
|
+
/* @__PURE__ */ new Set(),
|
|
58454
|
+
arg
|
|
58455
|
+
)
|
|
58456
|
+
)
|
|
58457
|
+
);
|
|
58458
|
+
argDef.optional = true;
|
|
58459
|
+
return argDef;
|
|
58460
|
+
})
|
|
58461
|
+
)
|
|
58462
|
+
)
|
|
58463
|
+
)
|
|
58464
|
+
])
|
|
58465
|
+
)
|
|
58466
|
+
)
|
|
58467
|
+
);
|
|
58468
|
+
}
|
|
58469
|
+
});
|
|
58470
|
+
}
|
|
58471
|
+
return AST12.tsTypeLiteral(lists);
|
|
58472
|
+
}
|
|
58473
|
+
function queryDefinitions(config2, body, docs, returnType) {
|
|
58474
|
+
return AST12.tsTupleType(
|
|
58475
|
+
docs.reduce((prev, doc) => {
|
|
58476
|
+
if (doc.kind !== "HoudiniQuery" /* Query */ || !doc.generateStore) {
|
|
58477
|
+
return prev;
|
|
58478
|
+
}
|
|
58479
|
+
const definition = doc.document.definitions.find(
|
|
58480
|
+
(def) => def.kind === "OperationDefinition" && def.operation === "query"
|
|
58481
|
+
);
|
|
58482
|
+
if (!definition) {
|
|
58483
|
+
return prev;
|
|
58484
|
+
}
|
|
58485
|
+
const runtimeType = returnType(doc);
|
|
58486
|
+
const [shapeType, inputType] = ensureImports({
|
|
58487
|
+
config: config2,
|
|
58488
|
+
body,
|
|
58489
|
+
sourceModule: path_exports.relative(
|
|
58490
|
+
config2.runtimeDirectory,
|
|
58491
|
+
config2.artifactImportPath(doc.name)
|
|
58492
|
+
),
|
|
58493
|
+
import: [`${doc.name}$result`, `${doc.name}$input`]
|
|
58494
|
+
});
|
|
58495
|
+
return prev.concat(
|
|
58496
|
+
AST12.tsTupleType([
|
|
58497
|
+
AST12.tsTypeReference(AST12.identifier(runtimeType)),
|
|
58498
|
+
AST12.tsTypeReference(AST12.identifier(shapeType)),
|
|
58499
|
+
AST12.tsTypeReference(AST12.identifier(inputType))
|
|
58500
|
+
])
|
|
58501
|
+
);
|
|
58502
|
+
}, [])
|
|
58503
|
+
);
|
|
58504
|
+
}
|
|
58505
|
+
function fragmentListMap(config2, concreteTypes, body, docs, return_type) {
|
|
58506
|
+
return docs.reduce((prev, doc) => {
|
|
58507
|
+
if (doc.kind !== "HoudiniFragment" /* Fragment */) {
|
|
58508
|
+
return prev;
|
|
58509
|
+
}
|
|
58510
|
+
const definition = doc.document.definitions.find(
|
|
58511
|
+
(def) => def.kind === "FragmentDefinition" && def.name.value === doc.name
|
|
58512
|
+
);
|
|
58513
|
+
if (!definition || !concreteTypes.includes(definition.typeCondition.name.value)) {
|
|
58514
|
+
return prev;
|
|
58515
|
+
}
|
|
58516
|
+
const typeName = definition.typeCondition.name.value;
|
|
58517
|
+
const previousValue = prev[typeName]?.elementTypes ?? [];
|
|
58518
|
+
const tagResult = return_type(doc);
|
|
58519
|
+
const [shapeType] = ensureImports({
|
|
58520
|
+
config: config2,
|
|
58521
|
+
body,
|
|
58522
|
+
sourceModule: path_exports.relative(
|
|
58523
|
+
config2.runtimeDirectory,
|
|
58524
|
+
config2.artifactImportPath(doc.name)
|
|
58027
58525
|
),
|
|
58028
|
-
|
|
58029
|
-
|
|
58030
|
-
|
|
58031
|
-
|
|
58526
|
+
import: [`${definition.name.value}$data`]
|
|
58527
|
+
});
|
|
58528
|
+
let inputType = AST12.tsNeverKeyword();
|
|
58529
|
+
let directive = definition.directives?.find(
|
|
58530
|
+
(directive2) => directive2.name.value === config2.argumentsDirective
|
|
58531
|
+
);
|
|
58532
|
+
if (directive) {
|
|
58533
|
+
inputType = AST12.tsTypeReference(
|
|
58534
|
+
AST12.identifier(
|
|
58535
|
+
ensureImports({
|
|
58032
58536
|
config: config2,
|
|
58033
|
-
filepath,
|
|
58034
|
-
rootType: type,
|
|
58035
|
-
selections,
|
|
58036
|
-
root: true,
|
|
58037
|
-
allowReadonly: true,
|
|
58038
58537
|
body,
|
|
58039
|
-
|
|
58040
|
-
|
|
58041
|
-
|
|
58042
|
-
|
|
58538
|
+
sourceModule: path_exports.relative(
|
|
58539
|
+
config2.runtimeDirectory,
|
|
58540
|
+
config2.artifactImportPath(doc.name)
|
|
58541
|
+
),
|
|
58542
|
+
import: [`${definition.name.value}$input`]
|
|
58543
|
+
})[0]
|
|
58544
|
+
)
|
|
58545
|
+
);
|
|
58546
|
+
}
|
|
58547
|
+
return {
|
|
58548
|
+
...prev,
|
|
58549
|
+
[typeName]: AST12.tsTupleType(
|
|
58550
|
+
previousValue.concat(
|
|
58551
|
+
AST12.tsTupleType([
|
|
58552
|
+
AST12.tsTypeReference(AST12.identifier(tagResult)),
|
|
58553
|
+
AST12.tsTypeReference(AST12.identifier(shapeType)),
|
|
58554
|
+
inputType
|
|
58555
|
+
])
|
|
58043
58556
|
)
|
|
58044
58557
|
)
|
|
58045
|
-
|
|
58046
|
-
}
|
|
58558
|
+
};
|
|
58559
|
+
}, {});
|
|
58560
|
+
}
|
|
58561
|
+
var CacheTypeDefName = "CacheTypeDef";
|
|
58562
|
+
function record(name2) {
|
|
58563
|
+
return AST12.tsTypeReference(
|
|
58564
|
+
AST12.identifier("Record"),
|
|
58565
|
+
AST12.tsTypeParameterInstantiation([
|
|
58566
|
+
AST12.tsTypeReference(AST12.identifier(CacheTypeDefName)),
|
|
58567
|
+
AST12.tsLiteralType(AST12.stringLiteral(name2))
|
|
58568
|
+
])
|
|
58569
|
+
);
|
|
58570
|
+
}
|
|
58571
|
+
|
|
58572
|
+
// src/codegen/generators/typescript/index.ts
|
|
58573
|
+
async function typescriptGenerator(config2, docs) {
|
|
58574
|
+
await Promise.all([
|
|
58575
|
+
generateDocumentTypes(config2, docs),
|
|
58576
|
+
imperativeCacheTypef(config2, docs)
|
|
58577
|
+
]);
|
|
58047
58578
|
}
|
|
58048
58579
|
|
|
58049
58580
|
// src/codegen/generators/persistedQueries/index.ts
|
|
58050
|
-
var
|
|
58581
|
+
var graphql18 = __toESM(require_graphql2(), 1);
|
|
58051
58582
|
async function persistOutputGenerator(config2, docs) {
|
|
58052
58583
|
if (typeof config2.persistedQueryPath !== "string" || config2.persistedQueryPath.length === 0)
|
|
58053
58584
|
return;
|
|
@@ -58059,8 +58590,8 @@ async function persistOutputGenerator(config2, docs) {
|
|
|
58059
58590
|
if (!generateArtifact) {
|
|
58060
58591
|
return acc;
|
|
58061
58592
|
}
|
|
58062
|
-
let rawString =
|
|
58063
|
-
|
|
58593
|
+
let rawString = graphql18.print(
|
|
58594
|
+
graphql18.visit(document, {
|
|
58064
58595
|
Directive(node) {
|
|
58065
58596
|
if (config2.isInternalDirective(node)) {
|
|
58066
58597
|
return null;
|
|
@@ -58069,7 +58600,7 @@ async function persistOutputGenerator(config2, docs) {
|
|
|
58069
58600
|
})
|
|
58070
58601
|
);
|
|
58071
58602
|
const operations = document.definitions.filter(
|
|
58072
|
-
({ kind }) => kind ===
|
|
58603
|
+
({ kind }) => kind === graphql18.Kind.OPERATION_DEFINITION
|
|
58073
58604
|
);
|
|
58074
58605
|
if (operations.length > 0 && operations[0].kind === "OperationDefinition") {
|
|
58075
58606
|
acc[hashDocument(rawString)] = rawString;
|
|
@@ -58082,11 +58613,11 @@ async function persistOutputGenerator(config2, docs) {
|
|
|
58082
58613
|
}
|
|
58083
58614
|
|
|
58084
58615
|
// src/codegen/generators/definitions/enums.ts
|
|
58085
|
-
var
|
|
58616
|
+
var graphql19 = __toESM(require_graphql2(), 1);
|
|
58086
58617
|
var recast13 = __toESM(require_main2(), 1);
|
|
58087
58618
|
var AST13 = recast13.types.builders;
|
|
58088
58619
|
async function definitionsGenerator(config2) {
|
|
58089
|
-
const enums =
|
|
58620
|
+
const enums = graphql19.parse(graphql19.printSchema(config2.schema)).definitions.filter(
|
|
58090
58621
|
(definition) => definition.kind === "EnumTypeDefinition"
|
|
58091
58622
|
).filter((def) => !config2.isInternalEnum(def));
|
|
58092
58623
|
const runtimeDefinitions = recast13.print(
|
|
@@ -58176,91 +58707,8 @@ async function writeIndexFile2(config2, docs) {
|
|
|
58176
58707
|
await fs_exports.writeFile(path_exports.join(config2.rootDir, "index.js"), body);
|
|
58177
58708
|
}
|
|
58178
58709
|
|
|
58179
|
-
// src/codegen/transforms/composeQueries.ts
|
|
58180
|
-
var import_graphql = __toESM(require_graphql2(), 1);
|
|
58181
|
-
async function includeFragmentDefinitions(config2, documents) {
|
|
58182
|
-
const fragments = collectFragments(config2, documents);
|
|
58183
|
-
for (const [index, { name: name2, document, filename }] of documents.entries()) {
|
|
58184
|
-
const operation = document.definitions.find(
|
|
58185
|
-
({ kind }) => kind === import_graphql.Kind.OPERATION_DEFINITION
|
|
58186
|
-
);
|
|
58187
|
-
if (!operation) {
|
|
58188
|
-
continue;
|
|
58189
|
-
}
|
|
58190
|
-
const allFragments = flattenFragments(
|
|
58191
|
-
filename,
|
|
58192
|
-
{ requiredFragments: findRequiredFragments(operation.selectionSet) },
|
|
58193
|
-
fragments
|
|
58194
|
-
);
|
|
58195
|
-
documents[index].document = {
|
|
58196
|
-
...document,
|
|
58197
|
-
definitions: [
|
|
58198
|
-
operation,
|
|
58199
|
-
...allFragments.map((fragmentName) => fragments[fragmentName].definition)
|
|
58200
|
-
]
|
|
58201
|
-
};
|
|
58202
|
-
}
|
|
58203
|
-
}
|
|
58204
|
-
function collectFragments(config2, docs) {
|
|
58205
|
-
return docs.reduce((acc, doc) => {
|
|
58206
|
-
const definitions = doc.document.definitions.reduce(
|
|
58207
|
-
(prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
|
|
58208
|
-
...prev,
|
|
58209
|
-
[definition.name.value]: {
|
|
58210
|
-
definition,
|
|
58211
|
-
requiredFragments: findRequiredFragments(definition.selectionSet),
|
|
58212
|
-
document: doc
|
|
58213
|
-
}
|
|
58214
|
-
},
|
|
58215
|
-
{}
|
|
58216
|
-
);
|
|
58217
|
-
return {
|
|
58218
|
-
...acc,
|
|
58219
|
-
...definitions
|
|
58220
|
-
};
|
|
58221
|
-
}, {});
|
|
58222
|
-
}
|
|
58223
|
-
function findRequiredFragments(selectionSet) {
|
|
58224
|
-
if (selectionSet.selections.length === 0) {
|
|
58225
|
-
return [];
|
|
58226
|
-
}
|
|
58227
|
-
const referencedFragments = [];
|
|
58228
|
-
for (const selection2 of selectionSet.selections) {
|
|
58229
|
-
if (selection2.kind === import_graphql.Kind.FRAGMENT_SPREAD) {
|
|
58230
|
-
referencedFragments.push(selection2.name.value);
|
|
58231
|
-
} else if (selection2.selectionSet) {
|
|
58232
|
-
referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
|
|
58233
|
-
}
|
|
58234
|
-
}
|
|
58235
|
-
return referencedFragments;
|
|
58236
|
-
}
|
|
58237
|
-
function flattenFragments(filepath, operation, fragments) {
|
|
58238
|
-
const frags = /* @__PURE__ */ new Set();
|
|
58239
|
-
const remaining = [...operation.requiredFragments];
|
|
58240
|
-
while (remaining.length > 0) {
|
|
58241
|
-
const nextFragment = remaining.shift();
|
|
58242
|
-
if (!nextFragment) {
|
|
58243
|
-
continue;
|
|
58244
|
-
}
|
|
58245
|
-
if (!frags.has(nextFragment)) {
|
|
58246
|
-
frags.add(nextFragment);
|
|
58247
|
-
} else {
|
|
58248
|
-
continue;
|
|
58249
|
-
}
|
|
58250
|
-
const targetFragment = fragments[nextFragment];
|
|
58251
|
-
if (!targetFragment) {
|
|
58252
|
-
throw new HoudiniError({
|
|
58253
|
-
filepath,
|
|
58254
|
-
message: "compose: could not find definition for fragment " + nextFragment
|
|
58255
|
-
});
|
|
58256
|
-
}
|
|
58257
|
-
remaining.push(...targetFragment.requiredFragments);
|
|
58258
|
-
}
|
|
58259
|
-
return [...frags];
|
|
58260
|
-
}
|
|
58261
|
-
|
|
58262
58710
|
// src/codegen/transforms/schema.ts
|
|
58263
|
-
var
|
|
58711
|
+
var graphql20 = __toESM(require_graphql2(), 1);
|
|
58264
58712
|
async function graphqlExtensions(config2, documents) {
|
|
58265
58713
|
const internalSchema = `
|
|
58266
58714
|
enum CachePolicy {
|
|
@@ -58324,9 +58772,9 @@ directive @${config2.argumentsDirective} on FRAGMENT_DEFINITION
|
|
|
58324
58772
|
directive @${config2.cacheDirective}(${config2.cachePolicyArg}: CachePolicy, ${config2.cachePartialArg}: Boolean) on QUERY
|
|
58325
58773
|
|
|
58326
58774
|
"""
|
|
58327
|
-
@${config2.
|
|
58775
|
+
@${config2.loadDirective} is used to disable automatic fetch (no load, no auto fetch in component), you will have to do it manually.
|
|
58328
58776
|
"""
|
|
58329
|
-
directive @${config2.
|
|
58777
|
+
directive @${config2.loadDirective} on QUERY
|
|
58330
58778
|
|
|
58331
58779
|
"""
|
|
58332
58780
|
@${config2.maskEnableDirective} to enable masking on fragment (overwriting the global conf)
|
|
@@ -58338,19 +58786,19 @@ directive @${config2.maskEnableDirective} on FRAGMENT_SPREAD
|
|
|
58338
58786
|
"""
|
|
58339
58787
|
directive @${config2.maskDisableDirective} on FRAGMENT_SPREAD
|
|
58340
58788
|
`;
|
|
58341
|
-
let currentSchema =
|
|
58789
|
+
let currentSchema = graphql20.printSchema(config2.schema);
|
|
58342
58790
|
if (!currentSchema.includes(`directive @${config2.listDirective}`)) {
|
|
58343
58791
|
currentSchema += internalSchema;
|
|
58344
58792
|
}
|
|
58345
58793
|
config2.newSchema += internalSchema;
|
|
58346
|
-
config2.schema =
|
|
58794
|
+
config2.schema = graphql20.buildSchema(currentSchema);
|
|
58347
58795
|
}
|
|
58348
58796
|
|
|
58349
58797
|
// src/codegen/transforms/typename.ts
|
|
58350
|
-
var
|
|
58798
|
+
var graphql21 = __toESM(require_graphql2(), 1);
|
|
58351
58799
|
async function addTypename(config2, documents) {
|
|
58352
58800
|
for (const doc of documents) {
|
|
58353
|
-
doc.document =
|
|
58801
|
+
doc.document = graphql21.visit(doc.document, {
|
|
58354
58802
|
Field(node, key, parent, path2, ancestors) {
|
|
58355
58803
|
if (!node.selectionSet) {
|
|
58356
58804
|
return;
|
|
@@ -58362,7 +58810,7 @@ async function addTypename(config2, documents) {
|
|
|
58362
58810
|
);
|
|
58363
58811
|
const field = type.getFields()[node.name.value];
|
|
58364
58812
|
const fieldType = unwrapType(config2, field.type).type;
|
|
58365
|
-
if (
|
|
58813
|
+
if (graphql21.isInterfaceType(fieldType) || graphql21.isUnionType(fieldType)) {
|
|
58366
58814
|
return {
|
|
58367
58815
|
...node,
|
|
58368
58816
|
selectionSet: {
|
|
@@ -58370,9 +58818,9 @@ async function addTypename(config2, documents) {
|
|
|
58370
58818
|
selections: [
|
|
58371
58819
|
...node.selectionSet.selections,
|
|
58372
58820
|
{
|
|
58373
|
-
kind:
|
|
58821
|
+
kind: graphql21.Kind.FIELD,
|
|
58374
58822
|
name: {
|
|
58375
|
-
kind:
|
|
58823
|
+
kind: graphql21.Kind.NAME,
|
|
58376
58824
|
value: "__typename"
|
|
58377
58825
|
}
|
|
58378
58826
|
}
|
|
@@ -58386,10 +58834,10 @@ async function addTypename(config2, documents) {
|
|
|
58386
58834
|
}
|
|
58387
58835
|
|
|
58388
58836
|
// src/codegen/transforms/addID.ts
|
|
58389
|
-
var
|
|
58837
|
+
var graphql22 = __toESM(require_graphql2(), 1);
|
|
58390
58838
|
async function addID(config2, documents) {
|
|
58391
58839
|
for (const doc of documents) {
|
|
58392
|
-
doc.document =
|
|
58840
|
+
doc.document = graphql22.visit(doc.document, {
|
|
58393
58841
|
Field(node, key, parent, path2, ancestors) {
|
|
58394
58842
|
if (!node.selectionSet) {
|
|
58395
58843
|
return;
|
|
@@ -58402,7 +58850,7 @@ async function addID(config2, documents) {
|
|
|
58402
58850
|
const field = type.getFields()[node.name.value];
|
|
58403
58851
|
const fieldType = unwrapType(config2, field.type).type;
|
|
58404
58852
|
if (node.selectionSet?.selections.length > 0) {
|
|
58405
|
-
if (!
|
|
58853
|
+
if (!graphql22.isObjectType(fieldType) && !graphql22.isInterfaceType(fieldType)) {
|
|
58406
58854
|
return;
|
|
58407
58855
|
}
|
|
58408
58856
|
const keyFields = config2.keyFieldsForType(fieldType.name);
|
|
@@ -58417,9 +58865,9 @@ async function addID(config2, documents) {
|
|
|
58417
58865
|
continue;
|
|
58418
58866
|
}
|
|
58419
58867
|
selections.push({
|
|
58420
|
-
kind:
|
|
58868
|
+
kind: graphql22.Kind.FIELD,
|
|
58421
58869
|
name: {
|
|
58422
|
-
kind:
|
|
58870
|
+
kind: graphql22.Kind.NAME,
|
|
58423
58871
|
value: keyField
|
|
58424
58872
|
}
|
|
58425
58873
|
});
|
|
@@ -58437,266 +58885,6 @@ async function addID(config2, documents) {
|
|
|
58437
58885
|
}
|
|
58438
58886
|
}
|
|
58439
58887
|
|
|
58440
|
-
// src/codegen/transforms/fragmentVariables.ts
|
|
58441
|
-
var graphql22 = __toESM(require_graphql2(), 1);
|
|
58442
|
-
var GraphqlKinds2 = graphql22.Kind;
|
|
58443
|
-
async function fragmentVariables(config2, documents) {
|
|
58444
|
-
const fragments = collectFragments(config2, documents);
|
|
58445
|
-
const generatedFragments = {};
|
|
58446
|
-
const visitedFragments = /* @__PURE__ */ new Set();
|
|
58447
|
-
for (const doc2 of documents) {
|
|
58448
|
-
const operation = doc2.document.definitions.find(
|
|
58449
|
-
({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
|
|
58450
|
-
);
|
|
58451
|
-
if (!operation) {
|
|
58452
|
-
continue;
|
|
58453
|
-
}
|
|
58454
|
-
doc2.document = inlineFragmentArgs({
|
|
58455
|
-
config: config2,
|
|
58456
|
-
filepath: doc2.filename,
|
|
58457
|
-
fragmentDefinitions: fragments,
|
|
58458
|
-
document: doc2.document,
|
|
58459
|
-
generatedFragments,
|
|
58460
|
-
visitedFragments,
|
|
58461
|
-
scope: null
|
|
58462
|
-
});
|
|
58463
|
-
}
|
|
58464
|
-
const doc = {
|
|
58465
|
-
kind: graphql22.Kind.DOCUMENT,
|
|
58466
|
-
definitions: Object.values(generatedFragments)
|
|
58467
|
-
};
|
|
58468
|
-
documents.push({
|
|
58469
|
-
name: "generated::fragmentVariables",
|
|
58470
|
-
kind: "HoudiniFragment" /* Fragment */,
|
|
58471
|
-
document: doc,
|
|
58472
|
-
originalDocument: doc,
|
|
58473
|
-
generateStore: false,
|
|
58474
|
-
generateArtifact: false,
|
|
58475
|
-
filename: "generated::fragmentVariables",
|
|
58476
|
-
originalString: ""
|
|
58477
|
-
});
|
|
58478
|
-
}
|
|
58479
|
-
function inlineFragmentArgs({
|
|
58480
|
-
config: config2,
|
|
58481
|
-
filepath,
|
|
58482
|
-
fragmentDefinitions,
|
|
58483
|
-
document,
|
|
58484
|
-
generatedFragments,
|
|
58485
|
-
visitedFragments,
|
|
58486
|
-
scope,
|
|
58487
|
-
newName
|
|
58488
|
-
}) {
|
|
58489
|
-
if (!scope) {
|
|
58490
|
-
scope = operationScope(
|
|
58491
|
-
document.definitions.find(
|
|
58492
|
-
({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
|
|
58493
|
-
)
|
|
58494
|
-
);
|
|
58495
|
-
}
|
|
58496
|
-
const definitionArgs = fragmentArguments(
|
|
58497
|
-
config2,
|
|
58498
|
-
filepath,
|
|
58499
|
-
document
|
|
58500
|
-
).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
|
|
58501
|
-
const result = graphql22.visit(document, {
|
|
58502
|
-
FragmentSpread(node) {
|
|
58503
|
-
const { definition } = fragmentDefinitions[node.name.value];
|
|
58504
|
-
let { args, hash } = collectWithArguments(config2, filepath, node, scope);
|
|
58505
|
-
const newFragmentName = `${node.name.value}${hash}`;
|
|
58506
|
-
if (!visitedFragments.has(newFragmentName)) {
|
|
58507
|
-
visitedFragments.add(newFragmentName);
|
|
58508
|
-
const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
|
|
58509
|
-
if (args) {
|
|
58510
|
-
for (const [field, value] of Object.entries(defaultArguments || {})) {
|
|
58511
|
-
if (!args[field]) {
|
|
58512
|
-
args[field] = value;
|
|
58513
|
-
}
|
|
58514
|
-
}
|
|
58515
|
-
generatedFragments[newFragmentName] = inlineFragmentArgs({
|
|
58516
|
-
config: config2,
|
|
58517
|
-
filepath,
|
|
58518
|
-
fragmentDefinitions,
|
|
58519
|
-
document: fragmentDefinitions[node.name.value].definition,
|
|
58520
|
-
generatedFragments,
|
|
58521
|
-
visitedFragments,
|
|
58522
|
-
scope: args,
|
|
58523
|
-
newName: newFragmentName
|
|
58524
|
-
});
|
|
58525
|
-
} else {
|
|
58526
|
-
const doc = fragmentDefinitions[node.name.value].document;
|
|
58527
|
-
const definitionIndex = doc.document.definitions.findIndex(
|
|
58528
|
-
(definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
|
|
58529
|
-
);
|
|
58530
|
-
const localDefinitions = [...doc.document.definitions];
|
|
58531
|
-
localDefinitions.splice(definitionIndex, 1);
|
|
58532
|
-
localDefinitions.push(
|
|
58533
|
-
inlineFragmentArgs({
|
|
58534
|
-
config: config2,
|
|
58535
|
-
filepath,
|
|
58536
|
-
fragmentDefinitions,
|
|
58537
|
-
document: fragmentDefinitions[node.name.value].definition,
|
|
58538
|
-
generatedFragments,
|
|
58539
|
-
visitedFragments,
|
|
58540
|
-
scope: defaultArguments,
|
|
58541
|
-
newName: ""
|
|
58542
|
-
})
|
|
58543
|
-
);
|
|
58544
|
-
doc.document = {
|
|
58545
|
-
...doc.document,
|
|
58546
|
-
definitions: localDefinitions
|
|
58547
|
-
};
|
|
58548
|
-
}
|
|
58549
|
-
if (node.name.value !== newFragmentName) {
|
|
58550
|
-
return {
|
|
58551
|
-
...node,
|
|
58552
|
-
name: {
|
|
58553
|
-
kind: "Name",
|
|
58554
|
-
value: newFragmentName
|
|
58555
|
-
}
|
|
58556
|
-
};
|
|
58557
|
-
}
|
|
58558
|
-
}
|
|
58559
|
-
},
|
|
58560
|
-
Argument(node) {
|
|
58561
|
-
const value = node.value;
|
|
58562
|
-
if (value.kind !== "Variable") {
|
|
58563
|
-
return;
|
|
58564
|
-
}
|
|
58565
|
-
if (!scope) {
|
|
58566
|
-
throw new HoudiniError({
|
|
58567
|
-
filepath,
|
|
58568
|
-
message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
|
|
58569
|
-
});
|
|
58570
|
-
}
|
|
58571
|
-
const newValue = scope[value.name.value];
|
|
58572
|
-
if (newValue) {
|
|
58573
|
-
return {
|
|
58574
|
-
...node,
|
|
58575
|
-
value: newValue
|
|
58576
|
-
};
|
|
58577
|
-
}
|
|
58578
|
-
if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
|
|
58579
|
-
throw new HoudiniError({
|
|
58580
|
-
filepath,
|
|
58581
|
-
message: "Missing value for required arg: " + value.name.value
|
|
58582
|
-
});
|
|
58583
|
-
}
|
|
58584
|
-
return null;
|
|
58585
|
-
}
|
|
58586
|
-
});
|
|
58587
|
-
if (newName) {
|
|
58588
|
-
result.name = {
|
|
58589
|
-
kind: graphql22.Kind.NAME,
|
|
58590
|
-
value: newName
|
|
58591
|
-
};
|
|
58592
|
-
}
|
|
58593
|
-
return result;
|
|
58594
|
-
}
|
|
58595
|
-
function withArguments(config2, node) {
|
|
58596
|
-
const withDirectives = node.directives?.filter(
|
|
58597
|
-
(directive) => directive.name.value === config2.withDirective
|
|
58598
|
-
);
|
|
58599
|
-
if (!withDirectives || withDirectives.length === 0) {
|
|
58600
|
-
return [];
|
|
58601
|
-
}
|
|
58602
|
-
return withDirectives.flatMap((directive) => directive.arguments || []);
|
|
58603
|
-
}
|
|
58604
|
-
function fragmentArguments(config2, filepath, definition) {
|
|
58605
|
-
const directives = definition.directives?.filter(
|
|
58606
|
-
(directive) => directive.name.value === config2.argumentsDirective
|
|
58607
|
-
);
|
|
58608
|
-
if (!directives || directives.length === 0) {
|
|
58609
|
-
return [];
|
|
58610
|
-
}
|
|
58611
|
-
return directives.flatMap(
|
|
58612
|
-
(directive) => directive.arguments?.flatMap((arg) => {
|
|
58613
|
-
if (arg.value.kind !== "ObjectValue") {
|
|
58614
|
-
throw new HoudiniError({
|
|
58615
|
-
filepath,
|
|
58616
|
-
message: "values of @argument must be objects"
|
|
58617
|
-
});
|
|
58618
|
-
}
|
|
58619
|
-
const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
|
|
58620
|
-
if (!typeArg || typeArg.kind !== "StringValue") {
|
|
58621
|
-
return [];
|
|
58622
|
-
}
|
|
58623
|
-
let type = typeArg.value;
|
|
58624
|
-
let name2 = arg.name.value;
|
|
58625
|
-
let required = false;
|
|
58626
|
-
let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
|
|
58627
|
-
if (type[type.length - 1] === "!") {
|
|
58628
|
-
type = type.slice(0, -1);
|
|
58629
|
-
required = true;
|
|
58630
|
-
defaultValue = null;
|
|
58631
|
-
}
|
|
58632
|
-
return [
|
|
58633
|
-
{
|
|
58634
|
-
name: name2,
|
|
58635
|
-
type,
|
|
58636
|
-
required,
|
|
58637
|
-
defaultValue
|
|
58638
|
-
}
|
|
58639
|
-
];
|
|
58640
|
-
}) || []
|
|
58641
|
-
);
|
|
58642
|
-
}
|
|
58643
|
-
function collectDefaultArgumentValues(config2, filepath, definition) {
|
|
58644
|
-
let result = {};
|
|
58645
|
-
for (const { name: name2, required, defaultValue } of fragmentArguments(
|
|
58646
|
-
config2,
|
|
58647
|
-
filepath,
|
|
58648
|
-
definition
|
|
58649
|
-
)) {
|
|
58650
|
-
if (required || !defaultValue) {
|
|
58651
|
-
continue;
|
|
58652
|
-
}
|
|
58653
|
-
result[name2] = defaultValue;
|
|
58654
|
-
}
|
|
58655
|
-
return result;
|
|
58656
|
-
}
|
|
58657
|
-
function collectWithArguments(config2, filepath, node, scope = {}) {
|
|
58658
|
-
const withArgs = withArguments(config2, node);
|
|
58659
|
-
if (withArgs.length === 0) {
|
|
58660
|
-
return { args: null, hash: "" };
|
|
58661
|
-
}
|
|
58662
|
-
let args = {};
|
|
58663
|
-
for (const arg of withArgs) {
|
|
58664
|
-
let value = arg.value;
|
|
58665
|
-
if (value.kind === GraphqlKinds2.VARIABLE) {
|
|
58666
|
-
if (!scope || !scope[value.name.value]) {
|
|
58667
|
-
throw new HoudiniError({
|
|
58668
|
-
filepath,
|
|
58669
|
-
message: "Encountered undefined variable: " + value.name.value
|
|
58670
|
-
});
|
|
58671
|
-
}
|
|
58672
|
-
value = scope[value.name.value];
|
|
58673
|
-
}
|
|
58674
|
-
args[arg.name.value] = {
|
|
58675
|
-
...value,
|
|
58676
|
-
loc: void 0
|
|
58677
|
-
};
|
|
58678
|
-
}
|
|
58679
|
-
return {
|
|
58680
|
-
args,
|
|
58681
|
-
hash: "_" + murmurHash(JSON.stringify(args))
|
|
58682
|
-
};
|
|
58683
|
-
}
|
|
58684
|
-
function operationScope(operation) {
|
|
58685
|
-
return operation.variableDefinitions?.reduce(
|
|
58686
|
-
(scope, definition) => ({
|
|
58687
|
-
...scope,
|
|
58688
|
-
[definition.variable.name.value]: {
|
|
58689
|
-
kind: "Variable",
|
|
58690
|
-
name: {
|
|
58691
|
-
kind: "Name",
|
|
58692
|
-
value: definition.variable.name.value
|
|
58693
|
-
}
|
|
58694
|
-
}
|
|
58695
|
-
}),
|
|
58696
|
-
{}
|
|
58697
|
-
) || {};
|
|
58698
|
-
}
|
|
58699
|
-
|
|
58700
58888
|
// src/codegen/validators/typeCheck.ts
|
|
58701
58889
|
var graphql23 = __toESM(require_graphql2(), 1);
|
|
58702
58890
|
async function typeCheck(config2, docs) {
|
|
@@ -59876,7 +60064,6 @@ function testConfigFile({ plugins, ...config2 } = {}) {
|
|
|
59876
60064
|
}
|
|
59877
60065
|
}
|
|
59878
60066
|
},
|
|
59879
|
-
framework: "kit",
|
|
59880
60067
|
types: {
|
|
59881
60068
|
Ghost: {
|
|
59882
60069
|
keys: ["name", "aka"],
|