Skip to content

Instantly share code, notes, and snippets.

@umutyerebakmaz
Last active March 8, 2023 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umutyerebakmaz/b186dddacc8be6773cd06b74f802dbde to your computer and use it in GitHub Desktop.
Save umutyerebakmaz/b186dddacc8be6773cd06b74f802dbde to your computer and use it in GitHub Desktop.
Using @FieldResolver
@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;
}
// 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