Open PatrickMunsey opened 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:
select
so I can understand your use-case to find a good implementation for this. I would guess some kind of dynamic data query similar to GraphQL in which the client specifies what fields can be selected? Maybe you have some example code for me how you would want the library to behave in a specific scenario?include
/select
because it assumes that you will specify it manually (because, if you want to process the query result, then you have to know what is included in the result which is not really possible if it's dynamic. That's why I'm asking for the specific use-case).DirectFilterPipe
(only one cursor type allowed) or something that the client hast to send as well? That's especially important, because you always have to sort by the cursor field (otherwise the results are unpredictable)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.
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:
select=firstName,lastName,roles.id
. This support both record fields and related record fields. This achieved what you suggested as some kind of dynamic data query similar to GraphQL in which the client specifies what fields can be selected. I'll look into the curser pagination points tomorrow and let you know my thoughts
Hi @Valerionn @PatrickMunsey any updates on merging this to main?
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:
string[]
which generates an array of all field names passed through the query stringselect: string[]
that are also within the keys array should be added to a select query field in findOptions<prismamodel>WhereInput
type is used to initialise the DirectFilterPipe instead of something like<prismamodel>FindManyArgs
which is making it hard for me to figure out how to add select and include fields with non-null type to generateQueryFindOptions and GeneratedFindOptions.<prismamodel>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.<prismamodel>FindManyArgs
type may also make it easier to add cursor handling functionality in the future?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