1

I have a simple prisma.schema

model Joke {
  id      String @default(cuid()) @id
  author  Author
  content String @unique
}

model Author {
  id    String @default(cuid()) @id
  name  String
  jokes Joke[]
}

And this is my Query

t.list.field('getJokeByAuthor', {
    type: 'Joke',
    args: {
        name: stringArg(),
    },
    resolve: (_, {name}, ctx) => {
        return ctx.photon.authors.findMany({
            where: {
                name,
            },
            select: {
                jokes: true,
            },
        });
        // return ctx.photon.jokes.findMany({
        //   where: {
        //     author: {
        //       name,
        //     },
        //   },
        // });
    },
});

The commented one works while the uncommented doesn't & gives me error "Cannot return null for non-nullable field Joke.id.". Why? I want to access jokes by a particular author by calling ctx.photon.authors. How can I achieve that?

Also, getJokeByAuthor's return type is [Joke]? Where does it get that? Shouldn't it be [Author] now that I'm returning ctx.photon.authors?

deadcoder0904
  • 7,232
  • 12
  • 66
  • 163

0 Answers0