Skip to main content

Action Only Fields

Allows configuring other fields to be added in the input of an Action.

In the address example, with the Event schema configured as follows:

src/schema/event_schema.ts
const EventSchema = new EntSchema({
actions: [
{
operation: ActionOperation.Create,
actionOnlyFields: [
{
name: "address",
type: "Object",
nullable: true,
actionName: "CreateAddressAction",
},
],
},
],
});
export default EventSchema;

and the following Address schema:

src/schema/address_schema.ts
const AddressSchema = new EntSchema({
fields: {
Street: StringType(),
City: StringType(),
State: StringType(),
ZipCode: StringType(),
Apartment: StringType({ nullable: true }),
OwnerID: UUIDType({
index: true,
polymorphic: {
types: [NodeType.Event],
}
}),
},

actions: [
{
operation: ActionOperation.Create,
},
],
});
export default AddressSchema

we end up with the following changes:

src/ent/generated/event/actions/create_event_action_base.ts
interface customAddressInput {
street: string;
city: string;
state: string;
zipCode: string;
apartment?: string | null;
}

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

src/graphql/generated/schema.gql
input EventCreateInput {
name: String!
creatorID: ID!
startTime: Time!
endTime: Time
eventLocation: String!
address: AddressEventCreateInput
}

input AddressEventCreateInput {
street: String!
city: String!
state: String!
zipCode: String!
apartment: String
}

and used as follows:

  // creates event and associated address at once
const event = await CreateEventAction.create(vc, {
name: "fun event",
creatorID: user.id,
startTime: yesterday,
endTime: now,
location: "location",
address: {
streetName: "1 Dr Carlton B Goodlett Pl",
city: "San Francisco",
state: "CA",
zip: "94102",
},
}).saveX();

Can be called via the GraphQL API similarly.

Note that nothing is automatically done with action only fields. It's up to the developer to use Triggers to actually process and use them effectively.

It's up to the developer's creativity to find other use cases than what's expressed here.