-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning Relay-connection style responses from custom resolvers #247
Comments
This looks about right, usually what I tend to do is something like this: return ActivitiesViewConnection.createFromPromise(
(q) => this.customQueryService.customQuery(q),
query,
(q) => this.customQueryService.customCount(q),
); That way not all logic goes into the resolver but to it's query service instead. |
Thanks @TriPSs, that's good to know. However, there is a need for a utility function to create relay-connection style responses as the one used by Digging deeper I noticed that resolvers with UnionTypes are not supported, e.g.:
You cannot create Query Args Type from the Union Type. This error provides more detail:
It makes sense for this not to work (QueryArgsType function expects DTOs), I just want to point out that there are no options to handle this case and still maintain the same API with the other resolvers? Additionally, I looked into defining my types for PageInfo, Connection, Edges, and so on, but the issue is that it will clash with the predefined types by nestjs-query, and the internal implementations are not exported. btw, if this is currently not supported, but you can give me some helpful pointers I can contribute this functionality. |
Interesting, I think a union type could be supported but then you would need to overwrite a lot of the service etc.
We could checkout what you need exactly and just export them so it will make it easier for ppl to reuse, PR would awesome! |
Btw, maybe this is a noob question (this might give you some perspective on how to answer it xD) Let's start with a fresh plate and put aside the union types. Using
The issue is that we don't have access to the Adding the types manually will fail because they are already defined by nestjs-query, i.e. this is not possible:
So what options do we have for a custom nestjs resolver that doesn't use nestjs-query to return the same response types (Utilizing Connections, Edges, and Nodes)? Why do we need this? However you still want to expose a uniform API. i.e. pagination should be identical for resolvers defined by nestjs-query and by your custom resolvers in nestjs. Let me know if I can clarify this, and as soon as you give me some direction, I can get started on contributing. |
If I understand it correctly, you could just follow Custom Endpoints from the docs? There is explained on how to create the return type with page info etc, you are not required to use the To answer alteast one of your questions: we indeed to not export |
How to convert the result of the database into a relay-connection style response? This is a workaround that I am currently using:
I would prefer a cleaner way of mapping the result into a relay-connection style response
The text was updated successfully, but these errors were encountered: