How to return more fields in afterUpdate (UpdateEvent) in typeorm subscriber and not just the updated field

122
February 06, 2022, at 05:30 AM

In my Resolver, I have this update function:

@Mutation(() => Email)
async updateEmail(
  @Arg("uuid", () => String) uuid: string,
  @Arg("params", () => UpdateEmailInput) params: UpdateEmailInput
){
  const email = await Email.findOne(uuid)
  if (!email) throw new Error("Email with given uuid not found.");
  await Email.update({ uuid }, params)
}

After the update, it triggers my subscriber correctly:

@EventSubscriber()
export class EmailSubscriber implements 
EntitySubscriberInterface<Email> {
listenTo() {
    return Email;
}
async afterInsert(event: InsertEvent<Email>) {
    console.log("subscriber triggered - one new insert")
    processNewEmail(event);
}
async afterUpdate(event: UpdateEvent<Email>) {
    console.log("subscriber triggered - one new update")
    updateEmail(event)
}
}

The problem is that event.entity in afterUpdate only contains the updated field (the send_on_date) and not all the fields. I have no such problem with the InsertEvent, just the UpdateEvent.

Here is the mutation I run in Graphql:

mutation UpdateEmail {
updateEmail(params: {
send_on_date : "2022-02-04T16:59:00+08:00"
}, uuid: "22") {
 uuid
 subject
 sender
 email_body
 created_at
 updated_at
 send_on_date
}
}

Basically, I also need the uuid to be returned.

Any help is appreciated as I come from an Android/Kotlin background and this is the first time I'm working on backend.

Rent Charter Buses Company
READ ALSO
PHP transfer variables between PHP includes in the same page

PHP transfer variables between PHP includes in the same page

I have indexphp page where there is the date

119
React infinite loop - onClick inside a render calls setState()

React infinite loop - onClick inside a render calls setState()

Pretty new to ReactI'm having some problems rendering a button component

186
addEventListener for submits overrides all my submit functions

addEventListener for submits overrides all my submit functions

I have an infinite scrolling template that has logic to override the submit action of formsThe issue is when my loop runs through it attaches the last eventListener to all my submit forms which causes issues

31