-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(front): handle ObjectRecord and not grapql record or connection
- Loading branch information
Showing
4 changed files
with
27 additions
and
54 deletions.
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
42 changes: 18 additions & 24 deletions
42
packages/twenty-front/src/modules/object-record/cache/utils/isObjectRecordConnection.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,30 +1,24 @@ | ||
import { z } from 'zod'; | ||
|
||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; | ||
import { RecordGqlConnection } from '@/object-record/graphql/types/RecordGqlConnection'; | ||
import { capitalize } from 'twenty-shared'; | ||
import { assertUnreachable } from '@/workflow/utils/assertUnreachable'; | ||
import { RelationDefinitionType } from '~/generated-metadata/graphql'; | ||
|
||
export const isObjectRecordConnection = ( | ||
objectNameSingular: string, | ||
relationDefinition: NonNullable<FieldMetadataItem['relationDefinition']>, | ||
value: unknown, | ||
): value is RecordGqlConnection => { | ||
const objectConnectionTypeName = `${capitalize( | ||
objectNameSingular, | ||
)}Connection`; | ||
const objectEdgeTypeName = `${capitalize(objectNameSingular)}Edge`; | ||
|
||
const objectConnectionSchema = z.object({ | ||
__typename: z.literal(objectConnectionTypeName).optional(), | ||
edges: z.array( | ||
z.object({ | ||
__typename: z.literal(objectEdgeTypeName).optional(), | ||
node: z.object({ | ||
id: z.string().uuid(), | ||
}), | ||
}), | ||
), | ||
}); | ||
|
||
const connectionValidation = objectConnectionSchema.safeParse(value); | ||
|
||
return connectionValidation.success; | ||
}; | ||
switch (relationDefinition.direction) { | ||
case RelationDefinitionType.MANY_TO_MANY: | ||
case RelationDefinitionType.ONE_TO_MANY: { | ||
return true; | ||
} | ||
case RelationDefinitionType.MANY_TO_ONE: | ||
case RelationDefinitionType.ONE_TO_ONE: { | ||
return false; | ||
} | ||
default: { | ||
return assertUnreachable(relationDefinition.direction); | ||
} | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
packages/twenty-front/src/modules/object-record/utils/hasManyTargetRecords.ts
This file was deleted.
Oops, something went wrong.