Core views frontend (#13932)
Parallel code path to read and write core views when IS_CORE_VIEW_ENABLED. Migrated view key to an enum. --------- Co-authored-by: Charles Bochet <charles@twenty.com> Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
-3
@@ -3,7 +3,6 @@ import { BigIntScalarType } from './big-int.scalar';
|
||||
import { CursorScalarType } from './cursor.scalar';
|
||||
import { DateScalarType } from './date.scalar';
|
||||
import { PositionScalarType } from './position.scalar';
|
||||
import { RawJSONScalar } from './raw-json.scalar';
|
||||
import { TimeScalarType } from './time.scalar';
|
||||
import { TSVectorScalarType } from './ts-vector.scalar';
|
||||
import { UUIDScalarType } from './uuid.scalar';
|
||||
@@ -13,7 +12,6 @@ export * from './big-int.scalar';
|
||||
export * from './cursor.scalar';
|
||||
export * from './date.scalar';
|
||||
export * from './position.scalar';
|
||||
export * from './raw-json.scalar';
|
||||
export * from './time.scalar';
|
||||
export * from './ts-vector.scalar';
|
||||
export * from './uuid.scalar';
|
||||
@@ -26,6 +24,5 @@ export const scalars = [
|
||||
UUIDScalarType,
|
||||
CursorScalarType,
|
||||
PositionScalarType,
|
||||
RawJSONScalar,
|
||||
TSVectorScalarType,
|
||||
];
|
||||
|
||||
-81
@@ -1,81 +0,0 @@
|
||||
import { GraphQLScalarType } from 'graphql';
|
||||
import { type Maybe } from 'graphql-yoga';
|
||||
import { type ObjMap } from 'graphql/jsutils/ObjMap';
|
||||
import { type ASTNode, Kind, type ValueNode } from 'graphql/language';
|
||||
|
||||
import { ValidationError } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
|
||||
|
||||
const parseLiteral = (
|
||||
ast: ValueNode,
|
||||
variables?: Maybe<ObjMap<unknown>>,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
): any => {
|
||||
switch (ast.kind) {
|
||||
case Kind.STRING:
|
||||
case Kind.BOOLEAN:
|
||||
return ast.value;
|
||||
case Kind.INT:
|
||||
case Kind.FLOAT:
|
||||
return parseFloat(ast.value);
|
||||
case Kind.OBJECT:
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return parseObject(ast as any, variables);
|
||||
case Kind.LIST:
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return (ast as any).values.map((n: ValueNode) =>
|
||||
parseLiteral(n, variables),
|
||||
);
|
||||
case Kind.NULL:
|
||||
return null;
|
||||
case Kind.VARIABLE:
|
||||
return variables ? variables[ast.name.value] : undefined;
|
||||
default:
|
||||
throw new ValidationError(
|
||||
`JSONStringify cannot represent value: ${JSON.stringify(ast)}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const parseObject = (
|
||||
ast: ASTNode,
|
||||
variables?: Maybe<ObjMap<unknown>>,
|
||||
): object => {
|
||||
const value = Object.create(null);
|
||||
|
||||
if ('fields' in ast) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
ast.fields?.forEach((field: any) => {
|
||||
value[field.name.value] = parseLiteral(field.value, variables);
|
||||
});
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const stringify = (value: any): string => {
|
||||
return JSON.stringify(value);
|
||||
};
|
||||
|
||||
const parseJSON = (value: string): object => {
|
||||
try {
|
||||
return JSON.parse(value);
|
||||
} catch {
|
||||
throw new ValidationError(`Value is not valid JSON: ${value}`);
|
||||
}
|
||||
};
|
||||
|
||||
export const RawJSONScalar = new GraphQLScalarType({
|
||||
name: 'RawJSONScalar',
|
||||
description:
|
||||
'The `RawJSONScalar` scalar type represents JSON values, but stringifies inputs and parses outputs.',
|
||||
serialize: parseJSON,
|
||||
parseValue: stringify,
|
||||
parseLiteral: (ast, variables) => {
|
||||
if (ast.kind === Kind.STRING) {
|
||||
return stringify(ast.value);
|
||||
} else {
|
||||
return stringify(parseLiteral(ast, variables));
|
||||
}
|
||||
},
|
||||
});
|
||||
+2
-2
@@ -13,6 +13,7 @@ import {
|
||||
GraphQLString,
|
||||
type GraphQLType,
|
||||
} from 'graphql';
|
||||
import GraphQLJSON from 'graphql-type-json';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
|
||||
import {
|
||||
@@ -41,7 +42,6 @@ import {
|
||||
UUIDScalarType,
|
||||
} from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
|
||||
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 { 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';
|
||||
|
||||
@@ -87,7 +87,7 @@ export class TypeMapperService {
|
||||
],
|
||||
[FieldMetadataType.NUMERIC, BigFloatScalarType],
|
||||
[FieldMetadataType.POSITION, PositionScalarType],
|
||||
[FieldMetadataType.RAW_JSON, RawJSONScalar],
|
||||
[FieldMetadataType.RAW_JSON, GraphQLJSON],
|
||||
[
|
||||
FieldMetadataType.ARRAY,
|
||||
StringArrayScalarType as unknown as GraphQLScalarType,
|
||||
|
||||
Reference in New Issue
Block a user