Skip to content

Ws poc #11293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 49 commits into from
Apr 17, 2025
Merged

Ws poc #11293

merged 49 commits into from
Apr 17, 2025

Conversation

martmull
Copy link
Contributor

@martmull martmull commented Mar 31, 2025

related to twentyhq/core-team-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
  @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

Enregistrement.de.l.ecran.2025-04-16.a.10.54.08.mov

@martmull martmull linked an issue Apr 2, 2025 that may be closed by this pull request
@charlesBochet
Copy link
Member

closing for now to keep the history of PR clean, let's re-open it once ready

Copy link
Contributor

@thomtrp thomtrp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!! Looks really promising ❤️

@martmull martmull enabled auto-merge (squash) April 16, 2025 19:59
@@ -9,7 +9,7 @@ const globalCoverage = {

const modulesCoverage = {
branches: 25,
statements: 44,
statements: 43,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are allowed this time because of the masterpiece!

const tokenPair = getTokenPair();

const sseClient = useMemo(() => {
return createClient({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, isn't there an apollo native integration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, not for sse

@@ -81,6 +83,8 @@ import { FileModule } from './file/file.module';
RoleModule,
TwentyConfigModule,
RedisClientModule,
WorkspaceQueryRunnerModule,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is needed so that databaseEventListener works also on the worker. Without that import, records created by a workflow action won't trigger webhooks for example
I have created a ticket to improve dbEventListener management -> twentyhq/core-team-issues#753

updatedFields: string[];
diff: object;
}) {
const workspaceId = this.scopedWorkspaceContextFactory.create().workspaceId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the regular syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It exists elsewhere, but
const { workspaceId, workspaceMetadataVersion, userWorkspaceId } = this.scopedWorkspaceContextFactory.create(); also exists


@Resolver()
@UseGuards(WorkspaceAuthGuard, UserAuthGuard)
export class SubscriptionsResolver {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what schema is this resolver part of?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/graphql

Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bravo, added questions but non merge blocker, this is a POC :)

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great job! 👏

@martmull martmull enabled auto-merge (squash) April 17, 2025 12:42
@charlesBochet charlesBochet disabled auto-merge April 17, 2025 14:03
@charlesBochet charlesBochet merged commit 42e060a into main Apr 17, 2025
46 checks passed
@charlesBochet charlesBochet deleted the ws-poc branch April 17, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Timebox 2j] Websocket POC
6 participants