forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new type position (twentyhq#4336)
* Create new type position * Remove position filter type --------- Co-authored-by: Thomas Trompette <[email protected]>
- Loading branch information
Showing
12 changed files
with
53 additions
and
0 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
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
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
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
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
38 changes: 38 additions & 0 deletions
38
...ty-server/src/workspace/workspace-schema-builder/graphql-types/scalars/position.scalar.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { GraphQLScalarType, Kind } from 'graphql'; | ||
|
||
type PositionType = 'first' | 'last' | number; | ||
|
||
const isValidStringPosition = (value: string): boolean => | ||
typeof value === 'string' && (value === 'first' || value === 'last'); | ||
|
||
const isValidNumberPosition = (value: number): boolean => | ||
typeof value === 'number' && value >= 0; | ||
|
||
const checkPosition = (value: any): PositionType => { | ||
if (isValidNumberPosition(value) || isValidStringPosition(value)) { | ||
return value; | ||
} | ||
throw new Error('Invalid position found'); | ||
}; | ||
|
||
export const PositionScalarType = new GraphQLScalarType({ | ||
name: 'Position', | ||
description: | ||
'A custom scalar type for representing record position in a list', | ||
serialize: checkPosition, | ||
parseValue: checkPosition, | ||
parseLiteral(ast): PositionType { | ||
if ( | ||
ast.kind == Kind.STRING && | ||
(ast.value === 'first' || ast.value === 'last') | ||
) { | ||
return ast.value; | ||
} | ||
|
||
if (ast.kind == Kind.INT || ast.kind == Kind.FLOAT) { | ||
return parseFloat(ast.value); | ||
} | ||
|
||
throw new Error('Invalid position found'); | ||
}, | ||
}); |
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