-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
GH-4797 Implement websockets [WIP] #5237
Closed
i-am-chitti
wants to merge
46
commits into
twentyhq:main
from
i-am-chitti:GH-4797/ws-gql-subscription
Closed
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
ade0ef5
Enable graphql-ws subscription
i-am-chitti 0ad6155
Add feature flag constant
i-am-chitti c1c98f0
Merge branch 'main' into GH-4797/ws-gql-subscription
i-am-chitti 3aeb60f
Merge branch 'main' into GH-4797/ws-gql-subscription
i-am-chitti dd51a85
Merge branch 'main' into GH-4797/ws-gql-subscription
i-am-chitti 2d20c00
Add event listeners
i-am-chitti 2e874e2
Add subscription resolver
i-am-chitti 8fd2094
Add subscription module
i-am-chitti 9014583
Add GQL field type in ObjectRecordBaseEvent
i-am-chitti 9b1f5ea
Update core-engine module
i-am-chitti 1196084
Merge branch 'main' into GH-4797/ws-gql-subscription
i-am-chitti 6e75a38
Merge branch 'main' into GH-4797/ws-gql-subscription
i-am-chitti 47d917f
Merge branch 'main' into GH-4797/ws-gql-subscription
i-am-chitti 3e8fa12
Fix database reset command
FelixMalfait 2f1e6c4
feat: update links field (#5212)
thaisguigon 62bd61c
Add relation in CSV exports (#5085)
gitstart-app[bot] 0983a20
Enable phone field type (#5052)
gitstart-app[bot] 1737fdb
Bump to 0.10.5
charlesBochet a41f813
User workspace middleware throws 401 if token is invalid (#5245)
Weiko 9f38c94
Constant api version (#5248)
brendanlaschke bb9a4b1
[feat] Minor updates to the edit db connection page (#5250)
ijreilly ceef884
[calendar] hide calendar settings until implemented (#5252)
Weiko 7946553
Fix sync metadata script (#5253)
charlesBochet ac5cb6e
Bump to 0.10.6
charlesBochet b287ddb
fix: fix storybook build script not found by Chromatic (#5235)
thaisguigon 83849ef
Build stripe integration on backend side (#5246)
thomtrp 5c23614
fix workspace-member deletion with existing attachments/documents (#5…
Weiko 6f73094
Quick job update (#5265)
FelixMalfait ce1f6bc
Fix token validation on graphql IntrospectionQuery (#5255)
Weiko 00071a3
Fix filter transform with logic operators (#5269)
Weiko 089164b
fix: fix storybook coverage task (#5256)
thaisguigon 726d5d1
4900 multi select field front implement expanded cells (#5151)
martmull db2da77
[calendar] Fix calendar sync status (#5272)
Weiko 347efc4
Fix white screen on token expire (#5271)
charlesBochet 072fcc9
Fix export with relations (#5279)
thomtrp ec3e2e4
Remove isMultiSelect feature flag (#5280)
thomtrp 6af88e5
Added OG Image (#5251)
ady-beraud 0b690a0
Fix yoga patch user id cache (#5285)
Weiko 71c73a5
Create convert record positions to integers command (#5287)
Weiko fa88c03
Remove Feature Flag on Calendar (#5288)
charlesBochet 1db3aae
Fix Filtered index view infinite re-render (#5286)
charlesBochet 489abfd
Bump versions to 0.11 (#5289)
charlesBochet c9db37b
fix: fix storybook:build memory allocation error in CI (#5284)
thaisguigon d1313dc
Merge branch 'main' into GH-4797/ws-gql-subscription
i-am-chitti 23a7ff2
Update event listner name
i-am-chitti 8980fc8
Merge branch 'main' into GH-4797/ws-gql-subscription
i-am-chitti File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...s/twenty-server/src/engine/integrations/event-emitter/types/object-record-create.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...s/twenty-server/src/engine/integrations/event-emitter/types/object-record-delete.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...s/twenty-server/src/engine/integrations/event-emitter/types/object-record-update.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...ges/twenty-server/src/engine/integrations/event-emitter/types/object-record.base.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,25 @@ | ||
import { Field, ObjectType } from '@nestjs/graphql'; | ||
|
||
import { ObjectMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/object-metadata.interface'; | ||
|
||
@ObjectType() | ||
export class ObjectRecordBaseEvent { | ||
@Field(() => String) | ||
name: string; | ||
|
||
@Field(() => String) | ||
workspaceId: string; | ||
|
||
@Field(() => String) | ||
recordId: string; | ||
|
||
@Field(() => String, { nullable: true }) | ||
userId?: string; | ||
|
||
@Field(() => String, { nullable: true }) | ||
workspaceMemberId?: string; | ||
|
||
@Field(() => ObjectMetadataInterface) | ||
objectMetadata: ObjectMetadataInterface; | ||
properties: any; | ||
} |
25 changes: 24 additions & 1 deletion
25
...-server/src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,48 @@ | ||
import { Field, ObjectType } from '@nestjs/graphql'; | ||
|
||
import GraphQLJSON from 'graphql-type-json'; | ||
|
||
import { FieldMetadataDefaultValue } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-default-value.interface'; | ||
import { FieldMetadataOptions } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-options.interface'; | ||
import { FieldMetadataSettings } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-settings.interface'; | ||
|
||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; | ||
import { RelationMetadataEntity } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity'; | ||
|
||
export interface FieldMetadataInterface< | ||
@ObjectType() | ||
export class FieldMetadataInterface< | ||
T extends FieldMetadataType | 'default' = 'default', | ||
> { | ||
id: string; | ||
type: FieldMetadataType; | ||
name: string; | ||
label: string; | ||
|
||
@Field(() => GraphQLJSON, { nullable: true }) | ||
defaultValue?: FieldMetadataDefaultValue<T>; | ||
|
||
@Field(() => [GraphQLJSON], { nullable: true }) | ||
options?: FieldMetadataOptions<T>; | ||
settings?: FieldMetadataSettings<T>; | ||
|
||
@Field(() => String) | ||
objectMetadataId: string; | ||
|
||
@Field(() => String, { nullable: true }) | ||
workspaceId?: string; | ||
|
||
@Field(() => String, { nullable: true }) | ||
description?: string; | ||
|
||
@Field(() => Boolean, { nullable: true }) | ||
isNullable?: boolean; | ||
|
||
@Field(() => RelationMetadataEntity, { nullable: true }) | ||
fromRelationMetadata?: RelationMetadataEntity; | ||
|
||
@Field(() => RelationMetadataEntity, { nullable: true }) | ||
toRelationMetadata?: RelationMetadataEntity; | ||
|
||
@Field(() => Boolean, { nullable: true }) | ||
isCustom?: boolean; | ||
} |
34 changes: 33 additions & 1 deletion
34
...server/src/engine/metadata-modules/field-metadata/interfaces/object-metadata.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,53 @@ | ||
import { Field, ObjectType } from '@nestjs/graphql'; | ||
|
||
import { RelationMetadataInterface } from './relation-metadata.interface'; | ||
import { FieldMetadataInterface } from './field-metadata.interface'; | ||
|
||
export interface ObjectMetadataInterface { | ||
@ObjectType() | ||
export class ObjectMetadataInterface { | ||
@Field(() => String) | ||
id: string; | ||
standardId?: string | null; | ||
|
||
@Field(() => String) | ||
nameSingular: string; | ||
|
||
@Field(() => String) | ||
namePlural: string; | ||
|
||
@Field(() => String) | ||
labelSingular: string; | ||
|
||
@Field(() => String) | ||
labelPlural: string; | ||
|
||
@Field(() => String, { nullable: true }) | ||
description?: string; | ||
|
||
@Field(() => String) | ||
targetTableName: string; | ||
|
||
@Field(() => [RelationMetadataInterface], { nullable: true }) | ||
fromRelations: RelationMetadataInterface[]; | ||
|
||
@Field(() => [RelationMetadataInterface], { nullable: true }) | ||
toRelations: RelationMetadataInterface[]; | ||
|
||
@Field(() => [FieldMetadataInterface]) | ||
fields: FieldMetadataInterface[]; | ||
|
||
@Field(() => Boolean) | ||
isSystem: boolean; | ||
|
||
@Field(() => Boolean) | ||
isCustom: boolean; | ||
|
||
@Field(() => Boolean) | ||
isActive: boolean; | ||
|
||
@Field(() => Boolean) | ||
isRemote: boolean; | ||
|
||
@Field(() => Boolean) | ||
isAuditLogged: boolean; | ||
} |
17 changes: 16 additions & 1 deletion
17
...rver/src/engine/metadata-modules/field-metadata/interfaces/relation-metadata.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,37 @@ | ||
import { Field, ID, ObjectType } from '@nestjs/graphql'; | ||
|
||
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity'; | ||
|
||
import { ObjectMetadataInterface } from './object-metadata.interface'; | ||
import { FieldMetadataInterface } from './field-metadata.interface'; | ||
|
||
export interface RelationMetadataInterface { | ||
@ObjectType() | ||
export class RelationMetadataInterface { | ||
@Field(() => ID) | ||
id: string; | ||
|
||
@Field(() => RelationMetadataType) | ||
relationType: RelationMetadataType; | ||
|
||
@Field(() => String) | ||
fromObjectMetadataId: string; | ||
|
||
fromObjectMetadata: ObjectMetadataInterface; | ||
|
||
@Field(() => String) | ||
toObjectMetadataId: string; | ||
|
||
toObjectMetadata: ObjectMetadataInterface; | ||
|
||
@Field(() => String) | ||
fromFieldMetadataId: string; | ||
|
||
@Field(() => FieldMetadataInterface) | ||
fromFieldMetadata: FieldMetadataInterface; | ||
|
||
@Field(() => String) | ||
toFieldMetadataId: string; | ||
|
||
@Field(() => FieldMetadataInterface) | ||
toFieldMetadata: FieldMetadataInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/twenty-server/src/engine/subscriptions/events.listener.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { OnEvent } from '@nestjs/event-emitter'; | ||
|
||
import { PubSub } from 'graphql-subscriptions'; | ||
|
||
import { ObjectRecordCreateEvent } from 'src/engine/integrations/event-emitter/types/object-record-create.event'; | ||
import { ObjectRecordDeleteEvent } from 'src/engine/integrations/event-emitter/types/object-record-delete.event'; | ||
import { ObjectRecordUpdateEvent } from 'src/engine/integrations/event-emitter/types/object-record-update.event'; | ||
|
||
@Injectable() | ||
export class EventsListener { | ||
constructor(@Inject('PUB_SUB') private readonly pubSub: PubSub) {} | ||
|
||
@OnEvent('*.created') | ||
async handleCreatedEvent(payload: ObjectRecordCreateEvent<any>) { | ||
this.pubSub.publish('recordCreated', { recordCreated: payload }); | ||
} | ||
|
||
@OnEvent('*.updated') | ||
async handleUpdatedEvent(payload: ObjectRecordUpdateEvent<any>) { | ||
this.pubSub.publish('recordUpdated', { recordUpdated: payload }); | ||
} | ||
|
||
@OnEvent('*.deleted') | ||
async handleDeletedEvent(payload: ObjectRecordDeleteEvent<any>) { | ||
this.pubSub.publish('recordDeleted', { recordDeleted: payload }); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/twenty-server/src/engine/subscriptions/subscriptions.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { PubSub } from 'graphql-subscriptions'; | ||
|
||
import { EventsListener } from 'src/engine/subscriptions/events.listener'; | ||
import { SubscriptionsResolver } from 'src/engine/subscriptions/subscriptions.resolver'; | ||
|
||
@Module({ | ||
imports: [], | ||
exports: [], | ||
providers: [ | ||
{ | ||
provide: 'PUB_SUB', | ||
useFactory: () => { | ||
return new PubSub(); | ||
}, | ||
}, | ||
SubscriptionsResolver, | ||
EventsListener, | ||
], | ||
}) | ||
export class SubscriptionsModule {} |
28 changes: 28 additions & 0 deletions
28
packages/twenty-server/src/engine/subscriptions/subscriptions.resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { Resolver, Subscription } from '@nestjs/graphql'; | ||
|
||
import { PubSub } from 'graphql-subscriptions'; | ||
|
||
import { ObjectRecordCreateEvent } from 'src/engine/integrations/event-emitter/types/object-record-create.event'; | ||
import { ObjectRecordDeleteEvent } from 'src/engine/integrations/event-emitter/types/object-record-delete.event'; | ||
import { ObjectRecordUpdateEvent } from 'src/engine/integrations/event-emitter/types/object-record-update.event'; | ||
|
||
@Resolver() | ||
export class SubscriptionsResolver { | ||
constructor(@Inject('PUB_SUB') private readonly pubSub: PubSub) {} | ||
|
||
@Subscription(() => ObjectRecordCreateEvent<any>) | ||
recordCreated() { | ||
return this.pubSub.asyncIterator('recordCreated'); | ||
} | ||
|
||
@Subscription(() => ObjectRecordUpdateEvent<any>) | ||
recordUpdated() { | ||
return this.pubSub.asyncIterator('recordUpdated'); | ||
} | ||
|
||
@Subscription(() => ObjectRecordDeleteEvent<any>) | ||
recordDeleted() { | ||
return this.pubSub.asyncIterator('recordDeleted'); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming feels too generic, every listener is an event listener :)