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

Generate WhereInput type and use outside of crud

Open thehappycoder opened this issue 4 years ago • 3 comments

Is it possible in 2020? I remember that wasn't possible the last time I tried nexus.

I've found nestjs-query that is able to generate such types and used them in custom queries. Would be awesome if nexus could do that as well.

thehappycoder avatar Dec 24 '20 07:12 thehappycoder

Still waiting for...

Fi1osof avatar Feb 22 '21 20:02 Fi1osof

It's amazingly already in there, at least I think it is, assuming you want to do something like this:

import {arg} from 'nexus'
t.int("numberOfFibbles", {
  args: {
    where: arg({ type: "FibbleWhereInput"})
  },
  async resolve(source, args, context) {
    const count = await context.prisma.fibble.count({where: args.where});
    return count;
  }
})

It seems arg({ type: "FibbleWhereInput"}) will give you access to any type currently in your schema

royletron avatar Feb 11 '22 12:02 royletron

will give you access to any type currently in your schema

Will, if FibbleWhereInput already registred. It will be only if you call before some like t.crud.fibbles(). This will generate FibbleWhereInput and yes, now you can use it like you said.

Fi1osof avatar Feb 12 '22 17:02 Fi1osof