Last active
March 8, 2023 11:21
-
-
Save umutyerebakmaz/b186dddacc8be6773cd06b74f802dbde to your computer and use it in GitHub Desktop.
Using @FieldResolver
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
@Entity() | |
@ObjectType() | |
export class Foo extends BaseEntity { | |
@PrimaryGeneratedColumn('uuid') | |
@Field(() => ID) | |
id: string; | |
@Column() | |
@Field() | |
title: string; | |
// we create a special field that has no equivalent in the database | |
@Field({ nullable: true }) | |
scheduledDate: Date; | |
} |
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
// https://typegraphql.com/docs/resolvers.html#field-resolvers | |
@FieldResolver(() => Date) | |
async scheduledDate(@Root() foo: Foo): Promise<Date> { | |
// Write the custom sql query you want with the gql root. | |
return new Date(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment