Creating the song DTO and decorating it for GraphQL

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 @Field to let GraphQL take those into account as well.

When no value is passed to @Field(), the property is considered a string.

With that done, we're ready to implement the song resolver.