chax-at / prisma-filter

MIT License
38 stars 8 forks source link

Select fields and pagination aliases #3

Open PatrickMunsey opened 1 year ago

PatrickMunsey commented 1 year ago

Hi,

This looks like a great library. I've been experimenting with it and I'm wondering if there are any plans on adding a select field feature and eventaually something to accomodate cursor pagination. I'm looking at exploring this myself and was wondering if you could give me some guidance as I continue to wrap my head around things.

Some notes:

If I can figure it out in the meantime I'll make a pull request if you like. I'm also happy to pair with someone on your team if that appeals to you.

Thanks

Valerionn commented 1 year ago

Hey,

I'm happy to hear that you like this library. It has currently all features we need internally - but I'm happy to help to make it better if I have time :)

General response:

Trying to answer your questions specifically:

I've tried adding and/or subsbtituting the FindManyArgs type into the IGeneratedFilter interface and dependant types to get these extra select, include and cursor types from prisma to play with but with no success so far.

If you want to insert FindManyArgs instead of WhereInput, then something like this should be possible (untested, just an idea):

export type GeneratedFindOptions<TFindManyArgs extends { where: unknown; select: unknown; }> = {
  where: TFindManyArgs['where'];
  select: TFindManyArgs['select'];
  skip: number | undefined;
  take: number | undefined;
  // This can be "any" because we might order by relations, therefore this will be an object
  orderBy: Array<{ [p in keyof TWhereInput]?: FilterOrder | any }>;
};

and then you should be able to use it. In the future, we could maybe improve this, but it should work for now.

I would have to check all the usages in our current projects to see if changing it to <prismamodel>FindManyArgs would be possible everywhere (for version 3), but if there are no conflicts there, then I don't see a problem with changing it.

Field names specified within the select query field that are also within the compound keys array should added to an include query field in findOptions

Why do you want to add it to include in this case and not select as well?


If you have any other specific questions, then feel free to ask them and I'll try my best to answer them. I'll try to look into these topics (especially cursor paged pagination) myself aswell - but this might take some time.

PatrickMunsey commented 1 year ago

Hi,

I've just put together some changes that should add some of the above discussed functionality. I've submitted a pull request so you can see the changes and we can have a more in depth discussion.

Some further thoughts specifically to the points above:

I'll look into the curser pagination points tomorrow and let you know my thoughts

darr1s commented 1 year ago

Hi @Valerionn @PatrickMunsey any updates on merging this to main?