Skip to content

Commit

Permalink
fix: remove null coalescing for graphql create forms (#1088)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtpascual committed Aug 22, 2023
1 parent 34facb7 commit bfdcb69
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export default function CreateOwnerForm(props) {
event.preventDefault();
let modelFields = {
name,
Dog: Dog ?? null,
Dog,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -322,7 +322,7 @@ export default function CreateOwnerForm(props) {
});
const modelFieldsToSave = {
name: modelFields.name,
ownerDogId: modelFields?.Dog?.id ?? null,
ownerDogId: modelFields?.Dog?.id,
};
const owner = (
await API.graphql({
Expand Down Expand Up @@ -809,13 +809,13 @@ export default function MyPostForm(props) {
onSubmit={async (event) => {
event.preventDefault();
let modelFields = {
caption: caption ?? null,
username: username ?? null,
post_url: post_url ?? null,
metadata: metadata ?? null,
profile_url: profile_url ?? null,
nonModelField: nonModelField ?? null,
nonModelFieldArray: nonModelFieldArray ?? null,
caption,
username,
post_url,
metadata,
profile_url,
nonModelField,
nonModelFieldArray,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -846,11 +846,11 @@ export default function MyPostForm(props) {
}
});
const modelFieldsToSave = {
caption: modelFields.caption ?? null,
username: modelFields.username ?? null,
post_url: modelFields.post_url ?? null,
metadata: modelFields.metadata ?? null,
profile_url: modelFields.profile_url ?? null,
caption: modelFields.caption,
username: modelFields.username,
post_url: modelFields.post_url,
metadata: modelFields.metadata,
profile_url: modelFields.profile_url,
nonModelFieldArray: modelFields.nonModelFieldArray.map((s) =>
JSON.parse(s)
),
Expand Down Expand Up @@ -1534,9 +1534,9 @@ export default function MyMemberForm(props) {
onSubmit={async (event) => {
event.preventDefault();
let modelFields = {
name: name ?? null,
name,
teamID,
Team: Team ?? null,
Team,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -1575,9 +1575,9 @@ export default function MyMemberForm(props) {
}
});
const modelFieldsToSave = {
name: modelFields.name ?? null,
name: modelFields.name,
teamID: modelFields.teamID,
teamMembersId: modelFields?.Team?.id ?? null,
teamMembersId: modelFields?.Team?.id,
};
await API.graphql({
query: createMember,
Expand Down Expand Up @@ -2176,8 +2176,8 @@ export default function MovieCreateForm(props) {
movieKey,
title,
genre,
rating: rating ?? null,
tags: tags ?? null,
rating,
tags,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -2219,7 +2219,7 @@ export default function MovieCreateForm(props) {
movieKey: modelFields.movieKey,
title: modelFields.title,
genre: modelFields.genre,
rating: modelFields.rating ?? null,
rating: modelFields.rating,
};
const movie = (
await API.graphql({
Expand Down Expand Up @@ -2815,8 +2815,8 @@ export default function SchoolCreateForm(props) {
onSubmit={async (event) => {
event.preventDefault();
let modelFields = {
name: name ?? null,
Students: Students ?? null,
name,
Students,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -2855,7 +2855,7 @@ export default function SchoolCreateForm(props) {
}
});
const modelFieldsToSave = {
name: modelFields.name ?? null,
name: modelFields.name,
};
const school = (
await API.graphql({
Expand Down Expand Up @@ -3371,8 +3371,8 @@ export default function BookCreateForm(props) {
onSubmit={async (event) => {
event.preventDefault();
let modelFields = {
name: name ?? null,
primaryAuthor: primaryAuthor ?? null,
name,
primaryAuthor,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -3411,8 +3411,8 @@ export default function BookCreateForm(props) {
}
});
const modelFieldsToSave = {
name: modelFields.name ?? null,
authorId: modelFields?.primaryAuthor?.id ?? null,
name: modelFields.name,
authorId: modelFields?.primaryAuthor?.id,
};
await API.graphql({
query: createBook,
Expand Down Expand Up @@ -3900,7 +3900,7 @@ export default function CommentCreateForm(props) {
event.preventDefault();
let modelFields = {
content,
postID: postID ?? null,
postID,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -4435,9 +4435,9 @@ export default function TagCreateForm(props) {
onSubmit={async (event) => {
event.preventDefault();
let modelFields = {
label: label ?? null,
Posts: Posts ?? null,
statuses: statuses ?? null,
label,
Posts,
statuses,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -4476,8 +4476,8 @@ export default function TagCreateForm(props) {
}
});
const modelFieldsToSave = {
label: modelFields.label ?? null,
statuses: modelFields.statuses ?? null,
label: modelFields.label,
statuses: modelFields.statuses,
};
const tag = (
await API.graphql({
Expand Down Expand Up @@ -5106,9 +5106,9 @@ export default function BookCreateForm(props) {
onSubmit={async (event) => {
event.preventDefault();
let modelFields = {
name: name ?? null,
primaryAuthor: primaryAuthor ?? null,
primaryTitle: primaryTitle ?? null,
name,
primaryAuthor,
primaryTitle,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -5147,9 +5147,9 @@ export default function BookCreateForm(props) {
}
});
const modelFieldsToSave = {
name: modelFields.name ?? null,
authorId: modelFields?.primaryAuthor?.id ?? null,
titleId: modelFields?.primaryTitle?.id ?? null,
name: modelFields.name,
authorId: modelFields?.primaryAuthor?.id,
titleId: modelFields?.primaryTitle?.id,
};
await API.graphql({
query: createBook,
Expand Down Expand Up @@ -5842,9 +5842,9 @@ export default function CreateCPKTeacherForm(props) {
event.preventDefault();
let modelFields = {
specialTeacherId,
CPKStudent: CPKStudent ?? null,
CPKClasses: CPKClasses ?? null,
CPKProjects: CPKProjects ?? null,
CPKStudent,
CPKClasses,
CPKProjects,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -5885,7 +5885,7 @@ export default function CreateCPKTeacherForm(props) {
const modelFieldsToSave = {
specialTeacherId: modelFields.specialTeacherId,
cPKTeacherCPKStudentSpecialStudentId:
modelFields?.CPKStudent?.specialStudentId ?? null,
modelFields?.CPKStudent?.specialStudentId,
};
const cPKTeacher = (
await API.graphql({
Expand Down Expand Up @@ -6581,9 +6581,9 @@ export default function CreateForm(props) {
onSubmit={async (event) => {
event.preventDefault();
let modelFields = {
name: name ?? null,
nmTest: nmTest ?? null,
parentTable: parentTable ?? null,
name,
nmTest,
parentTable,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -6622,8 +6622,8 @@ export default function CreateForm(props) {
}
});
const modelFieldsToSave = {
name: modelFields.name ?? null,
parentTableBasicTablesId: modelFields?.parentTable?.id ?? null,
name: modelFields.name,
parentTableBasicTablesId: modelFields?.parentTable?.id,
nmTest: modelFields.nmTest
? JSON.parse(modelFields.nmTest)
: modelFields.nmTest,
Expand Down Expand Up @@ -13718,9 +13718,8 @@ export default function CreateCompositeToyForm(props) {
let modelFields = {
kind,
color,
compositeDogCompositeToysName: compositeDogCompositeToysName ?? null,
compositeDogCompositeToysDescription:
compositeDogCompositeToysDescription ?? null,
compositeDogCompositeToysName,
compositeDogCompositeToysDescription,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -14570,10 +14569,10 @@ export default function CreateCommentForm(props) {
event.preventDefault();
let modelFields = {
name,
post: post ?? null,
User: User ?? null,
post,
User,
Org,
postCommentsId: postCommentsId ?? null,
postCommentsId,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -14613,10 +14612,10 @@ export default function CreateCommentForm(props) {
});
const modelFieldsToSave = {
name: modelFields.name,
postID: modelFields?.post?.id ?? null,
userCommentsId: modelFields?.User?.id ?? null,
orgCommentsId: modelFields?.Org?.id ?? null,
postCommentsId: modelFields.postCommentsId ?? null,
postID: modelFields?.post?.id,
userCommentsId: modelFields?.User?.id,
orgCommentsId: modelFields?.Org?.id,
postCommentsId: modelFields.postCommentsId,
};
await API.graphql({
query: createComment,
Expand Down Expand Up @@ -15560,10 +15559,10 @@ export default function CreateCompositeDogForm(props) {
let modelFields = {
name,
description,
CompositeBowl: CompositeBowl ?? null,
CompositeOwner: CompositeOwner ?? null,
CompositeToys: CompositeToys ?? null,
CompositeVets: CompositeVets ?? null,
CompositeBowl,
CompositeOwner,
CompositeToys,
CompositeVets,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -15604,14 +15603,12 @@ export default function CreateCompositeDogForm(props) {
const modelFieldsToSave = {
name: modelFields.name,
description: modelFields.description,
compositeDogCompositeBowlShape:
modelFields?.CompositeBowl?.shape ?? null,
compositeDogCompositeBowlSize:
modelFields?.CompositeBowl?.size ?? null,
compositeDogCompositeBowlShape: modelFields?.CompositeBowl?.shape,
compositeDogCompositeBowlSize: modelFields?.CompositeBowl?.size,
compositeDogCompositeOwnerLastName:
modelFields?.CompositeOwner?.lastName ?? null,
modelFields?.CompositeOwner?.lastName,
compositeDogCompositeOwnerFirstName:
modelFields?.CompositeOwner?.firstName ?? null,
modelFields?.CompositeOwner?.firstName,
};
const compositeDog = (
await API.graphql({
Expand Down Expand Up @@ -16478,8 +16475,8 @@ export default function CreatePostForm(props) {
onSubmit={async (event) => {
event.preventDefault();
let modelFields = {
name: name ?? null,
comments: comments ?? null,
name,
comments,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -16518,7 +16515,7 @@ export default function CreatePostForm(props) {
}
});
const modelFieldsToSave = {
name: modelFields.name ?? null,
name: modelFields.name,
};
const post = (
await API.graphql({
Expand Down Expand Up @@ -18974,7 +18971,7 @@ export default function CreateDogForm(props) {
onSubmit={async (event) => {
event.preventDefault();
let modelFields = {
name: name ?? null,
name,
owner,
};
const validationResponses = await Promise.all(
Expand Down Expand Up @@ -19014,8 +19011,8 @@ export default function CreateDogForm(props) {
}
});
const modelFieldsToSave = {
name: modelFields.name ?? null,
dogOwnerId: modelFields?.owner?.id ?? null,
name: modelFields.name,
dogOwnerId: modelFields?.owner?.id,
};
const dog = (
await API.graphql({
Expand Down Expand Up @@ -19522,7 +19519,7 @@ export default function CreateOwnerForm(props) {
event.preventDefault();
let modelFields = {
name,
Dog: Dog ?? null,
Dog,
};
const validationResponses = await Promise.all(
Object.keys(validations).reduce((promises, fieldName) => {
Expand Down Expand Up @@ -19562,7 +19559,7 @@ export default function CreateOwnerForm(props) {
});
const modelFieldsToSave = {
name: modelFields.name,
ownerDogId: modelFields?.Dog?.id ?? null,
ownerDogId: modelFields?.Dog?.id,
};
const owner = (
await API.graphql({
Expand Down
1 change: 1 addition & 0 deletions packages/codegen-ui-react/lib/amplify-ui-renderers/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ export default class FormRenderer extends ReactComponentRenderer<BaseComponentPr
formMetadata?.fieldConfigs,
undefined,
this.renderConfig.apiConfiguration?.dataApi,
formMetadata?.formActionType,
),
...onSubmitValidationRun(hasModelField),
...this.getOnSubmitDSCall(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export const buildExpression = (
modelFieldsObjectName,
dataSchema.models,
dataApi === 'GraphQL',
dataStoreActionType,
);

const modelObjectToSaveStatements: Statement[] = [];
Expand Down

0 comments on commit bfdcb69

Please sign in to comment.