omar-dulaimi / prisma-trpc-generator

Prisma 2+ generator to emit fully implemented tRPC routers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default Filters for FindMany

ibrahimyaacob92 opened this issue · comments

Problem

Filters for list (find many) are not appear out of the box

Suggested solution

Have default optional filters like Hasura where we can filters based on other fields (columns) and it should be as powerful like having equal, greater than, lesser than and like.

Hello @ibrahimyaacob92

I have heard of Hasura, but never really used it before. So, could you provide an example of what you want to achieve?

hi @omar-dulaimi, let me share you this, in Hasura, its building the graphql API automagically and it includes all the necessary filters that you can think of.

example below:

query listOfUsers{
  users{
    username
    email
    age
    address_state
    address_city

  }
}

i can actually filter all the users based on any field and any method (equal, greater than, less than, like..)
next, the ordering is also included! I could actually order the user list based on the date created or their username alphabetically,
last of all, pagination is also comes out of the box by setting the offset and limit on the variables

image

its going to be a very big thing if this library able to pull this off. let me know if you need more detail, i'm very much happy to help

Hey @ibrahimyaacob92

If I understood you correctly, I think what you want is already built and supported.

For example:

  .query("findManyCompany", {
    input: CompanyFindManySchema,
    async resolve({ ctx, input }) {
      const findManyCompany = await ctx.prisma.company.findMany(input);
      return findManyCompany;
    },
  })

The CompanyFindManySchema have the following keys, which can be used to filter the result:

where
orderBy
cursor
take
skip
distinct

If you go inside where, you could filter by field level as well. The operators you mentioned are also available, and they depend on the field type. This library was created to match Prisma's API.

Unless I got you wrong, please explain to me again :)

Closing for cleanup purposes. Feel free to comment to re-open.