hi everyone, I have a weird behavior on my query t...
# orm-help
o
hi everyone, I have a weird behavior on my query that returns a list of Albums, with an artist relation. I got null on artist field : here is my query and the schema :
Copy code
// query 
query {
  allAlbums {
    name
    artist {
      id
      lastName
    }
  }
}

// schema
model Artist {
  id        String  @id @default(cuid())
  firstName String
  lastName  String
  stageName String
  cover     String
  age       Int?
  biography String?
  song      Song[]
  album     Album[]
}

model Album {
  id       String  @id @default(cuid())
  name     String
  cover    String
  genre    Genre?  @default(POP)
  artistId String?
  artist   Artist? @relation(fields: [artistId], references: [id])
}
the query returns a list of albums but Artist is null, knowing that I have the artistId in the albums table in db… anyone can help please ?
d
Interesting... Did you remember to add a resolver for Album.artist?
💯 1
r
@Omar Harras yeah, could you share the resolvers if possible?
o
yes, here is the resolver for
allAlbums
query :
Copy code
allAlbums: async (parent, args, contect) => {
      const albums = await contect.Prisma.album.findMany();
      return albums;
    },
Am i missing something ?
r
And the resolver for
artist
?
o
I don’t have one, should i implement it for an albums query ?
r
Yes that would need to be implemented as albums would have to be fetched from a resolver. Or another thing you could do is :
Copy code
allAlbums: async (parent, args, contect) => {
      const albums = await contect.Prisma.album.findMany({ include: { artist: true } });
      return albums;
},
o
thank you @Ryan it works !
💯 1