Skip to content
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

Generate generic Pagination API for connections #639

Open
JLLeitschuh opened this issue Jan 6, 2024 · 5 comments
Open

Generate generic Pagination API for connections #639

JLLeitschuh opened this issue Jan 6, 2024 · 5 comments

Comments

@JLLeitschuh
Copy link

JLLeitschuh commented Jan 6, 2024

When attempting to simply using dgs for a code generator for API clients, there aren't great solutions for generating generic pagination APIs. Each connection type is unique, and there doesn't exist a common interface for all edge/node types.

If you enable generateKotlinClosureProjections but also attempt to do type mapping for simple list connections, eg...

typeMapping["RecipeRunHistoryConnection"] = "graphql.relay.SimpleListConnection<$packageName.types.RecipeRunHistoryEdge>"

Then the projection's don't get generated correctly (you lose the projections for edges), meaning you can't request paginated elements.

Overall, this results in a less than stellar experience for trying to use dgs for pure client side code

@srinivasankavitha
Copy link
Contributor

@mbossenbroek - could you please take a look when you get a chance?

@mbossenbroek
Copy link
Contributor

@JLLeitschuh you're right - when creating the projections I was converting the type to kotlin first & then deriving the name of the projection by picking the innermost type. Obviously this failed if it found a mapped generic type & picked the inner type of the edge instead of the connection.

This should fix it by looking instead at the name of the GQL type itself for determining the name of the projection, effectively ignoring the mapped types when building the client. I updated one of the examples to use the relay mapping as well to confirm the behavior: #642

@mbossenbroek
Copy link
Contributor

@srinivasankavitha looks like the build passed on that PR; feel free to merge/release at your convenience

@JLLeitschuh
Copy link
Author

Does SimpleListConnection work for client types? I'm hoping it does.

Also, couldn't DGS automatically detect pagination structures and auto-generate the correct paginated API for the model types?

@mbossenbroek
Copy link
Contributor

I'm not sure I follow what you mean by this:

Does SimpleListConnection work for client types?

You can specify that you'd like to use that class instead of the generated ones & it will put it in there. As to whether or not it deserializes correctly depends on the json library you're using.

Also, couldn't DGS automatically detect pagination structures and auto-generate the correct paginated API for the model types?

There is no specified "correct" paginated type as GQL doesn't specify that sort of thing. There are the relay types you found, which can certainly be used, but they have some faults of their own. Namely, they won't differentiate between explicit null fields and those that are simply not requested. Left alone, the code-gen will generate the appropriate pagination structures for a client without having to involve the relay classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants