nexus-prisma icon indicating copy to clipboard operation
nexus-prisma copied to clipboard

Filtering on relations

Open dimaip opened this issue 4 years ago • 2 comments

Perceived Problem

This plugin provides you with automatically generated resolvers for relation fields. But it would be nice if it provided you with some filtering options automatically generated for you, ideally exposing the whole querying api of Prisma (or at least some basic stuff).

Ideas / Proposed Solution(s)

E.g. check how TypeGraphQL does it: https://typegraphql.com/docs/prisma.html

dimaip avatar Jun 17 '21 13:06 dimaip

Maybe it should be added to the project roadmap next to relation ordering? https://github.com/prisma/nexus-prisma#midterm

iddan avatar Jun 22 '21 22:06 iddan

Is there currently any way to filter a relation that's automatically included in the Prisma request? It seems like my include > where clauses are being overwritten by the Nexus plugin and ignored. Let's say I have a User and Post models and a resolver that does:

const result = await prisma.user.findMany({ where: { userId }, include: { posts: { where: { something: 'impossible' }}}})
console.log(result) // [{ id, ... posts: [] }]
return result

And a query that does:

{
  posts {
    title
  }
}

But the response sent to the client is:

{
  posts: [plenty of posts]
}

How to filter them correctly?

Is there any workaround? If I change:

t.field(User.posts)

to:

t.list.nonNull.field('posts', { type: 'Post' })

Filtering works correctly.

verekia avatar Oct 07 '21 12:10 verekia