-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(float_decorator): support float decorator
- Loading branch information
Dewey Jose
committed
Mar 29, 2019
1 parent
32673c3
commit ef6d560
Showing
6 changed files
with
53 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Field, Float } from 'type-graphql'; | ||
import { Column } from 'typeorm'; | ||
|
||
import { composeMethodDecorators, MethodDecoratorFactory } from '../utils'; | ||
|
||
interface FloatFieldOptions { | ||
nullable?: boolean; | ||
} | ||
|
||
export function FloatField(args: FloatFieldOptions = {}): any { | ||
const nullableOption = args.nullable === true ? { nullable: true } : {}; | ||
|
||
// These are the 2 required decorators to get type-graphql and typeorm working | ||
const factories = [ | ||
// We explicitly say string here because when we're metaprogramming without | ||
// TS types, Field does not know that this should be a String | ||
Field(type => Float, { | ||
...nullableOption | ||
}), | ||
Column({ | ||
type: 'float8', | ||
...nullableOption | ||
}) as MethodDecoratorFactory | ||
]; | ||
|
||
return composeMethodDecorators(...factories); | ||
} |
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