type-graphql#Directive TypeScript Examples
The following examples show how to use
type-graphql#Directive.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: user.ts From typegraphql-nestjs with MIT License | 6 votes |
@Directive(`@key(fields: "id")`)
@ObjectType()
export default class User {
@Field(type => ID)
id!: string;
@Field()
username!: string;
@Field()
name!: string;
@Field()
birthDate!: string;
}
Example #2
Source File: resolver.ts From typegraphql-nestjs with MIT License | 6 votes |
@Directive(`@requires(fields: "price weight")`)
@FieldResolver(returns => Number)
async shippingEstimate(@Root() product: Product): Promise<number> {
// free for expensive items
if (product.price > 1000) {
return 0;
}
// estimate is based on weight
return product.weight * 0.5;
}
Example #3
Source File: product.ts From typegraphql-nestjs with MIT License | 6 votes |
@Directive(`@key(fields: "upc")`)
@ObjectType()
export default class Product {
@Field()
upc!: string;
@Field()
name!: string;
@Field()
price!: number;
@Field()
weight!: number;
}
Example #4
Source File: review.ts From typegraphql-nestjs with MIT License | 6 votes |
@Directive(`@key(fields: "id")`)
@ObjectType()
export default class Review {
@Field(type => ID)
id!: string;
@Field()
body!: string;
@Directive(`@provides(fields: "username")`)
@Field()
author!: User;
@Field()
product!: Product;
}
Example #5
Source File: user.ts From typegraphql-nestjs with MIT License | 6 votes |
@Directive("@extends")
@Directive(`@key(fields: "id")`)
@ObjectType()
export default class User {
@Directive("@external")
@Field(type => ID)
id!: string;
@Directive("@external")
@Field()
username!: string;
}
Example #6
Source File: util.ts From backend with MIT License | 6 votes |
export function Deprecated(reason: string) {
return Directive(`@deprecated(reason: "${reason}")`);
}
Example #7
Source File: request.ts From opensaas with MIT License | 6 votes |
@Directive('@key(fields: "id")')
@Entity({ name: 'requests' })
@ObjectType()
export class Request extends BaseEntity {
@Field(() => ID)
@PrimaryGeneratedColumn()
id!: number;
@Field(() => ID)
@Column('varchar', { length: 256, nullable: false })
tenantId!: string;
@Field(() => String)
@Column('text', { nullable: false })
url!: string;
@Field(() => Number)
@Column('smallint', { nullable: false })
statusCode!: number;
@Field(() => String)
@Column('text', { nullable: false })
userAgent!: string;
@Field(() => String)
@Column('varchar', { length: 32 })
ip!: string;
@Field(() => Date)
@CreateDateColumn({ type: 'timestamp' })
createdAt!: Date;
@Field(() => Date)
@UpdateDateColumn({ type: 'timestamp' })
updatedAt!: Date;
}
Example #8
Source File: product.ts From typegraphql-nestjs with MIT License | 5 votes |
@Field()
@Directive("@external")
upc!: string;
Example #9
Source File: product.ts From typegraphql-nestjs with MIT License | 5 votes |
@Field()
@Directive("@external")
weight!: number;
Example #10
Source File: product.ts From typegraphql-nestjs with MIT License | 5 votes |
@Field()
@Directive("@external")
price!: number;
Example #11
Source File: product.ts From typegraphql-nestjs with MIT License | 5 votes |
@Directive("@external")
@Field()
upc!: string;
Example #12
Source File: product.ts From typegraphql-nestjs with MIT License | 5 votes |
@Directive("@extends")
@Directive(`@key(fields: "upc")`)
@ObjectType()
export default class Product {
@Directive("@external")
@Field()
upc!: string;
}
Example #13
Source File: review.ts From typegraphql-nestjs with MIT License | 5 votes |
@Directive(`@provides(fields: "username")`)
@Field()
author!: User;
Example #14
Source File: user.ts From typegraphql-nestjs with MIT License | 5 votes |
@Directive("@external")
@Field(type => ID)
id!: string;
Example #15
Source File: user.ts From typegraphql-nestjs with MIT License | 5 votes |
@Directive("@external")
@Field()
username!: string;
Example #16
Source File: cache.ts From backend with MIT License | 5 votes |
cacheAllFields = {
fields: {
_all: [Directive("@cacheControl(inheritMaxAge: true)")]
}
}