Skip to main content

Input

Most Actions have an Input associated with them. This is generated based on how the action is configured.

Action Input

The Input is usually a subset of all the fields exposed in the schema for the Ent although it can include other fields if there are action only fields.

For example, in the create action, the input looks as follows:

src/ent/generated/event/actions/create_event_action_base.ts

export interface EventCreateInput {
name: string;
creatorID: ID | Builder<User, Viewer>;
startTime: Date;
endTime?: Date | null;
location: string;
}

but in the edit action, it looks slightly different with each field optional:

src/ent/generated/event/actions/edit_event_action_base.ts
export interface EventEditInput {
name?: string;
creatorID?: ID | Builder<User, Viewer>;
startTime?: Date;
endTime?: Date | null;
location?: string;
}

This input is passed as the second argument to Triggers, Validators, and Observers. This enables them to be strongly typed when needed e.g. in the observer example.

Builder Input

Each generated Builder has an associated Input which the Action Input is a subset of.

The Builder Input is the source of truth and any updates (in Triggers) is done via the updateInput method.

For example, in a confirm email action, can update the emailVerified field as follows:

src/ent/user/actions/confirm_email_action.ts

export default ConfirmEmailAction extends ConfirmEmailActionBase {

getTriggers() {
return [
{
changeset(builder: UserBuilder<ConfirmEmailInput, Viewer>, input: ConfirmEmailInput) {
builder.updateInput({
emailVerified:true,
});
},
},
];
}
}