-
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.
Merge pull request #412 from goldcaddy77/411-typed-jsonb-fields
feat(decorators): allow concrete type on JSONField
- Loading branch information
Showing
11 changed files
with
184 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const caller = require('caller'); // eslint-disable-line @typescript-eslint/no-var-requires | ||
import * as path from 'path'; | ||
import { ObjectType as TypeGraphQLObjectType } from 'type-graphql'; | ||
import { ObjectOptions } from 'type-graphql/dist/decorators/ObjectType.d'; | ||
|
||
import { ClassType } from '../core'; | ||
import { getMetadataStorage } from '../metadata'; | ||
import { ClassDecoratorFactory, composeClassDecorators, generatedFolderPath } from '../utils/'; | ||
|
||
// Allow default TypeORM and TypeGraphQL options to be used | ||
// export function Model({ api = {}, db = {}, apiOnly = false, dbOnly = false }: ModelOptions = {}) { | ||
export function ObjectType(options: ObjectOptions = {}) { | ||
// In order to use the enums in the generated classes file, we need to | ||
// save their locations and import them in the generated file | ||
const modelFileName = caller(); | ||
|
||
// Use relative paths when linking source files so that we can check the generated code in | ||
// and it will work in any directory structure | ||
const relativeFilePath = path.relative(generatedFolderPath(), modelFileName); | ||
|
||
const registerModelWithWarthog = (target: ClassType): void => { | ||
// Save off where the model is located so that we can import it in the generated classes | ||
getMetadataStorage().addClass(target.name, target, relativeFilePath); | ||
}; | ||
|
||
const factories: any[] = []; | ||
|
||
// We add our own Warthog decorator regardless of dbOnly and apiOnly | ||
factories.push(registerModelWithWarthog as ClassDecoratorFactory); | ||
|
||
// We shouldn't add this as it creates the GraphQL type, but there is a | ||
// bug if we don't add it because we end up adding the Field decorators in the models | ||
factories.push(TypeGraphQLObjectType(options as ObjectOptions) as ClassDecoratorFactory); | ||
|
||
return composeClassDecorators(...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
Oops, something went wrong.