Skip to content

Commit

Permalink
Remove relations for remotes (twentyhq#5455)
Browse files Browse the repository at this point in the history
For remotes, we will only create the foreign key, without the relation
metadata. Expected behavior will be:
- possible to create an activity. But the remote object will not be
displayed in the relations of the activity
- the remote objects should not be available in the search for relations

Also switched the number settings to an enum, since we now have to
handle `BigInt` case.

---------

Co-authored-by: Thomas Trompette <thomast@twenty.com>
  • Loading branch information
thomtrp and Thomas Trompette committed May 20, 2024
1 parent b098027 commit 4d479ee
Show file tree
Hide file tree
Showing 12 changed files with 454 additions and 479 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"graphql-fields": "^2.0.3",
"graphql-middleware": "^6.1.35",
"graphql-rate-limit": "^3.3.0",
"graphql-scalars": "^1.23.0",
"graphql-subscriptions": "2.0.0",
"graphql-tag": "^2.12.6",
"graphql-type-json": "^0.3.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ export const useMultiObjectSearchMatchesSearchFilterAndToSelectQuery = ({
}) => {
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);

const nonSystemObjectMetadataItems = objectMetadataItems.filter(
({ isSystem }) => !isSystem,
const selectableObjectMetadataItems = objectMetadataItems.filter(
({ isSystem, isRemote }) => !isSystem && !isRemote,
);

const { searchFilterPerMetadataItemNameSingular } =
useSearchFilterPerMetadataItem({
objectMetadataItems: nonSystemObjectMetadataItems,
objectMetadataItems: selectableObjectMetadataItems,
searchFilterValue,
});

const objectRecordsToSelectAndMatchesSearchFilterTextFilterPerMetadataItem =
Object.fromEntries(
nonSystemObjectMetadataItems
selectableObjectMetadataItems
.map(({ nameSingular }) => {
const selectedIds = selectedObjectRecordIds
.filter(
Expand Down Expand Up @@ -74,16 +74,16 @@ export const useMultiObjectSearchMatchesSearchFilterAndToSelectQuery = ({
);

const { orderByFieldPerMetadataItem } = useOrderByFieldPerMetadataItem({
objectMetadataItems: nonSystemObjectMetadataItems,
objectMetadataItems: selectableObjectMetadataItems,
});

const { limitPerMetadataItem } = useLimitPerMetadataItem({
objectMetadataItems: nonSystemObjectMetadataItems,
objectMetadataItems: selectableObjectMetadataItems,
limit,
});

const multiSelectQuery = useGenerateCombinedFindManyRecordsQuery({
operationSignatures: nonSystemObjectMetadataItems.map(
operationSignatures: selectableObjectMetadataItems.map(
(objectMetadataItem) => ({
objectNameSingular: objectMetadataItem.nameSingular,
variables: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import {
GraphQLInputObjectType,
GraphQLList,
GraphQLNonNull,
GraphQLInt,
} from 'graphql';
import { GraphQLInputObjectType, GraphQLList, GraphQLNonNull } from 'graphql';
import { GraphQLBigInt } from 'graphql-scalars';

import { FilterIs } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/input/filter-is.input-type';

export const BigIntFilterType = new GraphQLInputObjectType({
name: 'BigIntFilter',
fields: {
eq: { type: GraphQLInt },
gt: { type: GraphQLInt },
gte: { type: GraphQLInt },
in: { type: new GraphQLList(new GraphQLNonNull(GraphQLInt)) },
lt: { type: GraphQLInt },
lte: { type: GraphQLInt },
neq: { type: GraphQLInt },
eq: { type: GraphQLBigInt },
gt: { type: GraphQLBigInt },
gte: { type: GraphQLBigInt },
in: { type: new GraphQLList(new GraphQLNonNull(GraphQLBigInt)) },
lt: { type: GraphQLBigInt },
lte: { type: GraphQLBigInt },
neq: { type: GraphQLBigInt },
is: { type: FilterIs },
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
GraphQLID,
GraphQLInputObjectType,
GraphQLInputType,
GraphQLInt,
GraphQLList,
GraphQLNonNull,
GraphQLScalarType,
Expand All @@ -26,7 +25,6 @@ import {
BooleanFilterType,
BigFloatFilterType,
RawJsonFilterType,
IntFilterType,
} from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/input';
import { OrderByDirectionType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/enum';
import {
Expand All @@ -36,6 +34,8 @@ import {
import { PositionScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars/position.scalar';
import { RawJSONScalar } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars/raw-json.scalar';
import { IDFilterType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/input/id-filter.input-type';
import { getNumberFilterType } from 'src/engine/api/graphql/workspace-schema-builder/utils/get-number-filter-type.util';
import { getNumberScalarType } from 'src/engine/api/graphql/workspace-schema-builder/utils/get-number-scalar-type.util';

export interface TypeOptions<T = any> {
nullable?: boolean;
Expand All @@ -57,13 +57,6 @@ export class TypeMapperService {
return GraphQLID;
}

const numberScalar =
fieldMetadataType === FieldMetadataType.NUMBER &&
(settings as FieldMetadataSettings<FieldMetadataType.NUMBER>)
?.precision === 0
? GraphQLInt
: GraphQLFloat;

const typeScalarMapping = new Map<FieldMetadataType, GraphQLScalarType>([
[FieldMetadataType.UUID, UUIDScalarType],
[FieldMetadataType.TEXT, GraphQLString],
Expand All @@ -72,7 +65,13 @@ export class TypeMapperService {
[FieldMetadataType.DATE_TIME, GraphQLISODateTime],
[FieldMetadataType.DATE, GraphQLISODateTime],
[FieldMetadataType.BOOLEAN, GraphQLBoolean],
[FieldMetadataType.NUMBER, numberScalar],
[
FieldMetadataType.NUMBER,
getNumberScalarType(
(settings as FieldMetadataSettings<FieldMetadataType.NUMBER>)
?.dataType,
),
],
[FieldMetadataType.NUMERIC, BigFloatScalarType],
[FieldMetadataType.PROBABILITY, GraphQLFloat],
[FieldMetadataType.POSITION, PositionScalarType],
Expand All @@ -91,13 +90,6 @@ export class TypeMapperService {
return IDFilterType;
}

const numberScalar =
fieldMetadataType === FieldMetadataType.NUMBER &&
(settings as FieldMetadataSettings<FieldMetadataType.NUMBER>)
?.precision === 0
? IntFilterType
: FloatFilterType;

const typeFilterMapping = new Map<
FieldMetadataType,
GraphQLInputObjectType | GraphQLScalarType
Expand All @@ -109,7 +101,13 @@ export class TypeMapperService {
[FieldMetadataType.DATE_TIME, DateFilterType],
[FieldMetadataType.DATE, DateFilterType],
[FieldMetadataType.BOOLEAN, BooleanFilterType],
[FieldMetadataType.NUMBER, numberScalar],
[
FieldMetadataType.NUMBER,
getNumberFilterType(
(settings as FieldMetadataSettings<FieldMetadataType.NUMBER>)
?.dataType,
),
],
[FieldMetadataType.NUMERIC, BigFloatFilterType],
[FieldMetadataType.PROBABILITY, FloatFilterType],
[FieldMetadataType.POSITION, FloatFilterType],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { GraphQLInputObjectType } from 'graphql';

import { NumberDataType } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-settings.interface';

import {
BigIntFilterType,
FloatFilterType,
IntFilterType,
} from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/input';

export const getNumberFilterType = (
subType: NumberDataType | undefined,
): GraphQLInputObjectType => {
switch (subType) {
case NumberDataType.FLOAT:
return FloatFilterType;
case NumberDataType.BIGINT:
return BigIntFilterType;
case NumberDataType.INT:
return IntFilterType;
default:
return FloatFilterType;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { GraphQLInt, GraphQLFloat, GraphQLScalarType } from 'graphql';
import { GraphQLBigInt } from 'graphql-scalars';

import { NumberDataType } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-settings.interface';

export const getNumberScalarType = (
dataType: NumberDataType,
): GraphQLScalarType => {
switch (dataType) {
case NumberDataType.FLOAT:
return GraphQLFloat;
case NumberDataType.BIGINT:
return GraphQLBigInt;
case NumberDataType.INT:
return GraphQLInt;
default:
return GraphQLFloat;
}
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';

export enum NumberDataType {
FLOAT = 'float',
INT = 'int',
BIGINT = 'bigint',
}

type FieldMetadataDefaultSettings = {
isForeignKey?: boolean;
};

type FieldMetadataNumberSettings = {
precision: number;
dataType: NumberDataType;
};

type FieldMetadataSettingsMapping = {
Expand Down
Loading

0 comments on commit 4d479ee

Please sign in to comment.