Fix microAmount (#2654)
* Fix microAmount * Code review returns * Parse currency values as string * Jeremy's returns * fix: scalars not properly implemented * fix: filters not working on big float scalar --------- Co-authored-by: Jérémy Magrin <jeremy.magrin@gmail.com>
This commit is contained in:
@ -1,22 +1,18 @@
|
||||
import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLList,
|
||||
GraphQLNonNull,
|
||||
GraphQLFloat,
|
||||
} from 'graphql';
|
||||
import { GraphQLInputObjectType, GraphQLList, GraphQLNonNull } from 'graphql';
|
||||
|
||||
import { FilterIsNullable } from 'src/workspace/workspace-schema-builder/graphql-types/input/filter-is-nullable.input-type';
|
||||
import { BigFloatScalarType } from 'src/workspace/workspace-schema-builder/graphql-types/scalars';
|
||||
|
||||
export const BigFloatFilterType = new GraphQLInputObjectType({
|
||||
name: 'BigFloatFilter',
|
||||
fields: {
|
||||
eq: { type: GraphQLFloat },
|
||||
gt: { type: GraphQLFloat },
|
||||
gte: { type: GraphQLFloat },
|
||||
in: { type: new GraphQLList(new GraphQLNonNull(GraphQLFloat)) },
|
||||
lt: { type: GraphQLFloat },
|
||||
lte: { type: GraphQLFloat },
|
||||
neq: { type: GraphQLFloat },
|
||||
eq: { type: BigFloatScalarType },
|
||||
gt: { type: BigFloatScalarType },
|
||||
gte: { type: BigFloatScalarType },
|
||||
in: { type: new GraphQLList(new GraphQLNonNull(BigFloatScalarType)) },
|
||||
lt: { type: BigFloatScalarType },
|
||||
lte: { type: BigFloatScalarType },
|
||||
neq: { type: BigFloatScalarType },
|
||||
is: { type: FilterIsNullable },
|
||||
},
|
||||
});
|
||||
|
||||
@ -5,17 +5,16 @@ export const BigFloatScalarType = new GraphQLScalarType({
|
||||
name: 'BigFloat',
|
||||
description:
|
||||
'A custom scalar type for representing big floating point numbers',
|
||||
serialize(value: number): string {
|
||||
return String(value);
|
||||
},
|
||||
parseValue(value: string): number {
|
||||
serialize(value: string): number {
|
||||
return parseFloat(value);
|
||||
},
|
||||
parseLiteral(ast): number | null {
|
||||
if (ast.kind === Kind.FLOAT) {
|
||||
return parseFloat(ast.value);
|
||||
parseValue(value: number): string {
|
||||
return String(value);
|
||||
},
|
||||
parseLiteral(ast): string | null {
|
||||
if (ast.kind === Kind.FLOAT || ast.kind === Kind.INT) {
|
||||
return String(ast.value);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
@ -13,7 +13,7 @@ export const currencyObjectDefinition = {
|
||||
fields: [
|
||||
{
|
||||
id: 'amountMicros',
|
||||
type: FieldMetadataType.NUMBER,
|
||||
type: FieldMetadataType.NUMERIC,
|
||||
objectMetadataId: FieldMetadataType.CURRENCY.toString(),
|
||||
name: 'amountMicros',
|
||||
label: 'AmountMicros',
|
||||
|
||||
@ -30,8 +30,10 @@ import {
|
||||
FloatFilterType,
|
||||
IntFilterType,
|
||||
BooleanFilterType,
|
||||
BigFloatFilterType,
|
||||
} from 'src/workspace/workspace-schema-builder/graphql-types/input';
|
||||
import { OrderByDirectionType } from 'src/workspace/workspace-schema-builder/graphql-types/enum';
|
||||
import { BigFloatScalarType } from 'src/workspace/workspace-schema-builder/graphql-types/scalars';
|
||||
|
||||
export interface TypeOptions<T = any> {
|
||||
nullable?: boolean;
|
||||
@ -61,6 +63,7 @@ export class TypeMapperService {
|
||||
[FieldMetadataType.DATE_TIME, dateScalar],
|
||||
[FieldMetadataType.BOOLEAN, GraphQLBoolean],
|
||||
[FieldMetadataType.NUMBER, numberScalar],
|
||||
[FieldMetadataType.NUMERIC, BigFloatScalarType],
|
||||
[FieldMetadataType.PROBABILITY, GraphQLFloat],
|
||||
[FieldMetadataType.RELATION, GraphQLID],
|
||||
]);
|
||||
@ -90,6 +93,7 @@ export class TypeMapperService {
|
||||
[FieldMetadataType.DATE_TIME, dateFilter],
|
||||
[FieldMetadataType.BOOLEAN, BooleanFilterType],
|
||||
[FieldMetadataType.NUMBER, numberScalar],
|
||||
[FieldMetadataType.NUMERIC, BigFloatFilterType],
|
||||
[FieldMetadataType.PROBABILITY, FloatFilterType],
|
||||
[FieldMetadataType.RELATION, UUIDFilterType],
|
||||
]);
|
||||
@ -109,6 +113,7 @@ export class TypeMapperService {
|
||||
[FieldMetadataType.DATE_TIME, OrderByDirectionType],
|
||||
[FieldMetadataType.BOOLEAN, OrderByDirectionType],
|
||||
[FieldMetadataType.NUMBER, OrderByDirectionType],
|
||||
[FieldMetadataType.NUMERIC, OrderByDirectionType],
|
||||
[FieldMetadataType.PROBABILITY, OrderByDirectionType],
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user