MCPcopy
hub / github.com/subquery/subql / generateEnums

Function generateEnums

packages/cli/src/controller/codegen-controller.ts:100–123  ·  view source on GitHub ↗
(projectPath: string, schema: string)

Source from the content-addressed store, hash-verified

98}
99
100export async function generateEnums(projectPath: string, schema: string): Promise<void> {
101 const typesDir = path.join(projectPath, TYPE_ROOT_DIR);
102 const jsonObjects = getAllEnums(schema);
103 const enums = jsonObjects.map((r) => {
104 return {
105 name: r.name,
106 values: r.getValues().map((v) => v.name),
107 };
108 });
109
110 if (enums.length !== 0) {
111 const enumsTemplate = {
112 props: {
113 enums,
114 },
115 };
116 try {
117 await renderTemplate(ENUM_TEMPLATE_PATH, path.join(typesDir, `enums.ts`), enumsTemplate);
118 exportTypes.enums = true;
119 } catch (e) {
120 throw new Error(`Codegen failed for enums.`, {cause: e});
121 }
122 }
123}
124
125export function processFields(
126 type: 'entity' | 'jsonField',

Callers 1

generateSchemaModelsFunction · 0.85

Calls 4

getAllEnumsFunction · 0.90
renderTemplateFunction · 0.90
mapMethod · 0.80
getValuesMethod · 0.80

Tested by

no test coverage detected