Skip to content

Commit

Permalink
noinit codegen from graphqlconfig (#706)
Browse files Browse the repository at this point in the history
* fix: add missing awaits

* chore: fail typegen if no queries are found
  • Loading branch information
alharris-at authored Sep 19, 2023
1 parent ff4e221 commit caad510
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function generateStatementsAndTypes(context, forceDownloadSchema, maxDepth
if (!withoutInit) {
apis = getAppSyncAPIDetails(context);
} else {
const api = getAppSyncAPIInfoFromProject(context, project);
const api = await getAppSyncAPIInfoFromProject(context, project);
if (api) {
apis = [api];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-codegen/src/commands/statements.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function generateStatements(context, forceDownloadSchema, maxDepth, withou
if (!withoutInit) {
apis = getAppSyncAPIDetails(context);
} else {
const api = getAppSyncAPIInfoFromProject(context, projects[0]);
const api = await getAppSyncAPIInfoFromProject(context, projects[0]);
if (api) {
apis = [api];
}
Expand Down
11 changes: 7 additions & 4 deletions packages/amplify-codegen/src/commands/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function generateTypes(context, forceDownloadSchema, withoutInit = false,
if (!withoutInit) {
apis = getAppSyncAPIDetails(context);
} else {
const api = getAppSyncAPIInfoFromProject(context, projects[0]);
const api = await getAppSyncAPIInfoFromProject(context, projects[0]);
if (api) {
apis = [api];
}
Expand All @@ -57,7 +57,7 @@ async function generateTypes(context, forceDownloadSchema, withoutInit = false,
const target = cfg.amplifyExtension.codeGenTarget;

const excludes = cfg.excludes.map(pattern => `!${pattern}`);
const queries = glob
const queryFiles = glob
.sync([...includeFiles, ...excludes], {
cwd: projectPath,
absolute: true,
Expand All @@ -73,8 +73,11 @@ async function generateTypes(context, forceDownloadSchema, withoutInit = false,
return extractDocumentFromJavascript(fileContents, '');
}
return fileContents;
})
.join('\n');
});
if (queryFiles.length === 0) {
throw new Error('No queries found to generate types for, you may need to run \'codegen statements\' first');
}
const queries = queryFiles.join('\n');

const schemaPath = path.join(projectPath, cfg.schema);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const getAppSyncAPIInfo = require('./getAppSyncAPIInfo');
/* Get AppSync api info if api id and region are avialable.
* Otherwise return undefined.
*/
function getAppSyncAPIInfoFromProject(context, project) {
async function getAppSyncAPIInfoFromProject(context, project) {
if (project.amplifyExtension.apiId && project.amplifyExtension.region) {
const {
amplifyExtension: { apiId, region },
Expand Down

0 comments on commit caad510

Please sign in to comment.