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
|
@@ -54617,7 +54617,7 @@ async function find_graphql(config2, parsedScript, walker) {
|
|
|
54617
54617
|
return;
|
|
54618
54618
|
}
|
|
54619
54619
|
const parsedTag = graphql2.parse(documentString);
|
|
54620
|
-
if (walker.where && !walker.where(parsedTag)) {
|
|
54620
|
+
if (walker.where && !walker.where(parsedTag, { node, parent })) {
|
|
54621
54621
|
return;
|
|
54622
54622
|
}
|
|
54623
54623
|
const definition = config2.extractDefinition(parsedTag);
|
|
@@ -54658,7 +54658,7 @@ async function find_graphql(config2, parsedScript, walker) {
|
|
|
54658
54658
|
}
|
|
54659
54659
|
|
|
54660
54660
|
// src/codegen/generators/artifacts/index.ts
|
|
54661
|
-
var
|
|
54661
|
+
var graphql12 = __toESM(require_graphql2(), 1);
|
|
54662
54662
|
var recast5 = __toESM(require_main2(), 1);
|
|
54663
54663
|
|
|
54664
54664
|
// src/codegen/utils/commonjs.ts
|
|
@@ -54916,159 +54916,534 @@ function murmurHash(str) {
|
|
|
54916
54916
|
return s;
|
|
54917
54917
|
}
|
|
54918
54918
|
|
|
54919
|
-
// src/codegen/
|
|
54920
|
-
async function writeIndexFile(config2, docs) {
|
|
54921
|
-
const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
|
|
54922
|
-
let body = config2.module === "esm" ? docsToGenerate.reduce(
|
|
54923
|
-
(content, doc) => content + `
|
|
54924
|
-
export { default as ${doc.name}} from './${doc.name}'`,
|
|
54925
|
-
""
|
|
54926
|
-
) : docsToGenerate.reduce(
|
|
54927
|
-
(content, doc) => content + `
|
|
54928
|
-
${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
|
|
54929
|
-
cjsIndexFilePreamble
|
|
54930
|
-
);
|
|
54931
|
-
await fs_exports.writeFile(path_exports.join(config2.artifactDirectory, "index.js"), body);
|
|
54932
|
-
}
|
|
54933
|
-
|
|
54934
|
-
// src/codegen/generators/artifacts/inputs.ts
|
|
54919
|
+
// src/codegen/transforms/fragmentVariables.ts
|
|
54935
54920
|
var graphql3 = __toESM(require_graphql2(), 1);
|
|
54936
|
-
var recast3 = __toESM(require_main2(), 1);
|
|
54937
|
-
var AST3 = recast3.types.builders;
|
|
54938
|
-
function inputObject(config2, inputs) {
|
|
54939
|
-
const visitedTypes = /* @__PURE__ */ new Set();
|
|
54940
|
-
const inputObj = {
|
|
54941
|
-
fields: inputs.reduce((fields, input) => {
|
|
54942
|
-
const { type } = unwrapType(config2, input.type);
|
|
54943
|
-
return {
|
|
54944
|
-
...fields,
|
|
54945
|
-
[input.variable.name.value]: type.name
|
|
54946
|
-
};
|
|
54947
|
-
}, {}),
|
|
54948
|
-
types: {}
|
|
54949
|
-
};
|
|
54950
|
-
for (const input of inputs) {
|
|
54951
|
-
walkInputs(config2, visitedTypes, inputObj, input.type);
|
|
54952
|
-
}
|
|
54953
|
-
return inputObj;
|
|
54954
|
-
}
|
|
54955
|
-
function walkInputs(config2, visitedTypes, inputObj, rootType) {
|
|
54956
|
-
const { type } = unwrapType(config2, rootType);
|
|
54957
|
-
if (visitedTypes.has(type.name)) {
|
|
54958
|
-
return;
|
|
54959
|
-
}
|
|
54960
|
-
if (graphql3.isEnumType(type) || graphql3.isScalarType(type)) {
|
|
54961
|
-
return;
|
|
54962
|
-
}
|
|
54963
|
-
if (graphql3.isUnionType(type)) {
|
|
54964
|
-
return;
|
|
54965
|
-
}
|
|
54966
|
-
visitedTypes.add(type.name);
|
|
54967
|
-
inputObj.types[type.name] = Object.values(type.getFields()).reduce(
|
|
54968
|
-
(typeFields, field) => {
|
|
54969
|
-
const { type: fieldType } = unwrapType(config2, field.type);
|
|
54970
|
-
walkInputs(config2, visitedTypes, inputObj, fieldType);
|
|
54971
|
-
return {
|
|
54972
|
-
...typeFields,
|
|
54973
|
-
[field.name]: fieldType.toString()
|
|
54974
|
-
};
|
|
54975
|
-
},
|
|
54976
|
-
{}
|
|
54977
|
-
);
|
|
54978
|
-
}
|
|
54979
54921
|
|
|
54980
|
-
// src/codegen/
|
|
54981
|
-
var
|
|
54982
|
-
|
|
54983
|
-
|
|
54984
|
-
|
|
54985
|
-
|
|
54986
|
-
|
|
54987
|
-
|
|
54988
|
-
|
|
54989
|
-
|
|
54922
|
+
// src/codegen/transforms/composeQueries.ts
|
|
54923
|
+
var import_graphql = __toESM(require_graphql2(), 1);
|
|
54924
|
+
async function includeFragmentDefinitions(config2, documents) {
|
|
54925
|
+
const fragments = collectFragments(config2, documents);
|
|
54926
|
+
for (const [index, { name: name2, document, filename }] of documents.entries()) {
|
|
54927
|
+
const operation = document.definitions.find(
|
|
54928
|
+
({ kind }) => kind === import_graphql.Kind.OPERATION_DEFINITION
|
|
54929
|
+
);
|
|
54930
|
+
if (!operation) {
|
|
54931
|
+
continue;
|
|
54932
|
+
}
|
|
54933
|
+
const allFragments = flattenFragments(
|
|
54934
|
+
filename,
|
|
54935
|
+
{ requiredFragments: findRequiredFragments(operation.selectionSet) },
|
|
54936
|
+
fragments
|
|
54937
|
+
);
|
|
54938
|
+
documents[index].document = {
|
|
54939
|
+
...document,
|
|
54940
|
+
definitions: [
|
|
54941
|
+
operation,
|
|
54942
|
+
...allFragments.map((fragmentName) => fragments[fragmentName].definition)
|
|
54943
|
+
]
|
|
54944
|
+
};
|
|
54990
54945
|
}
|
|
54991
|
-
|
|
54992
|
-
|
|
54993
|
-
|
|
54994
|
-
|
|
54995
|
-
)
|
|
54946
|
+
}
|
|
54947
|
+
function collectFragments(config2, docs) {
|
|
54948
|
+
return docs.reduce((acc, doc) => {
|
|
54949
|
+
const definitions = doc.document.definitions.reduce(
|
|
54950
|
+
(prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
|
|
54951
|
+
...prev,
|
|
54952
|
+
[definition.name.value]: {
|
|
54953
|
+
definition,
|
|
54954
|
+
requiredFragments: findRequiredFragments(definition.selectionSet),
|
|
54955
|
+
document: doc
|
|
54956
|
+
}
|
|
54957
|
+
},
|
|
54958
|
+
{}
|
|
54996
54959
|
);
|
|
54960
|
+
return {
|
|
54961
|
+
...acc,
|
|
54962
|
+
...definitions
|
|
54963
|
+
};
|
|
54964
|
+
}, {});
|
|
54965
|
+
}
|
|
54966
|
+
function findRequiredFragments(selectionSet) {
|
|
54967
|
+
if (selectionSet.selections.length === 0) {
|
|
54968
|
+
return [];
|
|
54997
54969
|
}
|
|
54998
|
-
|
|
54999
|
-
|
|
55000
|
-
|
|
55001
|
-
|
|
55002
|
-
|
|
55003
|
-
);
|
|
54970
|
+
const referencedFragments = [];
|
|
54971
|
+
for (const selection2 of selectionSet.selections) {
|
|
54972
|
+
if (selection2.kind === import_graphql.Kind.FRAGMENT_SPREAD) {
|
|
54973
|
+
referencedFragments.push(selection2.name.value);
|
|
54974
|
+
} else if (selection2.selectionSet) {
|
|
54975
|
+
referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
|
|
55004
54976
|
}
|
|
55005
|
-
return AST4.stringLiteral(value);
|
|
55006
54977
|
}
|
|
55007
|
-
return
|
|
54978
|
+
return referencedFragments;
|
|
55008
54979
|
}
|
|
55009
|
-
function
|
|
55010
|
-
|
|
55011
|
-
|
|
55012
|
-
|
|
55013
|
-
|
|
54980
|
+
function flattenFragments(filepath, operation, fragments) {
|
|
54981
|
+
const frags = /* @__PURE__ */ new Set();
|
|
54982
|
+
const remaining = [...operation.requiredFragments];
|
|
54983
|
+
while (remaining.length > 0) {
|
|
54984
|
+
const nextFragment = remaining.shift();
|
|
54985
|
+
if (!nextFragment) {
|
|
54986
|
+
continue;
|
|
55014
54987
|
}
|
|
55015
|
-
|
|
55016
|
-
|
|
55017
|
-
|
|
55018
|
-
|
|
55019
|
-
|
|
55020
|
-
|
|
55021
|
-
|
|
55022
|
-
|
|
55023
|
-
|
|
55024
|
-
|
|
55025
|
-
}
|
|
55026
|
-
fields[key].push(value);
|
|
54988
|
+
if (!frags.has(nextFragment)) {
|
|
54989
|
+
frags.add(nextFragment);
|
|
54990
|
+
} else {
|
|
54991
|
+
continue;
|
|
54992
|
+
}
|
|
54993
|
+
const targetFragment = fragments[nextFragment];
|
|
54994
|
+
if (!targetFragment) {
|
|
54995
|
+
throw new HoudiniError({
|
|
54996
|
+
filepath,
|
|
54997
|
+
message: "compose: could not find definition for fragment " + nextFragment
|
|
54998
|
+
});
|
|
55027
54999
|
}
|
|
55000
|
+
remaining.push(...targetFragment.requiredFragments);
|
|
55028
55001
|
}
|
|
55029
|
-
return
|
|
55030
|
-
Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
|
|
55031
|
-
);
|
|
55002
|
+
return [...frags];
|
|
55032
55003
|
}
|
|
55033
|
-
|
|
55034
|
-
|
|
55035
|
-
|
|
55036
|
-
|
|
55037
|
-
|
|
55038
|
-
|
|
55039
|
-
|
|
55040
|
-
|
|
55041
|
-
|
|
55042
|
-
|
|
55043
|
-
|
|
55044
|
-
|
|
55045
|
-
|
|
55046
|
-
|
|
55047
|
-
|
|
55048
|
-
|
|
55049
|
-
|
|
55050
|
-
|
|
55004
|
+
|
|
55005
|
+
// src/codegen/transforms/fragmentVariables.ts
|
|
55006
|
+
var GraphqlKinds2 = graphql3.Kind;
|
|
55007
|
+
async function fragmentVariables(config2, documents) {
|
|
55008
|
+
const fragments = collectFragments(config2, documents);
|
|
55009
|
+
const generatedFragments = {};
|
|
55010
|
+
const visitedFragments = /* @__PURE__ */ new Set();
|
|
55011
|
+
for (const doc2 of documents) {
|
|
55012
|
+
const operation = doc2.document.definitions.find(
|
|
55013
|
+
({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
|
|
55014
|
+
);
|
|
55015
|
+
if (!operation) {
|
|
55016
|
+
continue;
|
|
55017
|
+
}
|
|
55018
|
+
doc2.document = inlineFragmentArgs({
|
|
55019
|
+
config: config2,
|
|
55020
|
+
filepath: doc2.filename,
|
|
55021
|
+
fragmentDefinitions: fragments,
|
|
55022
|
+
document: doc2.document,
|
|
55023
|
+
generatedFragments,
|
|
55024
|
+
visitedFragments,
|
|
55025
|
+
scope: null
|
|
55026
|
+
});
|
|
55051
55027
|
}
|
|
55052
|
-
|
|
55028
|
+
const doc = {
|
|
55029
|
+
kind: graphql3.Kind.DOCUMENT,
|
|
55030
|
+
definitions: Object.values(generatedFragments)
|
|
55031
|
+
};
|
|
55032
|
+
documents.push({
|
|
55033
|
+
name: "generated::fragmentVariables",
|
|
55034
|
+
kind: "HoudiniFragment" /* Fragment */,
|
|
55035
|
+
document: doc,
|
|
55036
|
+
originalDocument: doc,
|
|
55037
|
+
generateStore: false,
|
|
55038
|
+
generateArtifact: false,
|
|
55039
|
+
filename: "generated::fragmentVariables",
|
|
55040
|
+
originalString: ""
|
|
55041
|
+
});
|
|
55053
55042
|
}
|
|
55054
|
-
|
|
55055
|
-
|
|
55056
|
-
|
|
55057
|
-
|
|
55058
|
-
|
|
55043
|
+
function inlineFragmentArgs({
|
|
55044
|
+
config: config2,
|
|
55045
|
+
filepath,
|
|
55046
|
+
fragmentDefinitions,
|
|
55047
|
+
document,
|
|
55048
|
+
generatedFragments,
|
|
55049
|
+
visitedFragments,
|
|
55050
|
+
scope,
|
|
55051
|
+
newName
|
|
55052
|
+
}) {
|
|
55053
|
+
if (!scope) {
|
|
55054
|
+
scope = operationScope(
|
|
55055
|
+
document.definitions.find(
|
|
55056
|
+
({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
|
|
55057
|
+
)
|
|
55058
|
+
);
|
|
55059
55059
|
}
|
|
55060
|
-
const
|
|
55061
|
-
|
|
55062
|
-
|
|
55063
|
-
|
|
55064
|
-
|
|
55065
|
-
|
|
55066
|
-
|
|
55067
|
-
|
|
55068
|
-
|
|
55069
|
-
}
|
|
55070
|
-
|
|
55071
|
-
|
|
55060
|
+
const definitionArgs = fragmentArguments(
|
|
55061
|
+
config2,
|
|
55062
|
+
filepath,
|
|
55063
|
+
document
|
|
55064
|
+
).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
|
|
55065
|
+
const result = graphql3.visit(document, {
|
|
55066
|
+
FragmentSpread(node) {
|
|
55067
|
+
const { definition } = fragmentDefinitions[node.name.value];
|
|
55068
|
+
let { args, hash } = collectWithArguments(config2, filepath, node, scope);
|
|
55069
|
+
const newFragmentName = `${node.name.value}${hash}`;
|
|
55070
|
+
if (!visitedFragments.has(newFragmentName)) {
|
|
55071
|
+
visitedFragments.add(newFragmentName);
|
|
55072
|
+
const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
|
|
55073
|
+
if (args) {
|
|
55074
|
+
for (const [field, value] of Object.entries(defaultArguments || {})) {
|
|
55075
|
+
if (!args[field]) {
|
|
55076
|
+
args[field] = value;
|
|
55077
|
+
}
|
|
55078
|
+
}
|
|
55079
|
+
generatedFragments[newFragmentName] = inlineFragmentArgs({
|
|
55080
|
+
config: config2,
|
|
55081
|
+
filepath,
|
|
55082
|
+
fragmentDefinitions,
|
|
55083
|
+
document: fragmentDefinitions[node.name.value].definition,
|
|
55084
|
+
generatedFragments,
|
|
55085
|
+
visitedFragments,
|
|
55086
|
+
scope: args,
|
|
55087
|
+
newName: newFragmentName
|
|
55088
|
+
});
|
|
55089
|
+
} else {
|
|
55090
|
+
const doc = fragmentDefinitions[node.name.value].document;
|
|
55091
|
+
const definitionIndex = doc.document.definitions.findIndex(
|
|
55092
|
+
(definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
|
|
55093
|
+
);
|
|
55094
|
+
const localDefinitions = [...doc.document.definitions];
|
|
55095
|
+
localDefinitions.splice(definitionIndex, 1);
|
|
55096
|
+
localDefinitions.push(
|
|
55097
|
+
inlineFragmentArgs({
|
|
55098
|
+
config: config2,
|
|
55099
|
+
filepath,
|
|
55100
|
+
fragmentDefinitions,
|
|
55101
|
+
document: fragmentDefinitions[node.name.value].definition,
|
|
55102
|
+
generatedFragments,
|
|
55103
|
+
visitedFragments,
|
|
55104
|
+
scope: defaultArguments,
|
|
55105
|
+
newName: ""
|
|
55106
|
+
})
|
|
55107
|
+
);
|
|
55108
|
+
doc.document = {
|
|
55109
|
+
...doc.document,
|
|
55110
|
+
definitions: localDefinitions
|
|
55111
|
+
};
|
|
55112
|
+
}
|
|
55113
|
+
if (node.name.value !== newFragmentName) {
|
|
55114
|
+
return {
|
|
55115
|
+
...node,
|
|
55116
|
+
name: {
|
|
55117
|
+
kind: "Name",
|
|
55118
|
+
value: newFragmentName
|
|
55119
|
+
}
|
|
55120
|
+
};
|
|
55121
|
+
}
|
|
55122
|
+
}
|
|
55123
|
+
},
|
|
55124
|
+
Argument(node) {
|
|
55125
|
+
const value = node.value;
|
|
55126
|
+
if (value.kind !== "Variable") {
|
|
55127
|
+
return;
|
|
55128
|
+
}
|
|
55129
|
+
if (!scope) {
|
|
55130
|
+
throw new HoudiniError({
|
|
55131
|
+
filepath,
|
|
55132
|
+
message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
|
|
55133
|
+
});
|
|
55134
|
+
}
|
|
55135
|
+
const newValue = scope[value.name.value];
|
|
55136
|
+
if (newValue) {
|
|
55137
|
+
return {
|
|
55138
|
+
...node,
|
|
55139
|
+
value: newValue
|
|
55140
|
+
};
|
|
55141
|
+
}
|
|
55142
|
+
if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
|
|
55143
|
+
throw new HoudiniError({
|
|
55144
|
+
filepath,
|
|
55145
|
+
message: "Missing value for required arg: " + value.name.value
|
|
55146
|
+
});
|
|
55147
|
+
}
|
|
55148
|
+
return null;
|
|
55149
|
+
}
|
|
55150
|
+
});
|
|
55151
|
+
if (newName) {
|
|
55152
|
+
result.name = {
|
|
55153
|
+
kind: graphql3.Kind.NAME,
|
|
55154
|
+
value: newName
|
|
55155
|
+
};
|
|
55156
|
+
}
|
|
55157
|
+
return result;
|
|
55158
|
+
}
|
|
55159
|
+
function withArguments(config2, node) {
|
|
55160
|
+
const withDirectives = node.directives?.filter(
|
|
55161
|
+
(directive) => directive.name.value === config2.withDirective
|
|
55162
|
+
);
|
|
55163
|
+
if (!withDirectives || withDirectives.length === 0) {
|
|
55164
|
+
return [];
|
|
55165
|
+
}
|
|
55166
|
+
return withDirectives.flatMap((directive) => directive.arguments || []);
|
|
55167
|
+
}
|
|
55168
|
+
function fragmentArguments(config2, filepath, definition) {
|
|
55169
|
+
const directives = definition.directives?.filter(
|
|
55170
|
+
(directive) => directive.name.value === config2.argumentsDirective
|
|
55171
|
+
);
|
|
55172
|
+
if (!directives || directives.length === 0) {
|
|
55173
|
+
return [];
|
|
55174
|
+
}
|
|
55175
|
+
return directives.flatMap(
|
|
55176
|
+
(directive) => directive.arguments?.flatMap((arg) => {
|
|
55177
|
+
if (arg.value.kind !== "ObjectValue") {
|
|
55178
|
+
throw new HoudiniError({
|
|
55179
|
+
filepath,
|
|
55180
|
+
message: "values of @argument must be objects"
|
|
55181
|
+
});
|
|
55182
|
+
}
|
|
55183
|
+
const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
|
|
55184
|
+
if (!typeArg || typeArg.kind !== "StringValue") {
|
|
55185
|
+
return [];
|
|
55186
|
+
}
|
|
55187
|
+
let type = typeArg.value;
|
|
55188
|
+
let name2 = arg.name.value;
|
|
55189
|
+
let required = false;
|
|
55190
|
+
let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
|
|
55191
|
+
if (type[type.length - 1] === "!") {
|
|
55192
|
+
type = type.slice(0, -1);
|
|
55193
|
+
required = true;
|
|
55194
|
+
defaultValue = null;
|
|
55195
|
+
}
|
|
55196
|
+
return [
|
|
55197
|
+
{
|
|
55198
|
+
name: name2,
|
|
55199
|
+
type,
|
|
55200
|
+
required,
|
|
55201
|
+
defaultValue
|
|
55202
|
+
}
|
|
55203
|
+
];
|
|
55204
|
+
}) || []
|
|
55205
|
+
);
|
|
55206
|
+
}
|
|
55207
|
+
function collectDefaultArgumentValues(config2, filepath, definition) {
|
|
55208
|
+
let result = {};
|
|
55209
|
+
for (const { name: name2, required, defaultValue } of fragmentArguments(
|
|
55210
|
+
config2,
|
|
55211
|
+
filepath,
|
|
55212
|
+
definition
|
|
55213
|
+
)) {
|
|
55214
|
+
if (required || !defaultValue) {
|
|
55215
|
+
continue;
|
|
55216
|
+
}
|
|
55217
|
+
result[name2] = defaultValue;
|
|
55218
|
+
}
|
|
55219
|
+
return result;
|
|
55220
|
+
}
|
|
55221
|
+
function collectWithArguments(config2, filepath, node, scope = {}) {
|
|
55222
|
+
const withArgs = withArguments(config2, node);
|
|
55223
|
+
if (withArgs.length === 0) {
|
|
55224
|
+
return { args: null, hash: "" };
|
|
55225
|
+
}
|
|
55226
|
+
let args = {};
|
|
55227
|
+
for (const arg of withArgs) {
|
|
55228
|
+
let value = arg.value;
|
|
55229
|
+
if (value.kind === GraphqlKinds2.VARIABLE) {
|
|
55230
|
+
if (!scope || !scope[value.name.value]) {
|
|
55231
|
+
throw new HoudiniError({
|
|
55232
|
+
filepath,
|
|
55233
|
+
message: "Encountered undefined variable: " + value.name.value
|
|
55234
|
+
});
|
|
55235
|
+
}
|
|
55236
|
+
value = scope[value.name.value];
|
|
55237
|
+
}
|
|
55238
|
+
args[arg.name.value] = {
|
|
55239
|
+
...value,
|
|
55240
|
+
loc: void 0
|
|
55241
|
+
};
|
|
55242
|
+
}
|
|
55243
|
+
return {
|
|
55244
|
+
args,
|
|
55245
|
+
hash: "_" + murmurHash(JSON.stringify(args))
|
|
55246
|
+
};
|
|
55247
|
+
}
|
|
55248
|
+
function operationScope(operation) {
|
|
55249
|
+
return operation.variableDefinitions?.reduce(
|
|
55250
|
+
(scope, definition) => ({
|
|
55251
|
+
...scope,
|
|
55252
|
+
[definition.variable.name.value]: {
|
|
55253
|
+
kind: "Variable",
|
|
55254
|
+
name: {
|
|
55255
|
+
kind: "Name",
|
|
55256
|
+
value: definition.variable.name.value
|
|
55257
|
+
}
|
|
55258
|
+
}
|
|
55259
|
+
}),
|
|
55260
|
+
{}
|
|
55261
|
+
) || {};
|
|
55262
|
+
}
|
|
55263
|
+
function fragmentArgumentsDefinitions(config2, filepath, definition) {
|
|
55264
|
+
const args = fragmentArguments(config2, filepath, definition);
|
|
55265
|
+
if (args.length === 0) {
|
|
55266
|
+
return [];
|
|
55267
|
+
}
|
|
55268
|
+
return args.map((arg) => {
|
|
55269
|
+
const innerType = {
|
|
55270
|
+
kind: "NamedType",
|
|
55271
|
+
name: {
|
|
55272
|
+
kind: "Name",
|
|
55273
|
+
value: arg.type
|
|
55274
|
+
}
|
|
55275
|
+
};
|
|
55276
|
+
return {
|
|
55277
|
+
kind: "VariableDefinition",
|
|
55278
|
+
type: arg.required ? innerType : {
|
|
55279
|
+
kind: "NonNullType",
|
|
55280
|
+
type: innerType
|
|
55281
|
+
},
|
|
55282
|
+
variable: {
|
|
55283
|
+
kind: "Variable",
|
|
55284
|
+
name: {
|
|
55285
|
+
kind: "Name",
|
|
55286
|
+
value: arg.name
|
|
55287
|
+
}
|
|
55288
|
+
},
|
|
55289
|
+
defaultValue: arg.defaultValue ?? void 0
|
|
55290
|
+
};
|
|
55291
|
+
});
|
|
55292
|
+
}
|
|
55293
|
+
|
|
55294
|
+
// src/codegen/generators/artifacts/indexFile.ts
|
|
55295
|
+
async function writeIndexFile(config2, docs) {
|
|
55296
|
+
const docsToGenerate = docs.filter((doc) => doc.generateArtifact).sort((a, b) => a.name.localeCompare(b.name));
|
|
55297
|
+
let body = config2.module === "esm" ? docsToGenerate.reduce(
|
|
55298
|
+
(content, doc) => content + `
|
|
55299
|
+
export { default as ${doc.name}} from './${doc.name}'`,
|
|
55300
|
+
""
|
|
55301
|
+
) : docsToGenerate.reduce(
|
|
55302
|
+
(content, doc) => content + `
|
|
55303
|
+
${exportDefaultFrom(`./${doc.name}`, doc.name)}`,
|
|
55304
|
+
cjsIndexFilePreamble
|
|
55305
|
+
);
|
|
55306
|
+
await fs_exports.writeFile(path_exports.join(config2.artifactDirectory, "index.js"), body);
|
|
55307
|
+
}
|
|
55308
|
+
|
|
55309
|
+
// src/codegen/generators/artifacts/inputs.ts
|
|
55310
|
+
var graphql4 = __toESM(require_graphql2(), 1);
|
|
55311
|
+
var recast3 = __toESM(require_main2(), 1);
|
|
55312
|
+
var AST3 = recast3.types.builders;
|
|
55313
|
+
function inputObject(config2, inputs) {
|
|
55314
|
+
const visitedTypes = /* @__PURE__ */ new Set();
|
|
55315
|
+
const inputObj = {
|
|
55316
|
+
fields: inputs.reduce((fields, input) => {
|
|
55317
|
+
const { type } = unwrapType(config2, input.type);
|
|
55318
|
+
return {
|
|
55319
|
+
...fields,
|
|
55320
|
+
[input.variable.name.value]: type.name
|
|
55321
|
+
};
|
|
55322
|
+
}, {}),
|
|
55323
|
+
types: {}
|
|
55324
|
+
};
|
|
55325
|
+
for (const input of inputs) {
|
|
55326
|
+
walkInputs(config2, visitedTypes, inputObj, input.type);
|
|
55327
|
+
}
|
|
55328
|
+
return inputObj;
|
|
55329
|
+
}
|
|
55330
|
+
function walkInputs(config2, visitedTypes, inputObj, rootType) {
|
|
55331
|
+
const { type } = unwrapType(config2, rootType);
|
|
55332
|
+
if (visitedTypes.has(type.name)) {
|
|
55333
|
+
return;
|
|
55334
|
+
}
|
|
55335
|
+
if (graphql4.isEnumType(type) || graphql4.isScalarType(type)) {
|
|
55336
|
+
return;
|
|
55337
|
+
}
|
|
55338
|
+
if (graphql4.isUnionType(type)) {
|
|
55339
|
+
return;
|
|
55340
|
+
}
|
|
55341
|
+
visitedTypes.add(type.name);
|
|
55342
|
+
inputObj.types[type.name] = Object.values(type.getFields()).reduce(
|
|
55343
|
+
(typeFields, field) => {
|
|
55344
|
+
const { type: fieldType } = unwrapType(config2, field.type);
|
|
55345
|
+
walkInputs(config2, visitedTypes, inputObj, fieldType);
|
|
55346
|
+
return {
|
|
55347
|
+
...typeFields,
|
|
55348
|
+
[field.name]: fieldType.toString()
|
|
55349
|
+
};
|
|
55350
|
+
},
|
|
55351
|
+
{}
|
|
55352
|
+
);
|
|
55353
|
+
}
|
|
55354
|
+
|
|
55355
|
+
// src/codegen/generators/artifacts/operations.ts
|
|
55356
|
+
var graphql6 = __toESM(require_graphql2(), 1);
|
|
55357
|
+
|
|
55358
|
+
// src/codegen/generators/artifacts/utils.ts
|
|
55359
|
+
var graphql5 = __toESM(require_graphql2(), 1);
|
|
55360
|
+
var recast4 = __toESM(require_main2(), 1);
|
|
55361
|
+
var AST4 = recast4.types.builders;
|
|
55362
|
+
function serializeValue(value) {
|
|
55363
|
+
if (Array.isArray(value)) {
|
|
55364
|
+
return AST4.arrayExpression(value.map(serializeValue));
|
|
55365
|
+
}
|
|
55366
|
+
if (typeof value === "object" && value !== null) {
|
|
55367
|
+
return AST4.objectExpression(
|
|
55368
|
+
Object.entries(value).filter(([, value2]) => typeof value2 !== "undefined").map(
|
|
55369
|
+
([key, value2]) => AST4.objectProperty(AST4.stringLiteral(key), serializeValue(value2))
|
|
55370
|
+
)
|
|
55371
|
+
);
|
|
55372
|
+
}
|
|
55373
|
+
if (typeof value === "string") {
|
|
55374
|
+
if (value.indexOf("\n") !== -1) {
|
|
55375
|
+
return AST4.templateLiteral(
|
|
55376
|
+
[AST4.templateElement({ raw: value, cooked: value }, true)],
|
|
55377
|
+
[]
|
|
55378
|
+
);
|
|
55379
|
+
}
|
|
55380
|
+
return AST4.stringLiteral(value);
|
|
55381
|
+
}
|
|
55382
|
+
return AST4.literal(value);
|
|
55383
|
+
}
|
|
55384
|
+
function deepMerge(filepath, ...targets) {
|
|
55385
|
+
if (typeof targets[0] !== "object") {
|
|
55386
|
+
const matches = targets.filter((val) => val !== targets[0]).length === 0;
|
|
55387
|
+
if (!matches) {
|
|
55388
|
+
throw new HoudiniError({ filepath, message: "could not merge: " + targets });
|
|
55389
|
+
}
|
|
55390
|
+
return targets[0];
|
|
55391
|
+
}
|
|
55392
|
+
if (Array.isArray(targets[0])) {
|
|
55393
|
+
return targets[0].concat(...targets.slice(1));
|
|
55394
|
+
}
|
|
55395
|
+
const fields = {};
|
|
55396
|
+
for (const target of targets) {
|
|
55397
|
+
for (const [key, value] of Object.entries(target)) {
|
|
55398
|
+
if (!fields[key]) {
|
|
55399
|
+
fields[key] = [];
|
|
55400
|
+
}
|
|
55401
|
+
fields[key].push(value);
|
|
55402
|
+
}
|
|
55403
|
+
}
|
|
55404
|
+
return Object.fromEntries(
|
|
55405
|
+
Object.entries(fields).map(([key, value]) => [key, deepMerge(filepath, ...value)])
|
|
55406
|
+
);
|
|
55407
|
+
}
|
|
55408
|
+
function convertValue(config2, val) {
|
|
55409
|
+
let value;
|
|
55410
|
+
let kind;
|
|
55411
|
+
if (val.kind === graphql5.Kind.INT) {
|
|
55412
|
+
value = parseInt(val.value, 10);
|
|
55413
|
+
kind = "Int";
|
|
55414
|
+
} else if (val.kind === graphql5.Kind.FLOAT) {
|
|
55415
|
+
value = parseFloat(val.value);
|
|
55416
|
+
kind = "Float";
|
|
55417
|
+
} else if (val.kind === graphql5.Kind.BOOLEAN) {
|
|
55418
|
+
value = val.value;
|
|
55419
|
+
kind = "Boolean";
|
|
55420
|
+
} else if (val.kind === graphql5.Kind.VARIABLE) {
|
|
55421
|
+
value = val.name.value;
|
|
55422
|
+
kind = "Variable";
|
|
55423
|
+
} else if (val.kind === graphql5.Kind.STRING) {
|
|
55424
|
+
value = val.value;
|
|
55425
|
+
kind = "String";
|
|
55426
|
+
}
|
|
55427
|
+
return { kind, value };
|
|
55428
|
+
}
|
|
55429
|
+
|
|
55430
|
+
// src/codegen/generators/artifacts/operations.ts
|
|
55431
|
+
function operationsByPath(config2, filepath, definition, filterTypes) {
|
|
55432
|
+
if (!definition) {
|
|
55433
|
+
return {};
|
|
55434
|
+
}
|
|
55435
|
+
const pathOperations = {};
|
|
55436
|
+
graphql6.visit(definition, {
|
|
55437
|
+
FragmentSpread(node, _, __, ___, ancestors) {
|
|
55438
|
+
if (!config2.isListFragment(node.name.value)) {
|
|
55439
|
+
return;
|
|
55440
|
+
}
|
|
55441
|
+
const path2 = ancestorKey(ancestors);
|
|
55442
|
+
if (!pathOperations[path2]) {
|
|
55443
|
+
pathOperations[path2] = [];
|
|
55444
|
+
}
|
|
55445
|
+
pathOperations[path2].push(
|
|
55446
|
+
operationObject({
|
|
55072
55447
|
config: config2,
|
|
55073
55448
|
filepath,
|
|
55074
55449
|
listName: config2.listNameFromFragment(node.name.value),
|
|
@@ -55217,7 +55592,7 @@ function ancestorKey(ancestors) {
|
|
|
55217
55592
|
}
|
|
55218
55593
|
|
|
55219
55594
|
// src/codegen/generators/artifacts/selection.ts
|
|
55220
|
-
var
|
|
55595
|
+
var graphql11 = __toESM(require_graphql2(), 1);
|
|
55221
55596
|
|
|
55222
55597
|
// ../../node_modules/.pnpm/@kitql+helper@0.5.0/node_modules/@kitql/helper/index.mjs
|
|
55223
55598
|
var config = {
|
|
@@ -55257,16 +55632,16 @@ function logYellow(str) {
|
|
|
55257
55632
|
}
|
|
55258
55633
|
|
|
55259
55634
|
// src/codegen/transforms/list.ts
|
|
55260
|
-
var
|
|
55635
|
+
var graphql9 = __toESM(require_graphql2(), 1);
|
|
55261
55636
|
|
|
55262
55637
|
// src/codegen/utils/objectIdentificationSelection.ts
|
|
55263
|
-
var
|
|
55638
|
+
var graphql7 = __toESM(require_graphql2(), 1);
|
|
55264
55639
|
var objectIdentificationSelection = (config2, type) => {
|
|
55265
55640
|
return config2.keyFieldsForType(type.name).map((key) => {
|
|
55266
55641
|
return {
|
|
55267
|
-
kind:
|
|
55642
|
+
kind: graphql7.Kind.FIELD,
|
|
55268
55643
|
name: {
|
|
55269
|
-
kind:
|
|
55644
|
+
kind: graphql7.Kind.NAME,
|
|
55270
55645
|
value: key
|
|
55271
55646
|
}
|
|
55272
55647
|
};
|
|
@@ -55274,7 +55649,7 @@ var objectIdentificationSelection = (config2, type) => {
|
|
|
55274
55649
|
};
|
|
55275
55650
|
|
|
55276
55651
|
// src/codegen/transforms/paginate.ts
|
|
55277
|
-
var
|
|
55652
|
+
var graphql8 = __toESM(require_graphql2(), 1);
|
|
55278
55653
|
async function paginate(config2, documents) {
|
|
55279
55654
|
const newDocs = [];
|
|
55280
55655
|
for (const doc of documents) {
|
|
@@ -55307,7 +55682,7 @@ async function paginate(config2, documents) {
|
|
|
55307
55682
|
};
|
|
55308
55683
|
let cursorType = "String";
|
|
55309
55684
|
let paginationPath = [];
|
|
55310
|
-
doc.document =
|
|
55685
|
+
doc.document = graphql8.visit(doc.document, {
|
|
55311
55686
|
Field(node, _, __, ___, ancestors) {
|
|
55312
55687
|
const paginateDirective = node.directives?.find(
|
|
55313
55688
|
(directive) => directive.name.value === config2.paginateDirective
|
|
@@ -55334,7 +55709,7 @@ async function paginate(config2, documents) {
|
|
|
55334
55709
|
flags.offset.enabled = offsetPagination;
|
|
55335
55710
|
flags.limit.enabled = offsetPagination;
|
|
55336
55711
|
paginationPath = ancestors.filter(
|
|
55337
|
-
(ancestor) => !Array.isArray(ancestor) && ancestor.kind ===
|
|
55712
|
+
(ancestor) => !Array.isArray(ancestor) && ancestor.kind === graphql8.Kind.FIELD
|
|
55338
55713
|
).concat(node).map((field) => field.alias?.value || field.name.value);
|
|
55339
55714
|
return {
|
|
55340
55715
|
...node,
|
|
@@ -55355,7 +55730,7 @@ async function paginate(config2, documents) {
|
|
|
55355
55730
|
refetchUpdate = "prepend" /* prepend */;
|
|
55356
55731
|
}
|
|
55357
55732
|
let fragment = "";
|
|
55358
|
-
doc.document =
|
|
55733
|
+
doc.document = graphql8.visit(doc.document, {
|
|
55359
55734
|
OperationDefinition(node) {
|
|
55360
55735
|
if (node.operation !== "query") {
|
|
55361
55736
|
throw new HoudiniError({
|
|
@@ -55409,9 +55784,9 @@ async function paginate(config2, documents) {
|
|
|
55409
55784
|
directives: [
|
|
55410
55785
|
...node.directives || [],
|
|
55411
55786
|
{
|
|
55412
|
-
kind:
|
|
55787
|
+
kind: graphql8.Kind.DIRECTIVE,
|
|
55413
55788
|
name: {
|
|
55414
|
-
kind:
|
|
55789
|
+
kind: graphql8.Kind.NAME,
|
|
55415
55790
|
value: config2.argumentsDirective
|
|
55416
55791
|
}
|
|
55417
55792
|
}
|
|
@@ -55474,16 +55849,16 @@ async function paginate(config2, documents) {
|
|
|
55474
55849
|
const paginationArgs = Object.entries(flags).filter(([_, { enabled }]) => enabled).map(([key, value]) => ({ name: key, ...value }));
|
|
55475
55850
|
const fragmentSpreadSelection = [
|
|
55476
55851
|
{
|
|
55477
|
-
kind:
|
|
55852
|
+
kind: graphql8.Kind.FRAGMENT_SPREAD,
|
|
55478
55853
|
name: {
|
|
55479
|
-
kind:
|
|
55854
|
+
kind: graphql8.Kind.NAME,
|
|
55480
55855
|
value: fragmentName
|
|
55481
55856
|
},
|
|
55482
55857
|
directives: [
|
|
55483
55858
|
{
|
|
55484
|
-
kind:
|
|
55859
|
+
kind: graphql8.Kind.DIRECTIVE,
|
|
55485
55860
|
name: {
|
|
55486
|
-
kind:
|
|
55861
|
+
kind: graphql8.Kind.NAME,
|
|
55487
55862
|
value: config2.withDirective
|
|
55488
55863
|
},
|
|
55489
55864
|
["arguments"]: paginationArgs.map(
|
|
@@ -55511,29 +55886,29 @@ async function paginate(config2, documents) {
|
|
|
55511
55886
|
});
|
|
55512
55887
|
const typeConfig = config2.typeConfig?.[fragment];
|
|
55513
55888
|
const queryDoc = {
|
|
55514
|
-
kind:
|
|
55889
|
+
kind: graphql8.Kind.DOCUMENT,
|
|
55515
55890
|
definitions: [
|
|
55516
55891
|
{
|
|
55517
|
-
kind:
|
|
55892
|
+
kind: graphql8.Kind.OPERATION_DEFINITION,
|
|
55518
55893
|
name: {
|
|
55519
|
-
kind:
|
|
55894
|
+
kind: graphql8.Kind.NAME,
|
|
55520
55895
|
value: refetchQueryName
|
|
55521
55896
|
},
|
|
55522
55897
|
operation: "query",
|
|
55523
55898
|
variableDefinitions: paginationArgs.map(
|
|
55524
55899
|
(arg) => ({
|
|
55525
|
-
kind:
|
|
55900
|
+
kind: graphql8.Kind.VARIABLE_DEFINITION,
|
|
55526
55901
|
type: {
|
|
55527
|
-
kind:
|
|
55902
|
+
kind: graphql8.Kind.NAMED_TYPE,
|
|
55528
55903
|
name: {
|
|
55529
|
-
kind:
|
|
55904
|
+
kind: graphql8.Kind.NAME,
|
|
55530
55905
|
value: arg.type
|
|
55531
55906
|
}
|
|
55532
55907
|
},
|
|
55533
55908
|
variable: {
|
|
55534
|
-
kind:
|
|
55909
|
+
kind: graphql8.Kind.VARIABLE,
|
|
55535
55910
|
name: {
|
|
55536
|
-
kind:
|
|
55911
|
+
kind: graphql8.Kind.NAME,
|
|
55537
55912
|
value: arg.name
|
|
55538
55913
|
}
|
|
55539
55914
|
},
|
|
@@ -55545,12 +55920,12 @@ async function paginate(config2, documents) {
|
|
|
55545
55920
|
).concat(
|
|
55546
55921
|
!nodeQuery ? [] : keys.map(
|
|
55547
55922
|
(key) => ({
|
|
55548
|
-
kind:
|
|
55923
|
+
kind: graphql8.Kind.VARIABLE_DEFINITION,
|
|
55549
55924
|
type: key.type,
|
|
55550
55925
|
variable: {
|
|
55551
|
-
kind:
|
|
55926
|
+
kind: graphql8.Kind.VARIABLE,
|
|
55552
55927
|
name: {
|
|
55553
|
-
kind:
|
|
55928
|
+
kind: graphql8.Kind.NAME,
|
|
55554
55929
|
value: key.name
|
|
55555
55930
|
}
|
|
55556
55931
|
}
|
|
@@ -55558,42 +55933,42 @@ async function paginate(config2, documents) {
|
|
|
55558
55933
|
)
|
|
55559
55934
|
),
|
|
55560
55935
|
selectionSet: {
|
|
55561
|
-
kind:
|
|
55936
|
+
kind: graphql8.Kind.SELECTION_SET,
|
|
55562
55937
|
selections: !nodeQuery ? fragmentSpreadSelection : [
|
|
55563
55938
|
{
|
|
55564
|
-
kind:
|
|
55939
|
+
kind: graphql8.Kind.FIELD,
|
|
55565
55940
|
name: {
|
|
55566
|
-
kind:
|
|
55941
|
+
kind: graphql8.Kind.NAME,
|
|
55567
55942
|
value: typeConfig?.resolve?.queryField || "node"
|
|
55568
55943
|
},
|
|
55569
55944
|
["arguments"]: keys.map((key) => ({
|
|
55570
|
-
kind:
|
|
55945
|
+
kind: graphql8.Kind.ARGUMENT,
|
|
55571
55946
|
name: {
|
|
55572
|
-
kind:
|
|
55947
|
+
kind: graphql8.Kind.NAME,
|
|
55573
55948
|
value: key.name
|
|
55574
55949
|
},
|
|
55575
55950
|
value: {
|
|
55576
|
-
kind:
|
|
55951
|
+
kind: graphql8.Kind.VARIABLE,
|
|
55577
55952
|
name: {
|
|
55578
|
-
kind:
|
|
55953
|
+
kind: graphql8.Kind.NAME,
|
|
55579
55954
|
value: key.name
|
|
55580
55955
|
}
|
|
55581
55956
|
}
|
|
55582
55957
|
})),
|
|
55583
55958
|
selectionSet: {
|
|
55584
|
-
kind:
|
|
55959
|
+
kind: graphql8.Kind.SELECTION_SET,
|
|
55585
55960
|
selections: [
|
|
55586
55961
|
{
|
|
55587
|
-
kind:
|
|
55962
|
+
kind: graphql8.Kind.FIELD,
|
|
55588
55963
|
name: {
|
|
55589
|
-
kind:
|
|
55964
|
+
kind: graphql8.Kind.NAME,
|
|
55590
55965
|
value: "__typename"
|
|
55591
55966
|
}
|
|
55592
55967
|
},
|
|
55593
55968
|
...(typeConfig?.keys || ["id"]).map((key) => ({
|
|
55594
|
-
kind:
|
|
55969
|
+
kind: graphql8.Kind.FIELD,
|
|
55595
55970
|
name: {
|
|
55596
|
-
kind:
|
|
55971
|
+
kind: graphql8.Kind.NAME,
|
|
55597
55972
|
value: key
|
|
55598
55973
|
}
|
|
55599
55974
|
})),
|
|
@@ -55655,15 +56030,15 @@ function replaceArgumentsWithVariables(args, flags) {
|
|
|
55655
56030
|
}
|
|
55656
56031
|
function variableAsArgument(name2, variable) {
|
|
55657
56032
|
return {
|
|
55658
|
-
kind:
|
|
56033
|
+
kind: graphql8.Kind.ARGUMENT,
|
|
55659
56034
|
name: {
|
|
55660
|
-
kind:
|
|
56035
|
+
kind: graphql8.Kind.NAME,
|
|
55661
56036
|
value: name2
|
|
55662
56037
|
},
|
|
55663
56038
|
value: {
|
|
55664
|
-
kind:
|
|
56039
|
+
kind: graphql8.Kind.VARIABLE,
|
|
55665
56040
|
name: {
|
|
55666
|
-
kind:
|
|
56041
|
+
kind: graphql8.Kind.NAME,
|
|
55667
56042
|
value: variable ?? name2
|
|
55668
56043
|
}
|
|
55669
56044
|
}
|
|
@@ -55671,18 +56046,18 @@ function variableAsArgument(name2, variable) {
|
|
|
55671
56046
|
}
|
|
55672
56047
|
function staticVariableDefinition(name2, type, defaultValue, variableName) {
|
|
55673
56048
|
return {
|
|
55674
|
-
kind:
|
|
56049
|
+
kind: graphql8.Kind.VARIABLE_DEFINITION,
|
|
55675
56050
|
type: {
|
|
55676
|
-
kind:
|
|
56051
|
+
kind: graphql8.Kind.NAMED_TYPE,
|
|
55677
56052
|
name: {
|
|
55678
|
-
kind:
|
|
56053
|
+
kind: graphql8.Kind.NAME,
|
|
55679
56054
|
value: type
|
|
55680
56055
|
}
|
|
55681
56056
|
},
|
|
55682
56057
|
variable: {
|
|
55683
|
-
kind:
|
|
56058
|
+
kind: graphql8.Kind.VARIABLE,
|
|
55684
56059
|
name: {
|
|
55685
|
-
kind:
|
|
56060
|
+
kind: graphql8.Kind.NAME,
|
|
55686
56061
|
value: variableName ?? name2
|
|
55687
56062
|
}
|
|
55688
56063
|
},
|
|
@@ -55694,9 +56069,9 @@ function staticVariableDefinition(name2, type, defaultValue, variableName) {
|
|
|
55694
56069
|
}
|
|
55695
56070
|
function argumentNode(name2, value) {
|
|
55696
56071
|
return {
|
|
55697
|
-
kind:
|
|
56072
|
+
kind: graphql8.Kind.ARGUMENT,
|
|
55698
56073
|
name: {
|
|
55699
|
-
kind:
|
|
56074
|
+
kind: graphql8.Kind.NAME,
|
|
55700
56075
|
value: name2
|
|
55701
56076
|
},
|
|
55702
56077
|
value: objectNode(value)
|
|
@@ -55704,16 +56079,16 @@ function argumentNode(name2, value) {
|
|
|
55704
56079
|
}
|
|
55705
56080
|
function objectNode([type, defaultValue]) {
|
|
55706
56081
|
const node = {
|
|
55707
|
-
kind:
|
|
56082
|
+
kind: graphql8.Kind.OBJECT,
|
|
55708
56083
|
fields: [
|
|
55709
56084
|
{
|
|
55710
|
-
kind:
|
|
56085
|
+
kind: graphql8.Kind.OBJECT_FIELD,
|
|
55711
56086
|
name: {
|
|
55712
|
-
kind:
|
|
56087
|
+
kind: graphql8.Kind.NAME,
|
|
55713
56088
|
value: "type"
|
|
55714
56089
|
},
|
|
55715
56090
|
value: {
|
|
55716
|
-
kind:
|
|
56091
|
+
kind: graphql8.Kind.STRING,
|
|
55717
56092
|
value: type
|
|
55718
56093
|
}
|
|
55719
56094
|
}
|
|
@@ -55721,8 +56096,8 @@ function objectNode([type, defaultValue]) {
|
|
|
55721
56096
|
};
|
|
55722
56097
|
if (defaultValue) {
|
|
55723
56098
|
node.fields.push({
|
|
55724
|
-
kind:
|
|
55725
|
-
name: { kind:
|
|
56099
|
+
kind: graphql8.Kind.OBJECT_FIELD,
|
|
56100
|
+
name: { kind: graphql8.Kind.NAME, value: "default" },
|
|
55726
56101
|
value: {
|
|
55727
56102
|
kind: typeof defaultValue === "number" ? "IntValue" : "StringValue",
|
|
55728
56103
|
value: defaultValue.toString()
|
|
@@ -55733,34 +56108,34 @@ function objectNode([type, defaultValue]) {
|
|
|
55733
56108
|
}
|
|
55734
56109
|
var pageInfoSelection = [
|
|
55735
56110
|
{
|
|
55736
|
-
kind:
|
|
56111
|
+
kind: graphql8.Kind.FIELD,
|
|
55737
56112
|
name: {
|
|
55738
|
-
kind:
|
|
56113
|
+
kind: graphql8.Kind.NAME,
|
|
55739
56114
|
value: "edges"
|
|
55740
56115
|
},
|
|
55741
56116
|
selectionSet: {
|
|
55742
|
-
kind:
|
|
56117
|
+
kind: graphql8.Kind.SELECTION_SET,
|
|
55743
56118
|
selections: [
|
|
55744
56119
|
{
|
|
55745
|
-
kind:
|
|
56120
|
+
kind: graphql8.Kind.FIELD,
|
|
55746
56121
|
name: {
|
|
55747
|
-
kind:
|
|
56122
|
+
kind: graphql8.Kind.NAME,
|
|
55748
56123
|
value: "cursor"
|
|
55749
56124
|
}
|
|
55750
56125
|
},
|
|
55751
56126
|
{
|
|
55752
|
-
kind:
|
|
56127
|
+
kind: graphql8.Kind.FIELD,
|
|
55753
56128
|
name: {
|
|
55754
|
-
kind:
|
|
56129
|
+
kind: graphql8.Kind.NAME,
|
|
55755
56130
|
value: "node"
|
|
55756
56131
|
},
|
|
55757
56132
|
selectionSet: {
|
|
55758
|
-
kind:
|
|
56133
|
+
kind: graphql8.Kind.SELECTION_SET,
|
|
55759
56134
|
selections: [
|
|
55760
56135
|
{
|
|
55761
|
-
kind:
|
|
56136
|
+
kind: graphql8.Kind.FIELD,
|
|
55762
56137
|
name: {
|
|
55763
|
-
kind:
|
|
56138
|
+
kind: graphql8.Kind.NAME,
|
|
55764
56139
|
value: "__typename"
|
|
55765
56140
|
}
|
|
55766
56141
|
}
|
|
@@ -55771,39 +56146,39 @@ var pageInfoSelection = [
|
|
|
55771
56146
|
}
|
|
55772
56147
|
},
|
|
55773
56148
|
{
|
|
55774
|
-
kind:
|
|
56149
|
+
kind: graphql8.Kind.FIELD,
|
|
55775
56150
|
name: {
|
|
55776
|
-
kind:
|
|
56151
|
+
kind: graphql8.Kind.NAME,
|
|
55777
56152
|
value: "pageInfo"
|
|
55778
56153
|
},
|
|
55779
56154
|
selectionSet: {
|
|
55780
|
-
kind:
|
|
56155
|
+
kind: graphql8.Kind.SELECTION_SET,
|
|
55781
56156
|
selections: [
|
|
55782
56157
|
{
|
|
55783
|
-
kind:
|
|
56158
|
+
kind: graphql8.Kind.FIELD,
|
|
55784
56159
|
name: {
|
|
55785
|
-
kind:
|
|
56160
|
+
kind: graphql8.Kind.NAME,
|
|
55786
56161
|
value: "hasPreviousPage"
|
|
55787
56162
|
}
|
|
55788
56163
|
},
|
|
55789
56164
|
{
|
|
55790
|
-
kind:
|
|
56165
|
+
kind: graphql8.Kind.FIELD,
|
|
55791
56166
|
name: {
|
|
55792
|
-
kind:
|
|
56167
|
+
kind: graphql8.Kind.NAME,
|
|
55793
56168
|
value: "hasNextPage"
|
|
55794
56169
|
}
|
|
55795
56170
|
},
|
|
55796
56171
|
{
|
|
55797
|
-
kind:
|
|
56172
|
+
kind: graphql8.Kind.FIELD,
|
|
55798
56173
|
name: {
|
|
55799
|
-
kind:
|
|
56174
|
+
kind: graphql8.Kind.NAME,
|
|
55800
56175
|
value: "startCursor"
|
|
55801
56176
|
}
|
|
55802
56177
|
},
|
|
55803
56178
|
{
|
|
55804
|
-
kind:
|
|
56179
|
+
kind: graphql8.Kind.FIELD,
|
|
55805
56180
|
name: {
|
|
55806
|
-
kind:
|
|
56181
|
+
kind: graphql8.Kind.NAME,
|
|
55807
56182
|
value: "endCursor"
|
|
55808
56183
|
}
|
|
55809
56184
|
}
|
|
@@ -55817,15 +56192,15 @@ async function addListFragments(config2, documents) {
|
|
|
55817
56192
|
const lists = {};
|
|
55818
56193
|
const errors = [];
|
|
55819
56194
|
for (const doc of documents) {
|
|
55820
|
-
doc.document =
|
|
56195
|
+
doc.document = graphql9.visit(doc.document, {
|
|
55821
56196
|
Directive(node, key, parent, path2, ancestors) {
|
|
55822
56197
|
if ([config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
|
|
55823
56198
|
const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
|
|
55824
56199
|
let error = {
|
|
55825
|
-
...new
|
|
56200
|
+
...new graphql9.GraphQLError(
|
|
55826
56201
|
"",
|
|
55827
56202
|
node,
|
|
55828
|
-
new
|
|
56203
|
+
new graphql9.Source(""),
|
|
55829
56204
|
node.loc ? [node.loc.start, node.loc.end] : null,
|
|
55830
56205
|
path2
|
|
55831
56206
|
),
|
|
@@ -55877,7 +56252,7 @@ async function addListFragments(config2, documents) {
|
|
|
55877
56252
|
{
|
|
55878
56253
|
kind: "Argument",
|
|
55879
56254
|
name: {
|
|
55880
|
-
kind:
|
|
56255
|
+
kind: graphql9.Kind.NAME,
|
|
55881
56256
|
value: "connection"
|
|
55882
56257
|
},
|
|
55883
56258
|
value: {
|
|
@@ -55927,7 +56302,7 @@ async function addListFragments(config2, documents) {
|
|
|
55927
56302
|
const validDeletes = [
|
|
55928
56303
|
...new Set(
|
|
55929
56304
|
Object.values(lists).map(({ type }) => {
|
|
55930
|
-
if (!(type instanceof
|
|
56305
|
+
if (!(type instanceof graphql9.GraphQLObjectType)) {
|
|
55931
56306
|
return "";
|
|
55932
56307
|
}
|
|
55933
56308
|
if (config2.keyFieldsForType(type.name).length !== 1) {
|
|
@@ -55941,7 +56316,7 @@ async function addListFragments(config2, documents) {
|
|
|
55941
56316
|
return;
|
|
55942
56317
|
}
|
|
55943
56318
|
const generatedDoc = {
|
|
55944
|
-
kind:
|
|
56319
|
+
kind: graphql9.Kind.DOCUMENT,
|
|
55945
56320
|
definitions: Object.entries(lists).flatMap(
|
|
55946
56321
|
([name2, { selection: selection2, type }]) => {
|
|
55947
56322
|
const schemaType = config2.schema.getType(type.name);
|
|
@@ -55949,7 +56324,7 @@ async function addListFragments(config2, documents) {
|
|
|
55949
56324
|
throw new HoudiniError({ message: "Lists must have a selection" });
|
|
55950
56325
|
}
|
|
55951
56326
|
const fragmentSelection = {
|
|
55952
|
-
kind:
|
|
56327
|
+
kind: graphql9.Kind.SELECTION_SET,
|
|
55953
56328
|
selections: [...selection2.selections]
|
|
55954
56329
|
};
|
|
55955
56330
|
if (schemaType && fragmentSelection && !fragmentSelection?.selections.find(
|
|
@@ -55964,14 +56339,14 @@ async function addListFragments(config2, documents) {
|
|
|
55964
56339
|
{
|
|
55965
56340
|
name: {
|
|
55966
56341
|
value: config2.listInsertFragment(name2),
|
|
55967
|
-
kind:
|
|
56342
|
+
kind: graphql9.Kind.NAME
|
|
55968
56343
|
},
|
|
55969
|
-
kind:
|
|
56344
|
+
kind: graphql9.Kind.FRAGMENT_DEFINITION,
|
|
55970
56345
|
selectionSet: fragmentSelection,
|
|
55971
56346
|
typeCondition: {
|
|
55972
|
-
kind:
|
|
56347
|
+
kind: graphql9.Kind.NAMED_TYPE,
|
|
55973
56348
|
name: {
|
|
55974
|
-
kind:
|
|
56349
|
+
kind: graphql9.Kind.NAME,
|
|
55975
56350
|
value: type.name
|
|
55976
56351
|
}
|
|
55977
56352
|
}
|
|
@@ -55979,32 +56354,32 @@ async function addListFragments(config2, documents) {
|
|
|
55979
56354
|
{
|
|
55980
56355
|
name: {
|
|
55981
56356
|
value: config2.listToggleFragment(name2),
|
|
55982
|
-
kind:
|
|
56357
|
+
kind: graphql9.Kind.NAME
|
|
55983
56358
|
},
|
|
55984
|
-
kind:
|
|
56359
|
+
kind: graphql9.Kind.FRAGMENT_DEFINITION,
|
|
55985
56360
|
selectionSet: fragmentSelection,
|
|
55986
56361
|
typeCondition: {
|
|
55987
|
-
kind:
|
|
56362
|
+
kind: graphql9.Kind.NAMED_TYPE,
|
|
55988
56363
|
name: {
|
|
55989
|
-
kind:
|
|
56364
|
+
kind: graphql9.Kind.NAME,
|
|
55990
56365
|
value: type.name
|
|
55991
56366
|
}
|
|
55992
56367
|
}
|
|
55993
56368
|
},
|
|
55994
56369
|
{
|
|
55995
|
-
kind:
|
|
56370
|
+
kind: graphql9.Kind.FRAGMENT_DEFINITION,
|
|
55996
56371
|
name: {
|
|
55997
56372
|
value: config2.listRemoveFragment(name2),
|
|
55998
|
-
kind:
|
|
56373
|
+
kind: graphql9.Kind.NAME
|
|
55999
56374
|
},
|
|
56000
56375
|
selectionSet: {
|
|
56001
|
-
kind:
|
|
56376
|
+
kind: graphql9.Kind.SELECTION_SET,
|
|
56002
56377
|
selections: [...objectIdentificationSelection(config2, type)]
|
|
56003
56378
|
},
|
|
56004
56379
|
typeCondition: {
|
|
56005
|
-
kind:
|
|
56380
|
+
kind: graphql9.Kind.NAMED_TYPE,
|
|
56006
56381
|
name: {
|
|
56007
|
-
kind:
|
|
56382
|
+
kind: graphql9.Kind.NAME,
|
|
56008
56383
|
value: type.name
|
|
56009
56384
|
}
|
|
56010
56385
|
}
|
|
@@ -56013,14 +56388,14 @@ async function addListFragments(config2, documents) {
|
|
|
56013
56388
|
}
|
|
56014
56389
|
).concat(
|
|
56015
56390
|
...validDeletes.map((typeName) => ({
|
|
56016
|
-
kind:
|
|
56391
|
+
kind: graphql9.Kind.DIRECTIVE_DEFINITION,
|
|
56017
56392
|
name: {
|
|
56018
|
-
kind:
|
|
56393
|
+
kind: graphql9.Kind.NAME,
|
|
56019
56394
|
value: config2.listDeleteDirective(typeName)
|
|
56020
56395
|
},
|
|
56021
56396
|
locations: [
|
|
56022
56397
|
{
|
|
56023
|
-
kind:
|
|
56398
|
+
kind: graphql9.Kind.NAME,
|
|
56024
56399
|
value: "FIELD"
|
|
56025
56400
|
}
|
|
56026
56401
|
],
|
|
@@ -56028,8 +56403,8 @@ async function addListFragments(config2, documents) {
|
|
|
56028
56403
|
}))
|
|
56029
56404
|
)
|
|
56030
56405
|
};
|
|
56031
|
-
config2.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(
|
|
56032
|
-
config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(
|
|
56406
|
+
config2.newSchema += "\n" + generatedDoc.definitions.filter((c) => c.kind !== "FragmentDefinition").map(graphql9.print).join("\n\n");
|
|
56407
|
+
config2.newDocuments += "\n" + generatedDoc.definitions.filter((c) => c.kind === "FragmentDefinition").map(graphql9.print).join("\n\n");
|
|
56033
56408
|
documents.push({
|
|
56034
56409
|
name: "generated::lists",
|
|
56035
56410
|
kind: "HoudiniFragment" /* Fragment */,
|
|
@@ -56114,11 +56489,11 @@ var nodeNotDefinedMessage = (config2) => `Looks like you are trying to use the $
|
|
|
56114
56489
|
For more information, visit this link: ${siteURL}/guides/pagination`;
|
|
56115
56490
|
|
|
56116
56491
|
// src/codegen/generators/artifacts/fieldKey.ts
|
|
56117
|
-
var
|
|
56492
|
+
var graphql10 = __toESM(require_graphql2(), 1);
|
|
56118
56493
|
function fieldKey(config2, field) {
|
|
56119
56494
|
const attributeName = field.alias?.value || field.name.value;
|
|
56120
|
-
const printed =
|
|
56121
|
-
const secondParse =
|
|
56495
|
+
const printed = graphql10.print(field);
|
|
56496
|
+
const secondParse = graphql10.parse(`{${printed}}`).definitions[0].selectionSet.selections[0];
|
|
56122
56497
|
const paginated = !!field.directives?.find(
|
|
56123
56498
|
(directive) => directive.name.value === config2.paginateDirective
|
|
56124
56499
|
);
|
|
@@ -56213,8 +56588,8 @@ function selection({
|
|
|
56213
56588
|
const typeConditionName = field.typeCondition.name.value;
|
|
56214
56589
|
const typeCondition = config2.schema.getType(typeConditionName);
|
|
56215
56590
|
const possibleTypes = [];
|
|
56216
|
-
if (!
|
|
56217
|
-
} else if (
|
|
56591
|
+
if (!graphql11.isAbstractType(typeCondition)) {
|
|
56592
|
+
} else if (graphql11.isAbstractType(parentType)) {
|
|
56218
56593
|
const possibleParentTypes = config2.schema.getPossibleTypes(parentType).map((type) => type.name);
|
|
56219
56594
|
for (const possible of config2.schema.getPossibleTypes(typeCondition)) {
|
|
56220
56595
|
if (possibleParentTypes.includes(possible.name)) {
|
|
@@ -56262,7 +56637,7 @@ function selection({
|
|
|
56262
56637
|
} else {
|
|
56263
56638
|
let typeRef = type.getFields()[field.name.value].type;
|
|
56264
56639
|
fieldType = getRootType(typeRef);
|
|
56265
|
-
nullable = !
|
|
56640
|
+
nullable = !graphql11.isNonNullType(typeRef);
|
|
56266
56641
|
}
|
|
56267
56642
|
const typeName = fieldType.toString();
|
|
56268
56643
|
const pathSoFar = path2.concat(attributeName);
|
|
@@ -56327,7 +56702,7 @@ function selection({
|
|
|
56327
56702
|
{}
|
|
56328
56703
|
);
|
|
56329
56704
|
}
|
|
56330
|
-
if (
|
|
56705
|
+
if (graphql11.isInterfaceType(fieldType) || graphql11.isUnionType(fieldType)) {
|
|
56331
56706
|
fieldObj.abstract = true;
|
|
56332
56707
|
}
|
|
56333
56708
|
object.fields = {
|
|
@@ -56384,7 +56759,7 @@ function artifactGenerator(stats) {
|
|
|
56384
56759
|
return async function(config2, docs) {
|
|
56385
56760
|
const filterTypes = {};
|
|
56386
56761
|
for (const doc of docs) {
|
|
56387
|
-
|
|
56762
|
+
graphql12.visit(doc.document, {
|
|
56388
56763
|
Directive(node, _, __, ___, ancestors) {
|
|
56389
56764
|
if (node.name.value !== config2.listDirective) {
|
|
56390
56765
|
return;
|
|
@@ -56443,7 +56818,7 @@ function artifactGenerator(stats) {
|
|
|
56443
56818
|
return;
|
|
56444
56819
|
}
|
|
56445
56820
|
const usedVariableNames = /* @__PURE__ */ new Set();
|
|
56446
|
-
let documentWithoutInternalDirectives =
|
|
56821
|
+
let documentWithoutInternalDirectives = graphql12.visit(document, {
|
|
56447
56822
|
Directive(node) {
|
|
56448
56823
|
if (config2.isInternalDirective(node)) {
|
|
56449
56824
|
return null;
|
|
@@ -56456,7 +56831,7 @@ function artifactGenerator(stats) {
|
|
|
56456
56831
|
}
|
|
56457
56832
|
}
|
|
56458
56833
|
});
|
|
56459
|
-
let documentWithoutExtraVariables =
|
|
56834
|
+
let documentWithoutExtraVariables = graphql12.visit(
|
|
56460
56835
|
documentWithoutInternalDirectives,
|
|
56461
56836
|
{
|
|
56462
56837
|
VariableDefinition(variableDefinitionNode) {
|
|
@@ -56467,13 +56842,13 @@ function artifactGenerator(stats) {
|
|
|
56467
56842
|
}
|
|
56468
56843
|
}
|
|
56469
56844
|
);
|
|
56470
|
-
let rawString =
|
|
56845
|
+
let rawString = graphql12.print(documentWithoutExtraVariables);
|
|
56471
56846
|
let docKind = doc.kind;
|
|
56472
56847
|
const operations = document.definitions.filter(
|
|
56473
|
-
({ kind }) => kind ===
|
|
56848
|
+
({ kind }) => kind === graphql12.Kind.OPERATION_DEFINITION
|
|
56474
56849
|
);
|
|
56475
56850
|
const fragments = document.definitions.filter(
|
|
56476
|
-
({ kind }) => kind ===
|
|
56851
|
+
({ kind }) => kind === graphql12.Kind.FRAGMENT_DEFINITION
|
|
56477
56852
|
);
|
|
56478
56853
|
let rootType = "";
|
|
56479
56854
|
let selectionSet;
|
|
@@ -56506,7 +56881,13 @@ function artifactGenerator(stats) {
|
|
|
56506
56881
|
rootType = matchingFragment.typeCondition.name.value;
|
|
56507
56882
|
selectionSet = matchingFragment.selectionSet;
|
|
56508
56883
|
}
|
|
56509
|
-
|
|
56884
|
+
let inputs = operations[0]?.variableDefinitions;
|
|
56885
|
+
let directive = fragments[0]?.directives?.find(
|
|
56886
|
+
(directive2) => directive2.name.value === config2.argumentsDirective
|
|
56887
|
+
);
|
|
56888
|
+
if (docKind === "HoudiniFragment" /* Fragment */ && directive) {
|
|
56889
|
+
inputs = fragmentArgumentsDefinitions(config2, doc.filename, fragments[0]);
|
|
56890
|
+
}
|
|
56510
56891
|
const mergedSelection = flattenSelections({
|
|
56511
56892
|
config: config2,
|
|
56512
56893
|
filepath: doc.filename,
|
|
@@ -56567,7 +56948,7 @@ function artifactGenerator(stats) {
|
|
|
56567
56948
|
}
|
|
56568
56949
|
if (docKind === "HoudiniQuery") {
|
|
56569
56950
|
const cacheDirective = operations[0].directives?.find(
|
|
56570
|
-
(
|
|
56951
|
+
(directive2) => directive2.name.value === config2.cacheDirective
|
|
56571
56952
|
);
|
|
56572
56953
|
if (cacheDirective) {
|
|
56573
56954
|
const args = cacheDirective.arguments?.reduce(
|
|
@@ -56783,19 +57164,19 @@ async function generatePluginRuntime(config2, plugin) {
|
|
|
56783
57164
|
);
|
|
56784
57165
|
}
|
|
56785
57166
|
|
|
56786
|
-
// src/codegen/generators/typescript/
|
|
56787
|
-
var
|
|
57167
|
+
// src/codegen/generators/typescript/documentTypes.ts
|
|
57168
|
+
var recast11 = __toESM(require_main2(), 1);
|
|
56788
57169
|
|
|
56789
57170
|
// src/codegen/generators/typescript/addReferencedInputTypes.ts
|
|
56790
|
-
var
|
|
57171
|
+
var graphql15 = __toESM(require_graphql2(), 1);
|
|
56791
57172
|
var recast9 = __toESM(require_main2(), 1);
|
|
56792
57173
|
|
|
56793
57174
|
// src/codegen/generators/typescript/typeReference.ts
|
|
56794
|
-
var
|
|
57175
|
+
var graphql14 = __toESM(require_graphql2(), 1);
|
|
56795
57176
|
var recast8 = __toESM(require_main2(), 1);
|
|
56796
57177
|
|
|
56797
57178
|
// src/codegen/generators/typescript/types.ts
|
|
56798
|
-
var
|
|
57179
|
+
var graphql13 = __toESM(require_graphql2(), 1);
|
|
56799
57180
|
var recast7 = __toESM(require_main2(), 1);
|
|
56800
57181
|
var AST7 = recast7.types.builders;
|
|
56801
57182
|
function readonlyProperty(prop, enable = true) {
|
|
@@ -56826,336 +57207,89 @@ function scalarPropertyValue(config2, missingScalars, target) {
|
|
|
56826
57207
|
return AST7.tsBooleanKeyword();
|
|
56827
57208
|
}
|
|
56828
57209
|
case "ID": {
|
|
56829
|
-
return AST7.tsStringKeyword();
|
|
56830
|
-
}
|
|
56831
|
-
default: {
|
|
56832
|
-
if (
|
|
56833
|
-
return scalarPropertyValue(
|
|
56834
|
-
config2,
|
|
56835
|
-
missingScalars,
|
|
56836
|
-
target.ofType
|
|
56837
|
-
);
|
|
56838
|
-
}
|
|
56839
|
-
if (config2.scalars?.[target.name]) {
|
|
56840
|
-
return AST7.tsTypeReference(AST7.identifier(config2.scalars?.[target.name].type));
|
|
56841
|
-
}
|
|
56842
|
-
missingScalars.add(target.name);
|
|
56843
|
-
return AST7.tsAnyKeyword();
|
|
56844
|
-
}
|
|
56845
|
-
}
|
|
56846
|
-
}
|
|
56847
|
-
|
|
56848
|
-
// src/codegen/generators/typescript/typeReference.ts
|
|
56849
|
-
var AST8 = recast8.types.builders;
|
|
56850
|
-
function tsTypeReference(config2, missingScalars, definition) {
|
|
56851
|
-
const { type, wrappers } = unwrapType(config2, definition.type);
|
|
56852
|
-
let result;
|
|
56853
|
-
if (graphql13.isScalarType(type)) {
|
|
56854
|
-
result = scalarPropertyValue(config2, missingScalars, type);
|
|
56855
|
-
} else {
|
|
56856
|
-
result = AST8.tsTypeReference(AST8.identifier(type.name));
|
|
56857
|
-
}
|
|
56858
|
-
for (const toWrap of wrappers) {
|
|
56859
|
-
if (toWrap === "NonNull" /* NonNull */) {
|
|
56860
|
-
continue;
|
|
56861
|
-
} else if (toWrap === "Nullable" /* Nullable */) {
|
|
56862
|
-
result = nullableField(result, true);
|
|
56863
|
-
} else if (toWrap === "List" /* List */) {
|
|
56864
|
-
result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
|
|
56865
|
-
}
|
|
56866
|
-
}
|
|
56867
|
-
return result;
|
|
56868
|
-
}
|
|
56869
|
-
|
|
56870
|
-
// src/codegen/generators/typescript/addReferencedInputTypes.ts
|
|
56871
|
-
var AST9 = recast9.types.builders;
|
|
56872
|
-
function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, rootType) {
|
|
56873
|
-
const { type } = unwrapType(config2, rootType);
|
|
56874
|
-
if (graphql14.isScalarType(type)) {
|
|
56875
|
-
return;
|
|
56876
|
-
}
|
|
56877
|
-
if (visitedTypes.has(type.name)) {
|
|
56878
|
-
return;
|
|
56879
|
-
}
|
|
56880
|
-
if (graphql14.isUnionType(type)) {
|
|
56881
|
-
throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
|
|
56882
|
-
}
|
|
56883
|
-
visitedTypes.add(type.name);
|
|
56884
|
-
if (graphql14.isEnumType(type)) {
|
|
56885
|
-
ensureImports({
|
|
56886
|
-
config: config2,
|
|
56887
|
-
body,
|
|
56888
|
-
import: [type.name],
|
|
56889
|
-
sourceModule: "$houdini/graphql/enums",
|
|
56890
|
-
importKind: "type"
|
|
56891
|
-
});
|
|
56892
|
-
return;
|
|
56893
|
-
}
|
|
56894
|
-
const members = [];
|
|
56895
|
-
for (const field of Object.values(type.getFields())) {
|
|
56896
|
-
addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, field.type);
|
|
56897
|
-
members.push(
|
|
56898
|
-
AST9.tsPropertySignature(
|
|
56899
|
-
AST9.identifier(field.name),
|
|
56900
|
-
AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
|
|
56901
|
-
graphql14.isNullableType(field.type)
|
|
56902
|
-
)
|
|
56903
|
-
);
|
|
56904
|
-
}
|
|
56905
|
-
body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
|
|
56906
|
-
}
|
|
56907
|
-
|
|
56908
|
-
// src/codegen/generators/typescript/imperativeCache.ts
|
|
56909
|
-
var graphql15 = __toESM(require_graphql2(), 1);
|
|
56910
|
-
var recast10 = __toESM(require_main2(), 1);
|
|
56911
|
-
var AST10 = recast10.types.builders;
|
|
56912
|
-
async function imperativeCacheTypef(config2, docs) {
|
|
56913
|
-
const target = path_exports.join(config2.runtimeDirectory, "generated.d.ts");
|
|
56914
|
-
const body = [];
|
|
56915
|
-
const declaration = AST10.tsTypeAliasDeclaration(
|
|
56916
|
-
AST10.identifier(CacheTypeDefName),
|
|
56917
|
-
AST10.tsTypeLiteral([
|
|
56918
|
-
AST10.tsPropertySignature(
|
|
56919
|
-
AST10.identifier("types"),
|
|
56920
|
-
AST10.tsTypeAnnotation(typeDefinitions(config2, body))
|
|
56921
|
-
),
|
|
56922
|
-
AST10.tsPropertySignature(
|
|
56923
|
-
AST10.identifier("lists"),
|
|
56924
|
-
AST10.tsTypeAnnotation(listDefinitions(config2, docs))
|
|
56925
|
-
)
|
|
56926
|
-
])
|
|
56927
|
-
);
|
|
56928
|
-
declaration.declare = true;
|
|
56929
|
-
const importRecord = AST10.importDeclaration(
|
|
56930
|
-
[AST10.importSpecifier(AST10.identifier("Record"))],
|
|
56931
|
-
AST10.stringLiteral("./public/record")
|
|
56932
|
-
);
|
|
56933
|
-
importRecord.importKind = "type";
|
|
56934
|
-
await fs_exports.writeFile(
|
|
56935
|
-
target,
|
|
56936
|
-
recast10.prettyPrint(
|
|
56937
|
-
AST10.program([importRecord, ...body, AST10.exportNamedDeclaration(declaration)])
|
|
56938
|
-
).code
|
|
56939
|
-
);
|
|
56940
|
-
}
|
|
56941
|
-
function typeDefinitions(config2, body) {
|
|
56942
|
-
const operationTypes = [config2.schema.getMutationType(), config2.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
|
|
56943
|
-
const visitedTypes = /* @__PURE__ */ new Set();
|
|
56944
|
-
const types14 = Object.values(config2.schema.getTypeMap()).filter(
|
|
56945
|
-
(type) => !graphql15.isAbstractType(type) && !graphql15.isScalarType(type) && !graphql15.isEnumType(type) && !graphql15.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
|
|
56946
|
-
);
|
|
56947
|
-
return AST10.tsTypeLiteral(
|
|
56948
|
-
types14.map((type) => {
|
|
56949
|
-
let typeName = type.name;
|
|
56950
|
-
if (config2.schema.getQueryType() && config2.schema.getQueryType()?.name === type.name) {
|
|
56951
|
-
typeName = "__ROOT__";
|
|
56952
|
-
}
|
|
56953
|
-
let idFields = AST10.tsNeverKeyword();
|
|
56954
|
-
const keys = keyFieldsForType(config2.configFile, type.name);
|
|
56955
|
-
if (graphql15.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
|
|
56956
|
-
idFields = AST10.tsTypeLiteral(
|
|
56957
|
-
keys.map((key) => {
|
|
56958
|
-
const fieldType = type.getFields()[key];
|
|
56959
|
-
const unwrapped = unwrapType(config2, fieldType.type);
|
|
56960
|
-
return AST10.tsPropertySignature(
|
|
56961
|
-
AST10.identifier(key),
|
|
56962
|
-
AST10.tsTypeAnnotation(
|
|
56963
|
-
scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
|
|
56964
|
-
)
|
|
56965
|
-
);
|
|
56966
|
-
})
|
|
56967
|
-
);
|
|
56968
|
-
} else if (typeName === "__ROOT__") {
|
|
56969
|
-
idFields = AST10.tsTypeLiteral([]);
|
|
56970
|
-
}
|
|
56971
|
-
let fields = AST10.tsTypeLiteral([]);
|
|
56972
|
-
if (graphql15.isObjectType(type)) {
|
|
56973
|
-
fields = AST10.tsTypeLiteral(
|
|
56974
|
-
Object.entries(type.getFields()).map(
|
|
56975
|
-
([key, fieldType]) => {
|
|
56976
|
-
const unwrapped = unwrapType(config2, fieldType.type);
|
|
56977
|
-
let typeOptions = AST10.tsUnionType([]);
|
|
56978
|
-
if (graphql15.isScalarType(unwrapped.type)) {
|
|
56979
|
-
typeOptions.types.push(
|
|
56980
|
-
scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
|
|
56981
|
-
);
|
|
56982
|
-
} else if (graphql15.isEnumType(unwrapped.type)) {
|
|
56983
|
-
typeOptions.types.push(
|
|
56984
|
-
AST10.tsTypeReference(AST10.identifier(unwrapped.type.name))
|
|
56985
|
-
);
|
|
56986
|
-
} else if (!graphql15.isAbstractType(unwrapped.type)) {
|
|
56987
|
-
typeOptions.types.push(record(unwrapped.type.name));
|
|
56988
|
-
} else {
|
|
56989
|
-
typeOptions.types.push(
|
|
56990
|
-
...config2.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
|
|
56991
|
-
);
|
|
56992
|
-
}
|
|
56993
|
-
for (const wrapper of unwrapped.wrappers) {
|
|
56994
|
-
if (wrapper === "Nullable" /* Nullable */) {
|
|
56995
|
-
typeOptions = AST10.tsParenthesizedType(
|
|
56996
|
-
AST10.tsUnionType([typeOptions, AST10.tsNullKeyword()])
|
|
56997
|
-
);
|
|
56998
|
-
} else if (wrapper === "List" /* List */) {
|
|
56999
|
-
typeOptions = AST10.tsArrayType(
|
|
57000
|
-
AST10.tsParenthesizedType(typeOptions)
|
|
57001
|
-
);
|
|
57002
|
-
}
|
|
57003
|
-
}
|
|
57004
|
-
if (typeOptions.type === "TSParenthesizedType") {
|
|
57005
|
-
typeOptions = typeOptions.typeAnnotation;
|
|
57006
|
-
}
|
|
57007
|
-
let args = AST10.tsNeverKeyword();
|
|
57008
|
-
if (fieldType.args?.length > 0) {
|
|
57009
|
-
args = AST10.tsTypeLiteral(
|
|
57010
|
-
fieldType.args.map((arg) => {
|
|
57011
|
-
addReferencedInputTypes(
|
|
57012
|
-
config2,
|
|
57013
|
-
"",
|
|
57014
|
-
body,
|
|
57015
|
-
visitedTypes,
|
|
57016
|
-
/* @__PURE__ */ new Set(),
|
|
57017
|
-
arg.type
|
|
57018
|
-
);
|
|
57019
|
-
const prop = AST10.tsPropertySignature(
|
|
57020
|
-
AST10.identifier(arg.name),
|
|
57021
|
-
AST10.tsTypeAnnotation(
|
|
57022
|
-
tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
|
|
57023
|
-
)
|
|
57024
|
-
);
|
|
57025
|
-
const unwrapped2 = unwrapType(config2, arg.type);
|
|
57026
|
-
prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
|
|
57027
|
-
return prop;
|
|
57028
|
-
})
|
|
57029
|
-
);
|
|
57030
|
-
}
|
|
57031
|
-
return AST10.tsPropertySignature(
|
|
57032
|
-
AST10.identifier(key),
|
|
57033
|
-
AST10.tsTypeAnnotation(
|
|
57034
|
-
AST10.tsTypeLiteral([
|
|
57035
|
-
AST10.tsPropertySignature(
|
|
57036
|
-
AST10.identifier("type"),
|
|
57037
|
-
AST10.tsTypeAnnotation(typeOptions)
|
|
57038
|
-
),
|
|
57039
|
-
AST10.tsPropertySignature(
|
|
57040
|
-
AST10.identifier("args"),
|
|
57041
|
-
AST10.tsTypeAnnotation(args)
|
|
57042
|
-
)
|
|
57043
|
-
])
|
|
57044
|
-
)
|
|
57045
|
-
);
|
|
57046
|
-
}
|
|
57047
|
-
)
|
|
57210
|
+
return AST7.tsStringKeyword();
|
|
57211
|
+
}
|
|
57212
|
+
default: {
|
|
57213
|
+
if (graphql13.isNonNullType(target) && "ofType" in target) {
|
|
57214
|
+
return scalarPropertyValue(
|
|
57215
|
+
config2,
|
|
57216
|
+
missingScalars,
|
|
57217
|
+
target.ofType
|
|
57048
57218
|
);
|
|
57049
57219
|
}
|
|
57050
|
-
|
|
57051
|
-
|
|
57052
|
-
AST10.tsTypeAnnotation(
|
|
57053
|
-
AST10.tsTypeLiteral([
|
|
57054
|
-
AST10.tsPropertySignature(
|
|
57055
|
-
AST10.identifier("idFields"),
|
|
57056
|
-
AST10.tsTypeAnnotation(idFields)
|
|
57057
|
-
),
|
|
57058
|
-
AST10.tsPropertySignature(
|
|
57059
|
-
AST10.identifier("fields"),
|
|
57060
|
-
AST10.tsTypeAnnotation(fields)
|
|
57061
|
-
)
|
|
57062
|
-
])
|
|
57063
|
-
)
|
|
57064
|
-
);
|
|
57065
|
-
})
|
|
57066
|
-
);
|
|
57067
|
-
}
|
|
57068
|
-
function listDefinitions(config2, docs) {
|
|
57069
|
-
const lists = [];
|
|
57070
|
-
const visitedLists = /* @__PURE__ */ new Set();
|
|
57071
|
-
for (const doc of docs) {
|
|
57072
|
-
graphql15.visit(doc.document, {
|
|
57073
|
-
Directive(node, key, parent, path2, ancestors) {
|
|
57074
|
-
if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
|
|
57075
|
-
return;
|
|
57076
|
-
}
|
|
57077
|
-
const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
|
|
57078
|
-
const nameValue = nameArg?.value?.value || "";
|
|
57079
|
-
if (!nameValue || visitedLists.has(nameValue)) {
|
|
57080
|
-
return;
|
|
57081
|
-
}
|
|
57082
|
-
visitedLists.add(nameValue);
|
|
57083
|
-
const parentType = parentTypeFromAncestors(
|
|
57084
|
-
config2.schema,
|
|
57085
|
-
doc.filename,
|
|
57086
|
-
ancestors.slice(0, -1)
|
|
57087
|
-
);
|
|
57088
|
-
const targetField = ancestors[ancestors.length - 1];
|
|
57089
|
-
const targetFieldDefinition = parentType.getFields()[targetField.name.value];
|
|
57090
|
-
const { type: listType } = unwrapType(config2, targetFieldDefinition.type);
|
|
57091
|
-
const possibleTypes = [];
|
|
57092
|
-
if (graphql15.isAbstractType(listType)) {
|
|
57093
|
-
possibleTypes.push(
|
|
57094
|
-
...config2.schema.getPossibleTypes(listType).map((possible) => possible.name)
|
|
57095
|
-
);
|
|
57096
|
-
} else {
|
|
57097
|
-
possibleTypes.push(listType.name);
|
|
57098
|
-
}
|
|
57099
|
-
lists.push(
|
|
57100
|
-
AST10.tsPropertySignature(
|
|
57101
|
-
AST10.identifier(nameValue),
|
|
57102
|
-
AST10.tsTypeAnnotation(
|
|
57103
|
-
AST10.tsTypeLiteral([
|
|
57104
|
-
AST10.tsPropertySignature(
|
|
57105
|
-
AST10.identifier("types"),
|
|
57106
|
-
AST10.tsTypeAnnotation(
|
|
57107
|
-
AST10.tsUnionType(
|
|
57108
|
-
possibleTypes.map(
|
|
57109
|
-
(possible) => AST10.tsLiteralType(AST10.stringLiteral(possible))
|
|
57110
|
-
)
|
|
57111
|
-
)
|
|
57112
|
-
)
|
|
57113
|
-
),
|
|
57114
|
-
AST10.tsPropertySignature(
|
|
57115
|
-
AST10.identifier("filters"),
|
|
57116
|
-
AST10.tsTypeAnnotation(
|
|
57117
|
-
targetFieldDefinition.args.length === 0 ? AST10.tsNeverKeyword() : AST10.tsTypeLiteral(
|
|
57118
|
-
targetFieldDefinition.args.map((arg) => {
|
|
57119
|
-
const argDef = AST10.tsPropertySignature(
|
|
57120
|
-
AST10.identifier(arg.name),
|
|
57121
|
-
AST10.tsTypeAnnotation(
|
|
57122
|
-
tsTypeReference(
|
|
57123
|
-
config2,
|
|
57124
|
-
/* @__PURE__ */ new Set(),
|
|
57125
|
-
arg
|
|
57126
|
-
)
|
|
57127
|
-
)
|
|
57128
|
-
);
|
|
57129
|
-
argDef.optional = true;
|
|
57130
|
-
return argDef;
|
|
57131
|
-
})
|
|
57132
|
-
)
|
|
57133
|
-
)
|
|
57134
|
-
)
|
|
57135
|
-
])
|
|
57136
|
-
)
|
|
57137
|
-
)
|
|
57138
|
-
);
|
|
57220
|
+
if (config2.scalars?.[target.name]) {
|
|
57221
|
+
return AST7.tsTypeReference(AST7.identifier(config2.scalars?.[target.name].type));
|
|
57139
57222
|
}
|
|
57140
|
-
|
|
57223
|
+
missingScalars.add(target.name);
|
|
57224
|
+
return AST7.tsAnyKeyword();
|
|
57225
|
+
}
|
|
57141
57226
|
}
|
|
57142
|
-
return AST10.tsTypeLiteral(lists);
|
|
57143
57227
|
}
|
|
57144
|
-
|
|
57145
|
-
|
|
57146
|
-
|
|
57147
|
-
|
|
57148
|
-
|
|
57149
|
-
|
|
57150
|
-
|
|
57151
|
-
|
|
57152
|
-
|
|
57228
|
+
|
|
57229
|
+
// src/codegen/generators/typescript/typeReference.ts
|
|
57230
|
+
var AST8 = recast8.types.builders;
|
|
57231
|
+
function tsTypeReference(config2, missingScalars, definition) {
|
|
57232
|
+
const { type, wrappers } = unwrapType(config2, definition.type);
|
|
57233
|
+
let result;
|
|
57234
|
+
if (graphql14.isScalarType(type)) {
|
|
57235
|
+
result = scalarPropertyValue(config2, missingScalars, type);
|
|
57236
|
+
} else {
|
|
57237
|
+
result = AST8.tsTypeReference(AST8.identifier(type.name));
|
|
57238
|
+
}
|
|
57239
|
+
for (const toWrap of wrappers) {
|
|
57240
|
+
if (toWrap === "NonNull" /* NonNull */) {
|
|
57241
|
+
continue;
|
|
57242
|
+
} else if (toWrap === "Nullable" /* Nullable */) {
|
|
57243
|
+
result = nullableField(result, true);
|
|
57244
|
+
} else if (toWrap === "List" /* List */) {
|
|
57245
|
+
result = AST8.tsArrayType(AST8.tsParenthesizedType(result));
|
|
57246
|
+
}
|
|
57247
|
+
}
|
|
57248
|
+
return result;
|
|
57249
|
+
}
|
|
57250
|
+
|
|
57251
|
+
// src/codegen/generators/typescript/addReferencedInputTypes.ts
|
|
57252
|
+
var AST9 = recast9.types.builders;
|
|
57253
|
+
function addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, rootType) {
|
|
57254
|
+
const { type } = unwrapType(config2, rootType);
|
|
57255
|
+
if (graphql15.isScalarType(type)) {
|
|
57256
|
+
return;
|
|
57257
|
+
}
|
|
57258
|
+
if (visitedTypes.has(type.name)) {
|
|
57259
|
+
return;
|
|
57260
|
+
}
|
|
57261
|
+
if (graphql15.isUnionType(type)) {
|
|
57262
|
+
throw new HoudiniError({ filepath, message: "Input Unions are not supported yet. Sorry!" });
|
|
57263
|
+
}
|
|
57264
|
+
visitedTypes.add(type.name);
|
|
57265
|
+
if (graphql15.isEnumType(type)) {
|
|
57266
|
+
ensureImports({
|
|
57267
|
+
config: config2,
|
|
57268
|
+
body,
|
|
57269
|
+
import: [type.name],
|
|
57270
|
+
sourceModule: "$houdini/graphql/enums",
|
|
57271
|
+
importKind: "type"
|
|
57272
|
+
});
|
|
57273
|
+
return;
|
|
57274
|
+
}
|
|
57275
|
+
const members = [];
|
|
57276
|
+
for (const field of Object.values(type.getFields())) {
|
|
57277
|
+
addReferencedInputTypes(config2, filepath, body, visitedTypes, missingScalars, field.type);
|
|
57278
|
+
members.push(
|
|
57279
|
+
AST9.tsPropertySignature(
|
|
57280
|
+
AST9.identifier(field.name),
|
|
57281
|
+
AST9.tsTypeAnnotation(tsTypeReference(config2, missingScalars, field)),
|
|
57282
|
+
graphql15.isNullableType(field.type)
|
|
57283
|
+
)
|
|
57284
|
+
);
|
|
57285
|
+
}
|
|
57286
|
+
body.push(AST9.tsTypeAliasDeclaration(AST9.identifier(type.name), AST9.tsTypeLiteral(members)));
|
|
57153
57287
|
}
|
|
57154
57288
|
|
|
57155
57289
|
// src/codegen/generators/typescript/inlineType.ts
|
|
57156
57290
|
var graphql16 = __toESM(require_graphql2(), 1);
|
|
57157
|
-
var
|
|
57158
|
-
var
|
|
57291
|
+
var recast10 = __toESM(require_main2(), 1);
|
|
57292
|
+
var AST10 = recast10.types.builders;
|
|
57159
57293
|
var fragmentKey = "$fragments";
|
|
57160
57294
|
function inlineType({
|
|
57161
57295
|
config: config2,
|
|
@@ -57184,7 +57318,7 @@ function inlineType({
|
|
|
57184
57318
|
});
|
|
57185
57319
|
visitedTypes.add(type.name);
|
|
57186
57320
|
}
|
|
57187
|
-
result =
|
|
57321
|
+
result = AST10.tsTypeReference(AST10.identifier(type.name));
|
|
57188
57322
|
} else if (selections) {
|
|
57189
57323
|
const rootObj = type;
|
|
57190
57324
|
const inlineFragments = {};
|
|
@@ -57235,7 +57369,7 @@ function inlineType({
|
|
|
57235
57369
|
selectedFields.push(selection2);
|
|
57236
57370
|
}
|
|
57237
57371
|
}
|
|
57238
|
-
result =
|
|
57372
|
+
result = AST10.tsTypeLiteral([
|
|
57239
57373
|
...(selectedFields || []).filter(
|
|
57240
57374
|
(field) => field.kind === "Field"
|
|
57241
57375
|
).map((selection2) => {
|
|
@@ -57255,9 +57389,9 @@ function inlineType({
|
|
|
57255
57389
|
allOptional
|
|
57256
57390
|
});
|
|
57257
57391
|
const prop = readonlyProperty(
|
|
57258
|
-
|
|
57259
|
-
|
|
57260
|
-
|
|
57392
|
+
AST10.tsPropertySignature(
|
|
57393
|
+
AST10.identifier(attributeName),
|
|
57394
|
+
AST10.tsTypeAnnotation(attributeType)
|
|
57261
57395
|
),
|
|
57262
57396
|
allowReadonly
|
|
57263
57397
|
);
|
|
@@ -57271,15 +57405,15 @@ function inlineType({
|
|
|
57271
57405
|
if (includeFragments && fragmentSpreads && fragmentSpreads.length) {
|
|
57272
57406
|
result.members.push(
|
|
57273
57407
|
readonlyProperty(
|
|
57274
|
-
|
|
57275
|
-
|
|
57276
|
-
|
|
57277
|
-
|
|
57408
|
+
AST10.tsPropertySignature(
|
|
57409
|
+
AST10.identifier(fragmentKey),
|
|
57410
|
+
AST10.tsTypeAnnotation(
|
|
57411
|
+
AST10.tsTypeLiteral(
|
|
57278
57412
|
(fragmentSpreads || []).map(
|
|
57279
|
-
(fragmentSpread) =>
|
|
57280
|
-
|
|
57281
|
-
|
|
57282
|
-
|
|
57413
|
+
(fragmentSpread) => AST10.tsPropertySignature(
|
|
57414
|
+
AST10.identifier(fragmentSpread.name.value),
|
|
57415
|
+
AST10.tsTypeAnnotation(
|
|
57416
|
+
AST10.tsLiteralType(AST10.booleanLiteral(true))
|
|
57283
57417
|
)
|
|
57284
57418
|
)
|
|
57285
57419
|
)
|
|
@@ -57325,9 +57459,9 @@ function inlineType({
|
|
|
57325
57459
|
}
|
|
57326
57460
|
objectType.members.push(
|
|
57327
57461
|
readonlyProperty(
|
|
57328
|
-
|
|
57329
|
-
|
|
57330
|
-
|
|
57462
|
+
AST10.tsPropertySignature(
|
|
57463
|
+
AST10.identifier("__typename"),
|
|
57464
|
+
AST10.tsTypeAnnotation(AST10.tsLiteralType(AST10.stringLiteral(typeName)))
|
|
57331
57465
|
),
|
|
57332
57466
|
allowReadonly
|
|
57333
57467
|
)
|
|
@@ -57338,8 +57472,8 @@ function inlineType({
|
|
|
57338
57472
|
if (Object.keys(inlineFragmentSelections).length > 0) {
|
|
57339
57473
|
let selectionTypes = Object.entries(inlineFragmentSelections).map(
|
|
57340
57474
|
([typeName, { type: type2, tsType }]) => {
|
|
57341
|
-
return
|
|
57342
|
-
|
|
57475
|
+
return AST10.tsParenthesizedType(
|
|
57476
|
+
AST10.tsIntersectionType(
|
|
57343
57477
|
[tsType].flatMap((type3) => {
|
|
57344
57478
|
if (type3.type === "TSUnionType") {
|
|
57345
57479
|
return type3.types.filter(
|
|
@@ -57352,9 +57486,9 @@ function inlineType({
|
|
|
57352
57486
|
);
|
|
57353
57487
|
}
|
|
57354
57488
|
);
|
|
57355
|
-
result =
|
|
57489
|
+
result = AST10.tsIntersectionType([
|
|
57356
57490
|
result,
|
|
57357
|
-
|
|
57491
|
+
AST10.tsParenthesizedType(AST10.tsUnionType(selectionTypes))
|
|
57358
57492
|
]);
|
|
57359
57493
|
}
|
|
57360
57494
|
} else {
|
|
@@ -57366,7 +57500,7 @@ function inlineType({
|
|
|
57366
57500
|
} else if (toWrap === "NonNull" /* NonNull */) {
|
|
57367
57501
|
continue;
|
|
57368
57502
|
} else if (toWrap === "List" /* List */) {
|
|
57369
|
-
result =
|
|
57503
|
+
result = AST10.tsArrayType(AST10.tsParenthesizedType(result));
|
|
57370
57504
|
}
|
|
57371
57505
|
}
|
|
57372
57506
|
return result;
|
|
@@ -57410,9 +57544,9 @@ function selectionTypeInfo(schema, filepath, rootType, selection2) {
|
|
|
57410
57544
|
return { field, type: selectionType };
|
|
57411
57545
|
}
|
|
57412
57546
|
|
|
57413
|
-
// src/codegen/generators/typescript/
|
|
57414
|
-
var
|
|
57415
|
-
async function
|
|
57547
|
+
// src/codegen/generators/typescript/documentTypes.ts
|
|
57548
|
+
var AST11 = recast11.types.builders;
|
|
57549
|
+
async function generateDocumentTypes(config2, docs) {
|
|
57416
57550
|
const typePaths = [];
|
|
57417
57551
|
const fragmentDefinitions = {};
|
|
57418
57552
|
for (const document of docs) {
|
|
@@ -57429,7 +57563,7 @@ async function typescriptGenerator(config2, docs) {
|
|
|
57429
57563
|
return;
|
|
57430
57564
|
}
|
|
57431
57565
|
const typeDefPath = config2.artifactTypePath(originalDocument);
|
|
57432
|
-
const program =
|
|
57566
|
+
const program = AST11.program([]);
|
|
57433
57567
|
const visitedTypes = /* @__PURE__ */ new Set();
|
|
57434
57568
|
let definition = originalDocument.definitions.find(
|
|
57435
57569
|
(def) => (def.kind === "OperationDefinition" || def.kind === "FragmentDefinition") && def.name?.value === name2
|
|
@@ -57462,21 +57596,21 @@ async function typescriptGenerator(config2, docs) {
|
|
|
57462
57596
|
missingScalars
|
|
57463
57597
|
);
|
|
57464
57598
|
}
|
|
57465
|
-
await fs_exports.writeFile(typeDefPath,
|
|
57599
|
+
await fs_exports.writeFile(typeDefPath, recast11.print(program).code);
|
|
57466
57600
|
typePaths.push(typeDefPath);
|
|
57467
57601
|
})
|
|
57468
57602
|
);
|
|
57469
|
-
const typeIndex =
|
|
57603
|
+
const typeIndex = AST11.program(
|
|
57470
57604
|
typePaths.sort((a, b) => a.localeCompare(b)).map((typePath) => {
|
|
57471
|
-
return
|
|
57472
|
-
|
|
57605
|
+
return AST11.exportAllDeclaration(
|
|
57606
|
+
AST11.literal(
|
|
57473
57607
|
"./" + path_exports.relative(path_exports.resolve(config2.typeIndexPath, ".."), typePath).replace(/\.[^/.]+\.[^/.]+$/, "")
|
|
57474
57608
|
),
|
|
57475
57609
|
null
|
|
57476
57610
|
);
|
|
57477
57611
|
}).concat([
|
|
57478
|
-
|
|
57479
|
-
|
|
57612
|
+
AST11.exportAllDeclaration(AST11.literal("./runtime"), null),
|
|
57613
|
+
AST11.exportAllDeclaration(AST11.literal("./graphql"), null)
|
|
57480
57614
|
])
|
|
57481
57615
|
);
|
|
57482
57616
|
const export_default_as = ({ module: module2, as }) => `
|
|
@@ -57485,7 +57619,7 @@ export { default as ${as} } from "${module2}"
|
|
|
57485
57619
|
const export_star_from = ({ module: module2 }) => `
|
|
57486
57620
|
export * from "${module2}"
|
|
57487
57621
|
`;
|
|
57488
|
-
let indexContent =
|
|
57622
|
+
let indexContent = recast11.print(typeIndex).code;
|
|
57489
57623
|
for (const plugin of config2.plugins) {
|
|
57490
57624
|
if (!plugin.index_file) {
|
|
57491
57625
|
continue;
|
|
@@ -57506,7 +57640,6 @@ export * from "${module2}"
|
|
|
57506
57640
|
}
|
|
57507
57641
|
}
|
|
57508
57642
|
await fs_exports.writeFile(config2.typeIndexPath, indexContent);
|
|
57509
|
-
await imperativeCacheTypef(config2, docs);
|
|
57510
57643
|
if (missingScalars.size > 0) {
|
|
57511
57644
|
console.warn(`\u26A0\uFE0F Missing definitions for the following scalars: ${[...missingScalars].join(
|
|
57512
57645
|
", "
|
|
@@ -57548,23 +57681,23 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
|
|
|
57548
57681
|
const optimisticTypeName = `${definition.name.value}$optimistic`;
|
|
57549
57682
|
const hasInputs = definition.variableDefinitions && definition.variableDefinitions.length > 0;
|
|
57550
57683
|
body.push(
|
|
57551
|
-
|
|
57552
|
-
|
|
57553
|
-
|
|
57554
|
-
|
|
57684
|
+
AST11.exportNamedDeclaration(
|
|
57685
|
+
AST11.tsTypeAliasDeclaration(
|
|
57686
|
+
AST11.identifier(definition.name.value),
|
|
57687
|
+
AST11.tsTypeLiteral([
|
|
57555
57688
|
readonlyProperty(
|
|
57556
|
-
|
|
57557
|
-
|
|
57558
|
-
|
|
57689
|
+
AST11.tsPropertySignature(
|
|
57690
|
+
AST11.stringLiteral("input"),
|
|
57691
|
+
AST11.tsTypeAnnotation(AST11.tsTypeReference(AST11.identifier(inputTypeName)))
|
|
57559
57692
|
)
|
|
57560
57693
|
),
|
|
57561
57694
|
readonlyProperty(
|
|
57562
|
-
|
|
57563
|
-
|
|
57564
|
-
|
|
57565
|
-
definition.operation === "mutation" ?
|
|
57566
|
-
|
|
57567
|
-
|
|
57695
|
+
AST11.tsPropertySignature(
|
|
57696
|
+
AST11.stringLiteral("result"),
|
|
57697
|
+
AST11.tsTypeAnnotation(
|
|
57698
|
+
definition.operation === "mutation" ? AST11.tsTypeReference(AST11.identifier(shapeTypeName)) : AST11.tsUnionType([
|
|
57699
|
+
AST11.tsTypeReference(AST11.identifier(shapeTypeName)),
|
|
57700
|
+
AST11.tsUndefinedKeyword()
|
|
57568
57701
|
])
|
|
57569
57702
|
)
|
|
57570
57703
|
)
|
|
@@ -57572,9 +57705,9 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
|
|
|
57572
57705
|
])
|
|
57573
57706
|
)
|
|
57574
57707
|
),
|
|
57575
|
-
|
|
57576
|
-
|
|
57577
|
-
|
|
57708
|
+
AST11.exportNamedDeclaration(
|
|
57709
|
+
AST11.tsTypeAliasDeclaration(
|
|
57710
|
+
AST11.identifier(shapeTypeName),
|
|
57578
57711
|
inlineType({
|
|
57579
57712
|
config: config2,
|
|
57580
57713
|
filepath,
|
|
@@ -57602,15 +57735,15 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
|
|
|
57602
57735
|
);
|
|
57603
57736
|
}
|
|
57604
57737
|
body.push(
|
|
57605
|
-
|
|
57606
|
-
|
|
57607
|
-
|
|
57608
|
-
|
|
57738
|
+
AST11.exportNamedDeclaration(
|
|
57739
|
+
AST11.tsTypeAliasDeclaration(
|
|
57740
|
+
AST11.identifier(inputTypeName),
|
|
57741
|
+
AST11.tsTypeLiteral(
|
|
57609
57742
|
(definition.variableDefinitions || []).map(
|
|
57610
57743
|
(definition2) => {
|
|
57611
|
-
return
|
|
57612
|
-
|
|
57613
|
-
|
|
57744
|
+
return AST11.tsPropertySignature(
|
|
57745
|
+
AST11.identifier(definition2.variable.name.value),
|
|
57746
|
+
AST11.tsTypeAnnotation(
|
|
57614
57747
|
tsTypeReference(config2, missingScalars, definition2)
|
|
57615
57748
|
),
|
|
57616
57749
|
definition2.type.kind !== "NonNullType"
|
|
@@ -57623,16 +57756,16 @@ async function generateOperationTypeDefs(config2, filepath, body, definition, se
|
|
|
57623
57756
|
);
|
|
57624
57757
|
} else {
|
|
57625
57758
|
body.push(
|
|
57626
|
-
|
|
57627
|
-
|
|
57759
|
+
AST11.exportNamedDeclaration(
|
|
57760
|
+
AST11.tsTypeAliasDeclaration(AST11.identifier(inputTypeName), AST11.tsNullKeyword())
|
|
57628
57761
|
)
|
|
57629
57762
|
);
|
|
57630
57763
|
}
|
|
57631
57764
|
if (definition.operation === "mutation") {
|
|
57632
57765
|
body.push(
|
|
57633
|
-
|
|
57634
|
-
|
|
57635
|
-
|
|
57766
|
+
AST11.exportNamedDeclaration(
|
|
57767
|
+
AST11.tsTypeAliasDeclaration(
|
|
57768
|
+
AST11.identifier(optimisticTypeName),
|
|
57636
57769
|
inlineType({
|
|
57637
57770
|
config: config2,
|
|
57638
57771
|
filepath,
|
|
@@ -57658,65 +57791,463 @@ async function generateFragmentTypeDefs(config2, filepath, body, selections, def
|
|
|
57658
57791
|
}
|
|
57659
57792
|
const propTypeName = definition.name.value;
|
|
57660
57793
|
const shapeTypeName = `${definition.name.value}$data`;
|
|
57794
|
+
const inputTypeName = `${definition.name.value}$input`;
|
|
57661
57795
|
const type = config2.schema.getType(definition.typeCondition.name.value);
|
|
57662
57796
|
if (!type) {
|
|
57663
57797
|
throw new Error("Should not get here");
|
|
57664
57798
|
}
|
|
57799
|
+
let extraExports = [];
|
|
57800
|
+
let directive = definition.directives?.find(
|
|
57801
|
+
(directive2) => directive2.name.value === config2.argumentsDirective
|
|
57802
|
+
);
|
|
57803
|
+
if (directive) {
|
|
57804
|
+
extraExports.push(
|
|
57805
|
+
AST11.exportNamedDeclaration(
|
|
57806
|
+
AST11.tsTypeAliasDeclaration(
|
|
57807
|
+
AST11.identifier(inputTypeName),
|
|
57808
|
+
AST11.tsTypeLiteral(
|
|
57809
|
+
(fragmentArgumentsDefinitions(config2, filepath, definition) || []).map(
|
|
57810
|
+
(definition2) => {
|
|
57811
|
+
return AST11.tsPropertySignature(
|
|
57812
|
+
AST11.identifier(definition2.variable.name.value),
|
|
57813
|
+
AST11.tsTypeAnnotation(
|
|
57814
|
+
tsTypeReference(config2, missingScalars, definition2)
|
|
57815
|
+
),
|
|
57816
|
+
definition2.type.kind !== "NonNullType"
|
|
57817
|
+
);
|
|
57818
|
+
}
|
|
57819
|
+
)
|
|
57820
|
+
)
|
|
57821
|
+
)
|
|
57822
|
+
)
|
|
57823
|
+
);
|
|
57824
|
+
}
|
|
57665
57825
|
body.push(
|
|
57666
|
-
|
|
57667
|
-
|
|
57668
|
-
|
|
57669
|
-
|
|
57826
|
+
...extraExports,
|
|
57827
|
+
AST11.exportNamedDeclaration(
|
|
57828
|
+
AST11.tsTypeAliasDeclaration(
|
|
57829
|
+
AST11.identifier(propTypeName),
|
|
57830
|
+
AST11.tsTypeLiteral([
|
|
57670
57831
|
readonlyProperty(
|
|
57671
|
-
|
|
57672
|
-
|
|
57673
|
-
|
|
57674
|
-
|
|
57832
|
+
AST11.tsPropertySignature(
|
|
57833
|
+
AST11.stringLiteral("shape"),
|
|
57834
|
+
AST11.tsTypeAnnotation(
|
|
57835
|
+
AST11.tsTypeReference(AST11.identifier(shapeTypeName))
|
|
57675
57836
|
),
|
|
57676
57837
|
true
|
|
57677
57838
|
)
|
|
57678
57839
|
),
|
|
57679
57840
|
readonlyProperty(
|
|
57680
|
-
|
|
57681
|
-
|
|
57841
|
+
AST11.tsPropertySignature(
|
|
57842
|
+
AST11.stringLiteral(fragmentKey),
|
|
57843
|
+
AST11.tsTypeAnnotation(
|
|
57844
|
+
AST11.tsTypeLiteral([
|
|
57845
|
+
AST11.tsPropertySignature(
|
|
57846
|
+
AST11.stringLiteral(propTypeName),
|
|
57847
|
+
AST11.tsTypeAnnotation(
|
|
57848
|
+
AST11.tsLiteralType(AST11.booleanLiteral(true))
|
|
57849
|
+
)
|
|
57850
|
+
)
|
|
57851
|
+
])
|
|
57852
|
+
)
|
|
57853
|
+
)
|
|
57854
|
+
)
|
|
57855
|
+
])
|
|
57856
|
+
)
|
|
57857
|
+
),
|
|
57858
|
+
AST11.exportNamedDeclaration(
|
|
57859
|
+
AST11.tsTypeAliasDeclaration(
|
|
57860
|
+
AST11.identifier(shapeTypeName),
|
|
57861
|
+
inlineType({
|
|
57862
|
+
config: config2,
|
|
57863
|
+
filepath,
|
|
57864
|
+
rootType: type,
|
|
57865
|
+
selections,
|
|
57866
|
+
root: true,
|
|
57867
|
+
allowReadonly: true,
|
|
57868
|
+
body,
|
|
57869
|
+
visitedTypes,
|
|
57870
|
+
missingScalars,
|
|
57871
|
+
includeFragments: true
|
|
57872
|
+
})
|
|
57873
|
+
)
|
|
57874
|
+
)
|
|
57875
|
+
);
|
|
57876
|
+
}
|
|
57877
|
+
}
|
|
57878
|
+
|
|
57879
|
+
// src/codegen/generators/typescript/imperativeTypeDef.ts
|
|
57880
|
+
var graphql17 = __toESM(require_graphql2(), 1);
|
|
57881
|
+
var recast12 = __toESM(require_main2(), 1);
|
|
57882
|
+
var AST12 = recast12.types.builders;
|
|
57883
|
+
async function imperativeCacheTypef(config2, docs) {
|
|
57884
|
+
const returnType = (doc) => config2.plugins.find((plugin) => plugin.graphql_tag_return)?.graphql_tag_return?.({
|
|
57885
|
+
config: config2,
|
|
57886
|
+
doc,
|
|
57887
|
+
ensure_import({ identifier, module: module2 }) {
|
|
57888
|
+
ensureImports({
|
|
57889
|
+
config: config2,
|
|
57890
|
+
body,
|
|
57891
|
+
sourceModule: module2,
|
|
57892
|
+
import: [identifier]
|
|
57893
|
+
});
|
|
57894
|
+
}
|
|
57895
|
+
}) ?? "any";
|
|
57896
|
+
const target = path_exports.join(config2.runtimeDirectory, "generated.d.ts");
|
|
57897
|
+
const body = [];
|
|
57898
|
+
const declaration = AST12.tsTypeAliasDeclaration(
|
|
57899
|
+
AST12.identifier(CacheTypeDefName),
|
|
57900
|
+
AST12.tsTypeLiteral([
|
|
57901
|
+
AST12.tsPropertySignature(
|
|
57902
|
+
AST12.identifier("types"),
|
|
57903
|
+
AST12.tsTypeAnnotation(typeDefinitions(config2, body, docs, returnType))
|
|
57904
|
+
),
|
|
57905
|
+
AST12.tsPropertySignature(
|
|
57906
|
+
AST12.identifier("lists"),
|
|
57907
|
+
AST12.tsTypeAnnotation(listDefinitions(config2, docs))
|
|
57908
|
+
),
|
|
57909
|
+
AST12.tsPropertySignature(
|
|
57910
|
+
AST12.identifier("queries"),
|
|
57911
|
+
AST12.tsTypeAnnotation(queryDefinitions(config2, body, docs, returnType))
|
|
57912
|
+
)
|
|
57913
|
+
])
|
|
57914
|
+
);
|
|
57915
|
+
declaration.declare = true;
|
|
57916
|
+
const importRecord = AST12.importDeclaration(
|
|
57917
|
+
[AST12.importSpecifier(AST12.identifier("Record"))],
|
|
57918
|
+
AST12.stringLiteral("./public/record")
|
|
57919
|
+
);
|
|
57920
|
+
importRecord.importKind = "type";
|
|
57921
|
+
await fs_exports.writeFile(
|
|
57922
|
+
target,
|
|
57923
|
+
recast12.prettyPrint(
|
|
57924
|
+
AST12.program([importRecord, ...body, AST12.exportNamedDeclaration(declaration)])
|
|
57925
|
+
).code
|
|
57926
|
+
);
|
|
57927
|
+
}
|
|
57928
|
+
function typeDefinitions(config2, body, docs, returnType) {
|
|
57929
|
+
const operationTypes = [config2.schema.getMutationType(), config2.schema.getSubscriptionType()].filter(Boolean).map((type) => type?.name);
|
|
57930
|
+
const visitedTypes = /* @__PURE__ */ new Set();
|
|
57931
|
+
const types14 = Object.values(config2.schema.getTypeMap()).filter(
|
|
57932
|
+
(type) => !graphql17.isAbstractType(type) && !graphql17.isScalarType(type) && !graphql17.isEnumType(type) && !graphql17.isInputObjectType(type) && !type.name.startsWith("__") && !operationTypes.includes(type.name)
|
|
57933
|
+
);
|
|
57934
|
+
const fragmentMap = fragmentListMap(
|
|
57935
|
+
config2,
|
|
57936
|
+
types14.map((type) => type.name),
|
|
57937
|
+
body,
|
|
57938
|
+
docs,
|
|
57939
|
+
returnType
|
|
57940
|
+
);
|
|
57941
|
+
return AST12.tsTypeLiteral(
|
|
57942
|
+
types14.map((type) => {
|
|
57943
|
+
let typeName = type.name;
|
|
57944
|
+
if (config2.schema.getQueryType() && config2.schema.getQueryType()?.name === type.name) {
|
|
57945
|
+
typeName = "__ROOT__";
|
|
57946
|
+
}
|
|
57947
|
+
let idFields = AST12.tsNeverKeyword();
|
|
57948
|
+
const keys = keyFieldsForType(config2.configFile, type.name);
|
|
57949
|
+
if (graphql17.isObjectType(type) && keys.length > 0 && keys.every((key) => type.getFields()[key])) {
|
|
57950
|
+
idFields = AST12.tsTypeLiteral(
|
|
57951
|
+
keys.map((key) => {
|
|
57952
|
+
const fieldType = type.getFields()[key];
|
|
57953
|
+
const unwrapped = unwrapType(config2, fieldType.type);
|
|
57954
|
+
return AST12.tsPropertySignature(
|
|
57955
|
+
AST12.identifier(key),
|
|
57956
|
+
AST12.tsTypeAnnotation(
|
|
57957
|
+
scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
|
|
57958
|
+
)
|
|
57959
|
+
);
|
|
57960
|
+
})
|
|
57961
|
+
);
|
|
57962
|
+
} else if (typeName === "__ROOT__") {
|
|
57963
|
+
idFields = AST12.tsTypeLiteral([]);
|
|
57964
|
+
}
|
|
57965
|
+
let fields = AST12.tsTypeLiteral([]);
|
|
57966
|
+
if (graphql17.isObjectType(type)) {
|
|
57967
|
+
fields = AST12.tsTypeLiteral(
|
|
57968
|
+
Object.entries(type.getFields()).map(
|
|
57969
|
+
([key, fieldType]) => {
|
|
57970
|
+
const unwrapped = unwrapType(config2, fieldType.type);
|
|
57971
|
+
let typeOptions = AST12.tsUnionType([]);
|
|
57972
|
+
if (graphql17.isScalarType(unwrapped.type)) {
|
|
57973
|
+
typeOptions.types.push(
|
|
57974
|
+
scalarPropertyValue(config2, /* @__PURE__ */ new Set(), unwrapped.type)
|
|
57975
|
+
);
|
|
57976
|
+
} else if (graphql17.isEnumType(unwrapped.type)) {
|
|
57977
|
+
typeOptions.types.push(
|
|
57978
|
+
AST12.tsTypeReference(AST12.identifier(unwrapped.type.name))
|
|
57979
|
+
);
|
|
57980
|
+
} else if (!graphql17.isAbstractType(unwrapped.type)) {
|
|
57981
|
+
typeOptions.types.push(record(unwrapped.type.name));
|
|
57982
|
+
} else {
|
|
57983
|
+
typeOptions.types.push(
|
|
57984
|
+
...config2.schema.getPossibleTypes(unwrapped.type).map((type2) => record(type2.name))
|
|
57985
|
+
);
|
|
57986
|
+
}
|
|
57987
|
+
for (const wrapper of unwrapped.wrappers) {
|
|
57988
|
+
if (wrapper === "Nullable" /* Nullable */) {
|
|
57989
|
+
typeOptions = AST12.tsParenthesizedType(
|
|
57990
|
+
AST12.tsUnionType([typeOptions, AST12.tsNullKeyword()])
|
|
57991
|
+
);
|
|
57992
|
+
} else if (wrapper === "List" /* List */) {
|
|
57993
|
+
typeOptions = AST12.tsArrayType(
|
|
57994
|
+
AST12.tsParenthesizedType(typeOptions)
|
|
57995
|
+
);
|
|
57996
|
+
}
|
|
57997
|
+
}
|
|
57998
|
+
if (typeOptions.type === "TSParenthesizedType") {
|
|
57999
|
+
typeOptions = typeOptions.typeAnnotation;
|
|
58000
|
+
}
|
|
58001
|
+
let args = AST12.tsNeverKeyword();
|
|
58002
|
+
if (fieldType.args?.length > 0) {
|
|
58003
|
+
args = AST12.tsTypeLiteral(
|
|
58004
|
+
fieldType.args.map((arg) => {
|
|
58005
|
+
addReferencedInputTypes(
|
|
58006
|
+
config2,
|
|
58007
|
+
"",
|
|
58008
|
+
body,
|
|
58009
|
+
visitedTypes,
|
|
58010
|
+
/* @__PURE__ */ new Set(),
|
|
58011
|
+
arg.type
|
|
58012
|
+
);
|
|
58013
|
+
const prop = AST12.tsPropertySignature(
|
|
58014
|
+
AST12.identifier(arg.name),
|
|
58015
|
+
AST12.tsTypeAnnotation(
|
|
58016
|
+
tsTypeReference(config2, /* @__PURE__ */ new Set(), arg)
|
|
58017
|
+
)
|
|
58018
|
+
);
|
|
58019
|
+
const unwrapped2 = unwrapType(config2, arg.type);
|
|
58020
|
+
prop.optional = unwrapped2.wrappers[unwrapped2.wrappers.length - 1] === "Nullable" /* Nullable */;
|
|
58021
|
+
return prop;
|
|
58022
|
+
})
|
|
58023
|
+
);
|
|
58024
|
+
}
|
|
58025
|
+
return AST12.tsPropertySignature(
|
|
58026
|
+
AST12.identifier(key),
|
|
57682
58027
|
AST12.tsTypeAnnotation(
|
|
57683
58028
|
AST12.tsTypeLiteral([
|
|
57684
58029
|
AST12.tsPropertySignature(
|
|
57685
|
-
AST12.
|
|
57686
|
-
AST12.tsTypeAnnotation(
|
|
57687
|
-
|
|
57688
|
-
|
|
58030
|
+
AST12.identifier("type"),
|
|
58031
|
+
AST12.tsTypeAnnotation(typeOptions)
|
|
58032
|
+
),
|
|
58033
|
+
AST12.tsPropertySignature(
|
|
58034
|
+
AST12.identifier("args"),
|
|
58035
|
+
AST12.tsTypeAnnotation(args)
|
|
57689
58036
|
)
|
|
57690
58037
|
])
|
|
57691
58038
|
)
|
|
57692
|
-
)
|
|
58039
|
+
);
|
|
58040
|
+
}
|
|
58041
|
+
)
|
|
58042
|
+
);
|
|
58043
|
+
}
|
|
58044
|
+
return AST12.tsPropertySignature(
|
|
58045
|
+
AST12.identifier(typeName),
|
|
58046
|
+
AST12.tsTypeAnnotation(
|
|
58047
|
+
AST12.tsTypeLiteral([
|
|
58048
|
+
AST12.tsPropertySignature(
|
|
58049
|
+
AST12.identifier("idFields"),
|
|
58050
|
+
AST12.tsTypeAnnotation(idFields)
|
|
58051
|
+
),
|
|
58052
|
+
AST12.tsPropertySignature(
|
|
58053
|
+
AST12.identifier("fields"),
|
|
58054
|
+
AST12.tsTypeAnnotation(fields)
|
|
58055
|
+
),
|
|
58056
|
+
AST12.tsPropertySignature(
|
|
58057
|
+
AST12.identifier("fragments"),
|
|
58058
|
+
AST12.tsTypeAnnotation(fragmentMap[typeName] ?? AST12.tsTupleType([]))
|
|
57693
58059
|
)
|
|
57694
58060
|
])
|
|
57695
58061
|
)
|
|
58062
|
+
);
|
|
58063
|
+
})
|
|
58064
|
+
);
|
|
58065
|
+
}
|
|
58066
|
+
function listDefinitions(config2, docs) {
|
|
58067
|
+
const lists = [];
|
|
58068
|
+
const visitedLists = /* @__PURE__ */ new Set();
|
|
58069
|
+
for (const doc of docs) {
|
|
58070
|
+
graphql17.visit(doc.document, {
|
|
58071
|
+
Directive(node, key, parent, path2, ancestors) {
|
|
58072
|
+
if (![config2.listDirective, config2.paginateDirective].includes(node.name.value)) {
|
|
58073
|
+
return;
|
|
58074
|
+
}
|
|
58075
|
+
const nameArg = node.arguments?.find((arg) => arg.name.value === "name");
|
|
58076
|
+
const nameValue = nameArg?.value?.value || "";
|
|
58077
|
+
if (!nameValue || visitedLists.has(nameValue)) {
|
|
58078
|
+
return;
|
|
58079
|
+
}
|
|
58080
|
+
visitedLists.add(nameValue);
|
|
58081
|
+
const parentType = parentTypeFromAncestors(
|
|
58082
|
+
config2.schema,
|
|
58083
|
+
doc.filename,
|
|
58084
|
+
ancestors.slice(0, -1)
|
|
58085
|
+
);
|
|
58086
|
+
const targetField = ancestors[ancestors.length - 1];
|
|
58087
|
+
const targetFieldDefinition = parentType.getFields()[targetField.name.value];
|
|
58088
|
+
const { type: listType } = unwrapType(config2, targetFieldDefinition.type);
|
|
58089
|
+
const possibleTypes = [];
|
|
58090
|
+
if (graphql17.isAbstractType(listType)) {
|
|
58091
|
+
possibleTypes.push(
|
|
58092
|
+
...config2.schema.getPossibleTypes(listType).map((possible) => possible.name)
|
|
58093
|
+
);
|
|
58094
|
+
} else {
|
|
58095
|
+
possibleTypes.push(listType.name);
|
|
58096
|
+
}
|
|
58097
|
+
lists.push(
|
|
58098
|
+
AST12.tsPropertySignature(
|
|
58099
|
+
AST12.identifier(nameValue),
|
|
58100
|
+
AST12.tsTypeAnnotation(
|
|
58101
|
+
AST12.tsTypeLiteral([
|
|
58102
|
+
AST12.tsPropertySignature(
|
|
58103
|
+
AST12.identifier("types"),
|
|
58104
|
+
AST12.tsTypeAnnotation(
|
|
58105
|
+
AST12.tsUnionType(
|
|
58106
|
+
possibleTypes.map(
|
|
58107
|
+
(possible) => AST12.tsLiteralType(AST12.stringLiteral(possible))
|
|
58108
|
+
)
|
|
58109
|
+
)
|
|
58110
|
+
)
|
|
58111
|
+
),
|
|
58112
|
+
AST12.tsPropertySignature(
|
|
58113
|
+
AST12.identifier("filters"),
|
|
58114
|
+
AST12.tsTypeAnnotation(
|
|
58115
|
+
targetFieldDefinition.args.length === 0 ? AST12.tsNeverKeyword() : AST12.tsTypeLiteral(
|
|
58116
|
+
targetFieldDefinition.args.map((arg) => {
|
|
58117
|
+
const argDef = AST12.tsPropertySignature(
|
|
58118
|
+
AST12.identifier(arg.name),
|
|
58119
|
+
AST12.tsTypeAnnotation(
|
|
58120
|
+
tsTypeReference(
|
|
58121
|
+
config2,
|
|
58122
|
+
/* @__PURE__ */ new Set(),
|
|
58123
|
+
arg
|
|
58124
|
+
)
|
|
58125
|
+
)
|
|
58126
|
+
);
|
|
58127
|
+
argDef.optional = true;
|
|
58128
|
+
return argDef;
|
|
58129
|
+
})
|
|
58130
|
+
)
|
|
58131
|
+
)
|
|
58132
|
+
)
|
|
58133
|
+
])
|
|
58134
|
+
)
|
|
58135
|
+
)
|
|
58136
|
+
);
|
|
58137
|
+
}
|
|
58138
|
+
});
|
|
58139
|
+
}
|
|
58140
|
+
return AST12.tsTypeLiteral(lists);
|
|
58141
|
+
}
|
|
58142
|
+
function queryDefinitions(config2, body, docs, returnType) {
|
|
58143
|
+
return AST12.tsTupleType(
|
|
58144
|
+
docs.reduce((prev, doc) => {
|
|
58145
|
+
if (doc.kind !== "HoudiniQuery" /* Query */ || !doc.generateStore) {
|
|
58146
|
+
return prev;
|
|
58147
|
+
}
|
|
58148
|
+
const definition = doc.document.definitions.find(
|
|
58149
|
+
(def) => def.kind === "OperationDefinition" && def.operation === "query"
|
|
58150
|
+
);
|
|
58151
|
+
if (!definition) {
|
|
58152
|
+
return prev;
|
|
58153
|
+
}
|
|
58154
|
+
const runtimeType = returnType(doc);
|
|
58155
|
+
const [shapeType, inputType] = ensureImports({
|
|
58156
|
+
config: config2,
|
|
58157
|
+
body,
|
|
58158
|
+
sourceModule: path_exports.relative(
|
|
58159
|
+
config2.runtimeDirectory,
|
|
58160
|
+
config2.artifactImportPath(doc.name)
|
|
58161
|
+
),
|
|
58162
|
+
import: [`${doc.name}$result`, `${doc.name}$input`]
|
|
58163
|
+
});
|
|
58164
|
+
return prev.concat(
|
|
58165
|
+
AST12.tsTupleType([
|
|
58166
|
+
AST12.tsTypeReference(AST12.identifier(runtimeType)),
|
|
58167
|
+
AST12.tsTypeReference(AST12.identifier(shapeType)),
|
|
58168
|
+
AST12.tsTypeReference(AST12.identifier(inputType))
|
|
58169
|
+
])
|
|
58170
|
+
);
|
|
58171
|
+
}, [])
|
|
58172
|
+
);
|
|
58173
|
+
}
|
|
58174
|
+
function fragmentListMap(config2, concreteTypes, body, docs, return_type) {
|
|
58175
|
+
return docs.reduce((prev, doc) => {
|
|
58176
|
+
if (doc.kind !== "HoudiniFragment" /* Fragment */) {
|
|
58177
|
+
return prev;
|
|
58178
|
+
}
|
|
58179
|
+
const definition = doc.document.definitions.find(
|
|
58180
|
+
(def) => def.kind === "FragmentDefinition" && def.name.value === doc.name
|
|
58181
|
+
);
|
|
58182
|
+
if (!definition || !concreteTypes.includes(definition.typeCondition.name.value)) {
|
|
58183
|
+
return prev;
|
|
58184
|
+
}
|
|
58185
|
+
const typeName = definition.typeCondition.name.value;
|
|
58186
|
+
const previousValue = prev[typeName]?.elementTypes ?? [];
|
|
58187
|
+
const tagResult = return_type(doc);
|
|
58188
|
+
const [shapeType] = ensureImports({
|
|
58189
|
+
config: config2,
|
|
58190
|
+
body,
|
|
58191
|
+
sourceModule: path_exports.relative(
|
|
58192
|
+
config2.runtimeDirectory,
|
|
58193
|
+
config2.artifactImportPath(doc.name)
|
|
57696
58194
|
),
|
|
57697
|
-
|
|
57698
|
-
|
|
57699
|
-
|
|
57700
|
-
|
|
58195
|
+
import: [`${definition.name.value}$data`]
|
|
58196
|
+
});
|
|
58197
|
+
let inputType = AST12.tsNeverKeyword();
|
|
58198
|
+
let directive = definition.directives?.find(
|
|
58199
|
+
(directive2) => directive2.name.value === config2.argumentsDirective
|
|
58200
|
+
);
|
|
58201
|
+
if (directive) {
|
|
58202
|
+
inputType = AST12.tsTypeReference(
|
|
58203
|
+
AST12.identifier(
|
|
58204
|
+
ensureImports({
|
|
57701
58205
|
config: config2,
|
|
57702
|
-
filepath,
|
|
57703
|
-
rootType: type,
|
|
57704
|
-
selections,
|
|
57705
|
-
root: true,
|
|
57706
|
-
allowReadonly: true,
|
|
57707
58206
|
body,
|
|
57708
|
-
|
|
57709
|
-
|
|
57710
|
-
|
|
57711
|
-
|
|
58207
|
+
sourceModule: path_exports.relative(
|
|
58208
|
+
config2.runtimeDirectory,
|
|
58209
|
+
config2.artifactImportPath(doc.name)
|
|
58210
|
+
),
|
|
58211
|
+
import: [`${definition.name.value}$input`]
|
|
58212
|
+
})[0]
|
|
58213
|
+
)
|
|
58214
|
+
);
|
|
58215
|
+
}
|
|
58216
|
+
return {
|
|
58217
|
+
...prev,
|
|
58218
|
+
[typeName]: AST12.tsTupleType(
|
|
58219
|
+
previousValue.concat(
|
|
58220
|
+
AST12.tsTupleType([
|
|
58221
|
+
AST12.tsTypeReference(AST12.identifier(tagResult)),
|
|
58222
|
+
AST12.tsTypeReference(AST12.identifier(shapeType)),
|
|
58223
|
+
inputType
|
|
58224
|
+
])
|
|
57712
58225
|
)
|
|
57713
58226
|
)
|
|
57714
|
-
|
|
57715
|
-
}
|
|
58227
|
+
};
|
|
58228
|
+
}, {});
|
|
58229
|
+
}
|
|
58230
|
+
var CacheTypeDefName = "CacheTypeDef";
|
|
58231
|
+
function record(name2) {
|
|
58232
|
+
return AST12.tsTypeReference(
|
|
58233
|
+
AST12.identifier("Record"),
|
|
58234
|
+
AST12.tsTypeParameterInstantiation([
|
|
58235
|
+
AST12.tsTypeReference(AST12.identifier(CacheTypeDefName)),
|
|
58236
|
+
AST12.tsLiteralType(AST12.stringLiteral(name2))
|
|
58237
|
+
])
|
|
58238
|
+
);
|
|
58239
|
+
}
|
|
58240
|
+
|
|
58241
|
+
// src/codegen/generators/typescript/index.ts
|
|
58242
|
+
async function typescriptGenerator(config2, docs) {
|
|
58243
|
+
await Promise.all([
|
|
58244
|
+
generateDocumentTypes(config2, docs),
|
|
58245
|
+
imperativeCacheTypef(config2, docs)
|
|
58246
|
+
]);
|
|
57716
58247
|
}
|
|
57717
58248
|
|
|
57718
58249
|
// src/codegen/generators/persistedQueries/index.ts
|
|
57719
|
-
var
|
|
58250
|
+
var graphql18 = __toESM(require_graphql2(), 1);
|
|
57720
58251
|
async function persistOutputGenerator(config2, docs) {
|
|
57721
58252
|
if (typeof config2.persistedQueryPath !== "string" || config2.persistedQueryPath.length === 0)
|
|
57722
58253
|
return;
|
|
@@ -57728,8 +58259,8 @@ async function persistOutputGenerator(config2, docs) {
|
|
|
57728
58259
|
if (!generateArtifact) {
|
|
57729
58260
|
return acc;
|
|
57730
58261
|
}
|
|
57731
|
-
let rawString =
|
|
57732
|
-
|
|
58262
|
+
let rawString = graphql18.print(
|
|
58263
|
+
graphql18.visit(document, {
|
|
57733
58264
|
Directive(node) {
|
|
57734
58265
|
if (config2.isInternalDirective(node)) {
|
|
57735
58266
|
return null;
|
|
@@ -57738,7 +58269,7 @@ async function persistOutputGenerator(config2, docs) {
|
|
|
57738
58269
|
})
|
|
57739
58270
|
);
|
|
57740
58271
|
const operations = document.definitions.filter(
|
|
57741
|
-
({ kind }) => kind ===
|
|
58272
|
+
({ kind }) => kind === graphql18.Kind.OPERATION_DEFINITION
|
|
57742
58273
|
);
|
|
57743
58274
|
if (operations.length > 0 && operations[0].kind === "OperationDefinition") {
|
|
57744
58275
|
acc[hashDocument(rawString)] = rawString;
|
|
@@ -57751,11 +58282,11 @@ async function persistOutputGenerator(config2, docs) {
|
|
|
57751
58282
|
}
|
|
57752
58283
|
|
|
57753
58284
|
// src/codegen/generators/definitions/enums.ts
|
|
57754
|
-
var
|
|
58285
|
+
var graphql19 = __toESM(require_graphql2(), 1);
|
|
57755
58286
|
var recast13 = __toESM(require_main2(), 1);
|
|
57756
58287
|
var AST13 = recast13.types.builders;
|
|
57757
58288
|
async function definitionsGenerator(config2) {
|
|
57758
|
-
const enums =
|
|
58289
|
+
const enums = graphql19.parse(graphql19.printSchema(config2.schema)).definitions.filter(
|
|
57759
58290
|
(definition) => definition.kind === "EnumTypeDefinition"
|
|
57760
58291
|
).filter((def) => !config2.isInternalEnum(def));
|
|
57761
58292
|
const runtimeDefinitions = recast13.print(
|
|
@@ -57845,91 +58376,8 @@ async function writeIndexFile2(config2, docs) {
|
|
|
57845
58376
|
await fs_exports.writeFile(path_exports.join(config2.rootDir, "index.js"), body);
|
|
57846
58377
|
}
|
|
57847
58378
|
|
|
57848
|
-
// src/codegen/transforms/composeQueries.ts
|
|
57849
|
-
var import_graphql = __toESM(require_graphql2(), 1);
|
|
57850
|
-
async function includeFragmentDefinitions(config2, documents) {
|
|
57851
|
-
const fragments = collectFragments(config2, documents);
|
|
57852
|
-
for (const [index, { name: name2, document, filename }] of documents.entries()) {
|
|
57853
|
-
const operation = document.definitions.find(
|
|
57854
|
-
({ kind }) => kind === import_graphql.Kind.OPERATION_DEFINITION
|
|
57855
|
-
);
|
|
57856
|
-
if (!operation) {
|
|
57857
|
-
continue;
|
|
57858
|
-
}
|
|
57859
|
-
const allFragments = flattenFragments(
|
|
57860
|
-
filename,
|
|
57861
|
-
{ requiredFragments: findRequiredFragments(operation.selectionSet) },
|
|
57862
|
-
fragments
|
|
57863
|
-
);
|
|
57864
|
-
documents[index].document = {
|
|
57865
|
-
...document,
|
|
57866
|
-
definitions: [
|
|
57867
|
-
operation,
|
|
57868
|
-
...allFragments.map((fragmentName) => fragments[fragmentName].definition)
|
|
57869
|
-
]
|
|
57870
|
-
};
|
|
57871
|
-
}
|
|
57872
|
-
}
|
|
57873
|
-
function collectFragments(config2, docs) {
|
|
57874
|
-
return docs.reduce((acc, doc) => {
|
|
57875
|
-
const definitions = doc.document.definitions.reduce(
|
|
57876
|
-
(prev, definition) => definition.kind !== "FragmentDefinition" ? prev : {
|
|
57877
|
-
...prev,
|
|
57878
|
-
[definition.name.value]: {
|
|
57879
|
-
definition,
|
|
57880
|
-
requiredFragments: findRequiredFragments(definition.selectionSet),
|
|
57881
|
-
document: doc
|
|
57882
|
-
}
|
|
57883
|
-
},
|
|
57884
|
-
{}
|
|
57885
|
-
);
|
|
57886
|
-
return {
|
|
57887
|
-
...acc,
|
|
57888
|
-
...definitions
|
|
57889
|
-
};
|
|
57890
|
-
}, {});
|
|
57891
|
-
}
|
|
57892
|
-
function findRequiredFragments(selectionSet) {
|
|
57893
|
-
if (selectionSet.selections.length === 0) {
|
|
57894
|
-
return [];
|
|
57895
|
-
}
|
|
57896
|
-
const referencedFragments = [];
|
|
57897
|
-
for (const selection2 of selectionSet.selections) {
|
|
57898
|
-
if (selection2.kind === import_graphql.Kind.FRAGMENT_SPREAD) {
|
|
57899
|
-
referencedFragments.push(selection2.name.value);
|
|
57900
|
-
} else if (selection2.selectionSet) {
|
|
57901
|
-
referencedFragments.push(...findRequiredFragments(selection2.selectionSet));
|
|
57902
|
-
}
|
|
57903
|
-
}
|
|
57904
|
-
return referencedFragments;
|
|
57905
|
-
}
|
|
57906
|
-
function flattenFragments(filepath, operation, fragments) {
|
|
57907
|
-
const frags = /* @__PURE__ */ new Set();
|
|
57908
|
-
const remaining = [...operation.requiredFragments];
|
|
57909
|
-
while (remaining.length > 0) {
|
|
57910
|
-
const nextFragment = remaining.shift();
|
|
57911
|
-
if (!nextFragment) {
|
|
57912
|
-
continue;
|
|
57913
|
-
}
|
|
57914
|
-
if (!frags.has(nextFragment)) {
|
|
57915
|
-
frags.add(nextFragment);
|
|
57916
|
-
} else {
|
|
57917
|
-
continue;
|
|
57918
|
-
}
|
|
57919
|
-
const targetFragment = fragments[nextFragment];
|
|
57920
|
-
if (!targetFragment) {
|
|
57921
|
-
throw new HoudiniError({
|
|
57922
|
-
filepath,
|
|
57923
|
-
message: "compose: could not find definition for fragment " + nextFragment
|
|
57924
|
-
});
|
|
57925
|
-
}
|
|
57926
|
-
remaining.push(...targetFragment.requiredFragments);
|
|
57927
|
-
}
|
|
57928
|
-
return [...frags];
|
|
57929
|
-
}
|
|
57930
|
-
|
|
57931
58379
|
// src/codegen/transforms/schema.ts
|
|
57932
|
-
var
|
|
58380
|
+
var graphql20 = __toESM(require_graphql2(), 1);
|
|
57933
58381
|
async function graphqlExtensions(config2, documents) {
|
|
57934
58382
|
const internalSchema = `
|
|
57935
58383
|
enum CachePolicy {
|
|
@@ -57993,9 +58441,9 @@ directive @${config2.argumentsDirective} on FRAGMENT_DEFINITION
|
|
|
57993
58441
|
directive @${config2.cacheDirective}(${config2.cachePolicyArg}: CachePolicy, ${config2.cachePartialArg}: Boolean) on QUERY
|
|
57994
58442
|
|
|
57995
58443
|
"""
|
|
57996
|
-
@${config2.
|
|
58444
|
+
@${config2.loadDirective} is used to disable automatic fetch (no load, no auto fetch in component), you will have to do it manually.
|
|
57997
58445
|
"""
|
|
57998
|
-
directive @${config2.
|
|
58446
|
+
directive @${config2.loadDirective} on QUERY
|
|
57999
58447
|
|
|
58000
58448
|
"""
|
|
58001
58449
|
@${config2.maskEnableDirective} to enable masking on fragment (overwriting the global conf)
|
|
@@ -58007,19 +58455,19 @@ directive @${config2.maskEnableDirective} on FRAGMENT_SPREAD
|
|
|
58007
58455
|
"""
|
|
58008
58456
|
directive @${config2.maskDisableDirective} on FRAGMENT_SPREAD
|
|
58009
58457
|
`;
|
|
58010
|
-
let currentSchema =
|
|
58458
|
+
let currentSchema = graphql20.printSchema(config2.schema);
|
|
58011
58459
|
if (!currentSchema.includes(`directive @${config2.listDirective}`)) {
|
|
58012
58460
|
currentSchema += internalSchema;
|
|
58013
58461
|
}
|
|
58014
58462
|
config2.newSchema += internalSchema;
|
|
58015
|
-
config2.schema =
|
|
58463
|
+
config2.schema = graphql20.buildSchema(currentSchema);
|
|
58016
58464
|
}
|
|
58017
58465
|
|
|
58018
58466
|
// src/codegen/transforms/typename.ts
|
|
58019
|
-
var
|
|
58467
|
+
var graphql21 = __toESM(require_graphql2(), 1);
|
|
58020
58468
|
async function addTypename(config2, documents) {
|
|
58021
58469
|
for (const doc of documents) {
|
|
58022
|
-
doc.document =
|
|
58470
|
+
doc.document = graphql21.visit(doc.document, {
|
|
58023
58471
|
Field(node, key, parent, path2, ancestors) {
|
|
58024
58472
|
if (!node.selectionSet) {
|
|
58025
58473
|
return;
|
|
@@ -58031,7 +58479,7 @@ async function addTypename(config2, documents) {
|
|
|
58031
58479
|
);
|
|
58032
58480
|
const field = type.getFields()[node.name.value];
|
|
58033
58481
|
const fieldType = unwrapType(config2, field.type).type;
|
|
58034
|
-
if (
|
|
58482
|
+
if (graphql21.isInterfaceType(fieldType) || graphql21.isUnionType(fieldType)) {
|
|
58035
58483
|
return {
|
|
58036
58484
|
...node,
|
|
58037
58485
|
selectionSet: {
|
|
@@ -58039,9 +58487,9 @@ async function addTypename(config2, documents) {
|
|
|
58039
58487
|
selections: [
|
|
58040
58488
|
...node.selectionSet.selections,
|
|
58041
58489
|
{
|
|
58042
|
-
kind:
|
|
58490
|
+
kind: graphql21.Kind.FIELD,
|
|
58043
58491
|
name: {
|
|
58044
|
-
kind:
|
|
58492
|
+
kind: graphql21.Kind.NAME,
|
|
58045
58493
|
value: "__typename"
|
|
58046
58494
|
}
|
|
58047
58495
|
}
|
|
@@ -58055,10 +58503,10 @@ async function addTypename(config2, documents) {
|
|
|
58055
58503
|
}
|
|
58056
58504
|
|
|
58057
58505
|
// src/codegen/transforms/addID.ts
|
|
58058
|
-
var
|
|
58506
|
+
var graphql22 = __toESM(require_graphql2(), 1);
|
|
58059
58507
|
async function addID(config2, documents) {
|
|
58060
58508
|
for (const doc of documents) {
|
|
58061
|
-
doc.document =
|
|
58509
|
+
doc.document = graphql22.visit(doc.document, {
|
|
58062
58510
|
Field(node, key, parent, path2, ancestors) {
|
|
58063
58511
|
if (!node.selectionSet) {
|
|
58064
58512
|
return;
|
|
@@ -58071,7 +58519,7 @@ async function addID(config2, documents) {
|
|
|
58071
58519
|
const field = type.getFields()[node.name.value];
|
|
58072
58520
|
const fieldType = unwrapType(config2, field.type).type;
|
|
58073
58521
|
if (node.selectionSet?.selections.length > 0) {
|
|
58074
|
-
if (!
|
|
58522
|
+
if (!graphql22.isObjectType(fieldType) && !graphql22.isInterfaceType(fieldType)) {
|
|
58075
58523
|
return;
|
|
58076
58524
|
}
|
|
58077
58525
|
const keyFields = config2.keyFieldsForType(fieldType.name);
|
|
@@ -58086,9 +58534,9 @@ async function addID(config2, documents) {
|
|
|
58086
58534
|
continue;
|
|
58087
58535
|
}
|
|
58088
58536
|
selections.push({
|
|
58089
|
-
kind:
|
|
58537
|
+
kind: graphql22.Kind.FIELD,
|
|
58090
58538
|
name: {
|
|
58091
|
-
kind:
|
|
58539
|
+
kind: graphql22.Kind.NAME,
|
|
58092
58540
|
value: keyField
|
|
58093
58541
|
}
|
|
58094
58542
|
});
|
|
@@ -58106,266 +58554,6 @@ async function addID(config2, documents) {
|
|
|
58106
58554
|
}
|
|
58107
58555
|
}
|
|
58108
58556
|
|
|
58109
|
-
// src/codegen/transforms/fragmentVariables.ts
|
|
58110
|
-
var graphql22 = __toESM(require_graphql2(), 1);
|
|
58111
|
-
var GraphqlKinds2 = graphql22.Kind;
|
|
58112
|
-
async function fragmentVariables(config2, documents) {
|
|
58113
|
-
const fragments = collectFragments(config2, documents);
|
|
58114
|
-
const generatedFragments = {};
|
|
58115
|
-
const visitedFragments = /* @__PURE__ */ new Set();
|
|
58116
|
-
for (const doc2 of documents) {
|
|
58117
|
-
const operation = doc2.document.definitions.find(
|
|
58118
|
-
({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
|
|
58119
|
-
);
|
|
58120
|
-
if (!operation) {
|
|
58121
|
-
continue;
|
|
58122
|
-
}
|
|
58123
|
-
doc2.document = inlineFragmentArgs({
|
|
58124
|
-
config: config2,
|
|
58125
|
-
filepath: doc2.filename,
|
|
58126
|
-
fragmentDefinitions: fragments,
|
|
58127
|
-
document: doc2.document,
|
|
58128
|
-
generatedFragments,
|
|
58129
|
-
visitedFragments,
|
|
58130
|
-
scope: null
|
|
58131
|
-
});
|
|
58132
|
-
}
|
|
58133
|
-
const doc = {
|
|
58134
|
-
kind: graphql22.Kind.DOCUMENT,
|
|
58135
|
-
definitions: Object.values(generatedFragments)
|
|
58136
|
-
};
|
|
58137
|
-
documents.push({
|
|
58138
|
-
name: "generated::fragmentVariables",
|
|
58139
|
-
kind: "HoudiniFragment" /* Fragment */,
|
|
58140
|
-
document: doc,
|
|
58141
|
-
originalDocument: doc,
|
|
58142
|
-
generateStore: false,
|
|
58143
|
-
generateArtifact: false,
|
|
58144
|
-
filename: "generated::fragmentVariables",
|
|
58145
|
-
originalString: ""
|
|
58146
|
-
});
|
|
58147
|
-
}
|
|
58148
|
-
function inlineFragmentArgs({
|
|
58149
|
-
config: config2,
|
|
58150
|
-
filepath,
|
|
58151
|
-
fragmentDefinitions,
|
|
58152
|
-
document,
|
|
58153
|
-
generatedFragments,
|
|
58154
|
-
visitedFragments,
|
|
58155
|
-
scope,
|
|
58156
|
-
newName
|
|
58157
|
-
}) {
|
|
58158
|
-
if (!scope) {
|
|
58159
|
-
scope = operationScope(
|
|
58160
|
-
document.definitions.find(
|
|
58161
|
-
({ kind }) => kind === GraphqlKinds2.OPERATION_DEFINITION
|
|
58162
|
-
)
|
|
58163
|
-
);
|
|
58164
|
-
}
|
|
58165
|
-
const definitionArgs = fragmentArguments(
|
|
58166
|
-
config2,
|
|
58167
|
-
filepath,
|
|
58168
|
-
document
|
|
58169
|
-
).reduce((acc, arg) => ({ ...acc, [arg.name]: arg }), {});
|
|
58170
|
-
const result = graphql22.visit(document, {
|
|
58171
|
-
FragmentSpread(node) {
|
|
58172
|
-
const { definition } = fragmentDefinitions[node.name.value];
|
|
58173
|
-
let { args, hash } = collectWithArguments(config2, filepath, node, scope);
|
|
58174
|
-
const newFragmentName = `${node.name.value}${hash}`;
|
|
58175
|
-
if (!visitedFragments.has(newFragmentName)) {
|
|
58176
|
-
visitedFragments.add(newFragmentName);
|
|
58177
|
-
const defaultArguments = collectDefaultArgumentValues(config2, filepath, definition);
|
|
58178
|
-
if (args) {
|
|
58179
|
-
for (const [field, value] of Object.entries(defaultArguments || {})) {
|
|
58180
|
-
if (!args[field]) {
|
|
58181
|
-
args[field] = value;
|
|
58182
|
-
}
|
|
58183
|
-
}
|
|
58184
|
-
generatedFragments[newFragmentName] = inlineFragmentArgs({
|
|
58185
|
-
config: config2,
|
|
58186
|
-
filepath,
|
|
58187
|
-
fragmentDefinitions,
|
|
58188
|
-
document: fragmentDefinitions[node.name.value].definition,
|
|
58189
|
-
generatedFragments,
|
|
58190
|
-
visitedFragments,
|
|
58191
|
-
scope: args,
|
|
58192
|
-
newName: newFragmentName
|
|
58193
|
-
});
|
|
58194
|
-
} else {
|
|
58195
|
-
const doc = fragmentDefinitions[node.name.value].document;
|
|
58196
|
-
const definitionIndex = doc.document.definitions.findIndex(
|
|
58197
|
-
(definition2) => definition2.kind === "FragmentDefinition" && definition2.name.value === node.name.value
|
|
58198
|
-
);
|
|
58199
|
-
const localDefinitions = [...doc.document.definitions];
|
|
58200
|
-
localDefinitions.splice(definitionIndex, 1);
|
|
58201
|
-
localDefinitions.push(
|
|
58202
|
-
inlineFragmentArgs({
|
|
58203
|
-
config: config2,
|
|
58204
|
-
filepath,
|
|
58205
|
-
fragmentDefinitions,
|
|
58206
|
-
document: fragmentDefinitions[node.name.value].definition,
|
|
58207
|
-
generatedFragments,
|
|
58208
|
-
visitedFragments,
|
|
58209
|
-
scope: defaultArguments,
|
|
58210
|
-
newName: ""
|
|
58211
|
-
})
|
|
58212
|
-
);
|
|
58213
|
-
doc.document = {
|
|
58214
|
-
...doc.document,
|
|
58215
|
-
definitions: localDefinitions
|
|
58216
|
-
};
|
|
58217
|
-
}
|
|
58218
|
-
if (node.name.value !== newFragmentName) {
|
|
58219
|
-
return {
|
|
58220
|
-
...node,
|
|
58221
|
-
name: {
|
|
58222
|
-
kind: "Name",
|
|
58223
|
-
value: newFragmentName
|
|
58224
|
-
}
|
|
58225
|
-
};
|
|
58226
|
-
}
|
|
58227
|
-
}
|
|
58228
|
-
},
|
|
58229
|
-
Argument(node) {
|
|
58230
|
-
const value = node.value;
|
|
58231
|
-
if (value.kind !== "Variable") {
|
|
58232
|
-
return;
|
|
58233
|
-
}
|
|
58234
|
-
if (!scope) {
|
|
58235
|
-
throw new HoudiniError({
|
|
58236
|
-
filepath,
|
|
58237
|
-
message: node.name.value + " is not defined in the current scope: " + JSON.stringify(scope)
|
|
58238
|
-
});
|
|
58239
|
-
}
|
|
58240
|
-
const newValue = scope[value.name.value];
|
|
58241
|
-
if (newValue) {
|
|
58242
|
-
return {
|
|
58243
|
-
...node,
|
|
58244
|
-
value: newValue
|
|
58245
|
-
};
|
|
58246
|
-
}
|
|
58247
|
-
if (definitionArgs[value.name.value] && definitionArgs[value.name.value].required) {
|
|
58248
|
-
throw new HoudiniError({
|
|
58249
|
-
filepath,
|
|
58250
|
-
message: "Missing value for required arg: " + value.name.value
|
|
58251
|
-
});
|
|
58252
|
-
}
|
|
58253
|
-
return null;
|
|
58254
|
-
}
|
|
58255
|
-
});
|
|
58256
|
-
if (newName) {
|
|
58257
|
-
result.name = {
|
|
58258
|
-
kind: graphql22.Kind.NAME,
|
|
58259
|
-
value: newName
|
|
58260
|
-
};
|
|
58261
|
-
}
|
|
58262
|
-
return result;
|
|
58263
|
-
}
|
|
58264
|
-
function withArguments(config2, node) {
|
|
58265
|
-
const withDirectives = node.directives?.filter(
|
|
58266
|
-
(directive) => directive.name.value === config2.withDirective
|
|
58267
|
-
);
|
|
58268
|
-
if (!withDirectives || withDirectives.length === 0) {
|
|
58269
|
-
return [];
|
|
58270
|
-
}
|
|
58271
|
-
return withDirectives.flatMap((directive) => directive.arguments || []);
|
|
58272
|
-
}
|
|
58273
|
-
function fragmentArguments(config2, filepath, definition) {
|
|
58274
|
-
const directives = definition.directives?.filter(
|
|
58275
|
-
(directive) => directive.name.value === config2.argumentsDirective
|
|
58276
|
-
);
|
|
58277
|
-
if (!directives || directives.length === 0) {
|
|
58278
|
-
return [];
|
|
58279
|
-
}
|
|
58280
|
-
return directives.flatMap(
|
|
58281
|
-
(directive) => directive.arguments?.flatMap((arg) => {
|
|
58282
|
-
if (arg.value.kind !== "ObjectValue") {
|
|
58283
|
-
throw new HoudiniError({
|
|
58284
|
-
filepath,
|
|
58285
|
-
message: "values of @argument must be objects"
|
|
58286
|
-
});
|
|
58287
|
-
}
|
|
58288
|
-
const typeArg = arg.value.fields?.find((arg2) => arg2.name.value === "type")?.value;
|
|
58289
|
-
if (!typeArg || typeArg.kind !== "StringValue") {
|
|
58290
|
-
return [];
|
|
58291
|
-
}
|
|
58292
|
-
let type = typeArg.value;
|
|
58293
|
-
let name2 = arg.name.value;
|
|
58294
|
-
let required = false;
|
|
58295
|
-
let defaultValue = arg.value.fields?.find((arg2) => arg2.name.value === "default")?.value || null;
|
|
58296
|
-
if (type[type.length - 1] === "!") {
|
|
58297
|
-
type = type.slice(0, -1);
|
|
58298
|
-
required = true;
|
|
58299
|
-
defaultValue = null;
|
|
58300
|
-
}
|
|
58301
|
-
return [
|
|
58302
|
-
{
|
|
58303
|
-
name: name2,
|
|
58304
|
-
type,
|
|
58305
|
-
required,
|
|
58306
|
-
defaultValue
|
|
58307
|
-
}
|
|
58308
|
-
];
|
|
58309
|
-
}) || []
|
|
58310
|
-
);
|
|
58311
|
-
}
|
|
58312
|
-
function collectDefaultArgumentValues(config2, filepath, definition) {
|
|
58313
|
-
let result = {};
|
|
58314
|
-
for (const { name: name2, required, defaultValue } of fragmentArguments(
|
|
58315
|
-
config2,
|
|
58316
|
-
filepath,
|
|
58317
|
-
definition
|
|
58318
|
-
)) {
|
|
58319
|
-
if (required || !defaultValue) {
|
|
58320
|
-
continue;
|
|
58321
|
-
}
|
|
58322
|
-
result[name2] = defaultValue;
|
|
58323
|
-
}
|
|
58324
|
-
return result;
|
|
58325
|
-
}
|
|
58326
|
-
function collectWithArguments(config2, filepath, node, scope = {}) {
|
|
58327
|
-
const withArgs = withArguments(config2, node);
|
|
58328
|
-
if (withArgs.length === 0) {
|
|
58329
|
-
return { args: null, hash: "" };
|
|
58330
|
-
}
|
|
58331
|
-
let args = {};
|
|
58332
|
-
for (const arg of withArgs) {
|
|
58333
|
-
let value = arg.value;
|
|
58334
|
-
if (value.kind === GraphqlKinds2.VARIABLE) {
|
|
58335
|
-
if (!scope || !scope[value.name.value]) {
|
|
58336
|
-
throw new HoudiniError({
|
|
58337
|
-
filepath,
|
|
58338
|
-
message: "Encountered undefined variable: " + value.name.value
|
|
58339
|
-
});
|
|
58340
|
-
}
|
|
58341
|
-
value = scope[value.name.value];
|
|
58342
|
-
}
|
|
58343
|
-
args[arg.name.value] = {
|
|
58344
|
-
...value,
|
|
58345
|
-
loc: void 0
|
|
58346
|
-
};
|
|
58347
|
-
}
|
|
58348
|
-
return {
|
|
58349
|
-
args,
|
|
58350
|
-
hash: "_" + murmurHash(JSON.stringify(args))
|
|
58351
|
-
};
|
|
58352
|
-
}
|
|
58353
|
-
function operationScope(operation) {
|
|
58354
|
-
return operation.variableDefinitions?.reduce(
|
|
58355
|
-
(scope, definition) => ({
|
|
58356
|
-
...scope,
|
|
58357
|
-
[definition.variable.name.value]: {
|
|
58358
|
-
kind: "Variable",
|
|
58359
|
-
name: {
|
|
58360
|
-
kind: "Name",
|
|
58361
|
-
value: definition.variable.name.value
|
|
58362
|
-
}
|
|
58363
|
-
}
|
|
58364
|
-
}),
|
|
58365
|
-
{}
|
|
58366
|
-
) || {};
|
|
58367
|
-
}
|
|
58368
|
-
|
|
58369
58557
|
// src/codegen/validators/typeCheck.ts
|
|
58370
58558
|
var graphql23 = __toESM(require_graphql2(), 1);
|
|
58371
58559
|
async function typeCheck(config2, docs) {
|