November 2019
Beginner
804 pages
20h 1m
English
Now that we have our first module and our resolver, we need to create a Data Transfer Object (DTO) for songs. Create a song.dto.ts file under src/song.
Add the following contents to that file:
import { Field, ID, ObjectType } from 'type-graphql';
@ObjectType()
export class SongDto {
@Field(() => ID)
id: string;
@Field()
name: string;
@Field()
artistId: string;
@Field(() => Boolean)
hasLyrics: boolean;
@Field(() => [String])
genres: string[];
}
This is the basic definition of a song. Notice that we have decorated our class with the @ObjectType() decorator from the type-graphql library to configure this class as a type that GraphQL should consider.
Also, each field has been decorated with ...
Read now
Unlock full access