Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noinit codegen from graphqlconfig #706

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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