Ws poc (#11293)
related to https://github.com/twentyhq/core-team-issues/issues/601 ## Done - add a `onDbEvent` `Subscription` graphql endpoint to listen to database_event using what we have done with webhooks: - you can subscribe to any `action` (created, updated, ...) for any `objectNameSingular` or a specific `recordId`. Parameters are nullable and treated as wildcards when null. - returns events with following shape ```typescript @Field(() => String) eventId: string; @Field() emittedAt: string; @Field(() => DatabaseEventAction) action: DatabaseEventAction; @Field(() => String) objectNameSingular: string; @Field(() => GraphQLJSON) record: ObjectRecord; @Field(() => [String], { nullable: true }) updatedFields?: string[]; ``` - front provide a componentEffect `<ListenRecordUpdatesEffect />` that listen for an `objectNameSingular`, a `recordId` and a list of `listenedFields`. It subscribes to record updates and updates its apollo cached value for specified `listenedFields` - subscription is protected with credentials ## Result Here is an application with `workflowRun` https://github.com/user-attachments/assets/c964d857-3b54-495f-bf14-587ba26c5a8c --------- Co-authored-by: prastoin <paul@twenty.com>
This commit is contained in:
@ -0,0 +1,30 @@
|
||||
import { Field, ObjectType, registerEnumType } from '@nestjs/graphql';
|
||||
|
||||
import GraphQLJSON from 'graphql-type-json';
|
||||
|
||||
import { ObjectRecord } from 'src/engine/api/graphql/workspace-query-builder/interfaces/object-record.interface';
|
||||
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
registerEnumType(DatabaseEventAction, {
|
||||
name: 'DatabaseEventAction',
|
||||
description: 'Database Event Action',
|
||||
});
|
||||
|
||||
@ObjectType()
|
||||
export class OnDbEventDTO {
|
||||
@Field(() => DatabaseEventAction)
|
||||
action: DatabaseEventAction;
|
||||
|
||||
@Field(() => String)
|
||||
objectNameSingular: string;
|
||||
|
||||
@Field()
|
||||
eventDate: Date;
|
||||
|
||||
@Field(() => GraphQLJSON)
|
||||
record: ObjectRecord;
|
||||
|
||||
@Field(() => [String], { nullable: true })
|
||||
updatedFields?: string[];
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
import { Field, InputType } from '@nestjs/graphql';
|
||||
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@InputType()
|
||||
export class OnDbEventInput {
|
||||
@Field(() => DatabaseEventAction, { nullable: true })
|
||||
action?: DatabaseEventAction;
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
objectNameSingular?: string;
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
recordId?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user