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

formgen: add type declaration generation #430

Merged
merged 9 commits into from
Oct 24, 2023
5 changes: 5 additions & 0 deletions .changeset/famous-rockets-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/form-generator': patch
---

Generate type declaration files for rendered components
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
GraphqlFormGenerator,
GraphqlGenerationResult,
} from './graphql_form_generator.js';
import { getDeclarationFilename } from '@aws-amplify/codegen-ui-react/dist/lib/react-studio-template-renderer-helper.js';
sdstolworthy marked this conversation as resolved.
Show resolved Hide resolved

type FormDef = Set<'create' | 'update'>;
type ModelRecord = Record<string, FormDef>;
Expand Down Expand Up @@ -125,11 +126,20 @@ export class LocalGraphqlFormGenerator implements GraphqlFormGenerator {
formFeatureFlags
);
const { componentText, declaration } = renderer.renderComponentInternal();
return {
componentText,
fileName: renderer.fileName,
declaration,
};
const files = [
{
componentText,
fileName: renderer.fileName,
},
];
if (declaration) {
files.push({
componentText: declaration,
fileName: getDeclarationFilename(renderer.fileName),
});
}

return files;
};
sdstolworthy marked this conversation as resolved.
Show resolved Hide resolved
private filterModelsByName = (
filteredModelNames: string[],
Expand Down Expand Up @@ -262,8 +272,10 @@ export class LocalGraphqlFormGenerator implements GraphqlFormGenerator {
);
const forms = baseForms.reduce<Record<string, string>>(
(prev, formSchema) => {
const result = this.codegenForm(dataSchema, formSchema);
prev[result.fileName] = result.componentText;
const results = this.codegenForm(dataSchema, formSchema);
results.forEach((result) => {
prev[result.fileName] = result.componentText;
});
return prev;
},
{}
Expand Down