Create new field type JSON (#4729)
### Description Create new field type JSON ### Refs https://github.com/twentyhq/twenty/issues/3900 ### Demo https://github.com/twentyhq/twenty/assets/140154534/9ebdf4d4-f332-4940-b9d8-d9cf91935b67 Fixes #3900 --------- Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com> Co-authored-by: Marie Stoppa <marie.stoppa@essec.edu>
This commit is contained in:
committed by
GitHub
parent
f25d58b0d9
commit
584d90ec89
@ -1,3 +1,4 @@
|
||||
import { JsonScalarType } from './json.scalar';
|
||||
import { PositionScalarType } from './position.scalar';
|
||||
import { CursorScalarType } from './cursor.scalar';
|
||||
import { BigFloatScalarType } from './big-float.scalar';
|
||||
@ -24,4 +25,5 @@ export const scalars = [
|
||||
UUIDScalarType,
|
||||
CursorScalarType,
|
||||
PositionScalarType,
|
||||
JsonScalarType,
|
||||
];
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
import { isString } from 'class-validator';
|
||||
import { GraphQLScalarType } from 'graphql';
|
||||
import GraphQLJSON from 'graphql-type-json';
|
||||
|
||||
export const JsonScalarType = new GraphQLScalarType({
|
||||
...GraphQLJSON,
|
||||
parseValue: (value) => {
|
||||
if (isString(value) && isString(JSON.parse(value))) {
|
||||
throw new Error(`Strings are not supported as JSON: ${value}`);
|
||||
}
|
||||
|
||||
return GraphQLJSON.parseValue(value);
|
||||
},
|
||||
});
|
||||
@ -14,7 +14,6 @@ import {
|
||||
GraphQLString,
|
||||
GraphQLType,
|
||||
} from 'graphql';
|
||||
import GraphQLJSON from 'graphql-type-json';
|
||||
|
||||
import {
|
||||
DateScalarMode,
|
||||
@ -39,6 +38,7 @@ 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 { JsonScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars/json.scalar';
|
||||
|
||||
export interface TypeOptions<T = any> {
|
||||
nullable?: boolean;
|
||||
@ -71,7 +71,7 @@ export class TypeMapperService {
|
||||
[FieldMetadataType.PROBABILITY, GraphQLFloat],
|
||||
[FieldMetadataType.RELATION, UUIDScalarType],
|
||||
[FieldMetadataType.POSITION, PositionScalarType],
|
||||
[FieldMetadataType.RAW_JSON, GraphQLJSON],
|
||||
[FieldMetadataType.RAW_JSON, JsonScalarType],
|
||||
]);
|
||||
|
||||
return typeScalarMapping.get(fieldMetadataType);
|
||||
|
||||
Reference in New Issue
Block a user