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
Next Next commit
formgen: add type declaration generation
sdstolworthy committed Oct 16, 2023

Verified

This commit was signed with the committer’s verified signature.
sdstolworthy Spencer Stolworthy
commit ba0a43215f0c9d6287e5587893461641d826c0ab
Original file line number Diff line number Diff line change
@@ -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>;
@@ -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[],
@@ -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;
},
{}