Can the plugin support getFields() in GraphQLResponseProjection?
See original GitHub issueDiscussed in https://github.com/kobylynskyi/graphql-java-codegen/discussions/984
<div type='discussions-op-text'>Originally posted by ruipliu July 22, 2022 This is to support complex use cases from client side building queries.
Now the response projections only have builder methods to add fields. But in client side there are certain business needs to dynamically build queries. The current client practice is creating the response projections and adding the fields in one time, which is hard coding. Could the plugin support getFields()
in GraphQLResponseProjection
for clients to access the fields
in response projection after they created?
Here is an example:
Consider the [User - Order - Product] model.
- Use case 1: load ‘user.orders.products.name’ for each getUser query
- Use case 2: load ‘user.orders.status’ and ‘user.orders.products.status’ for each getUser query
- etc
In the client application, we might need data in
use case 1
oruse case 2
oruse case 1 & 2
. Hence we need to write 3UserResponseProjection
. If we have 10 use cases and their combinations exploded, we would prefer having aUserResponseProjection
for each use case and combine these projections if we want to load fields in multiple use cases, which needs the fields attribute accessible.</div>
Issue Analytics
- State:
- Created a year ago
- Comments:13 (4 by maintainers)
Top GitHub Comments
@ruipliu, thanks for your response.
To your 1st point:
This should not be a problem. I think we can use a
LinkedHashMap
instead of aList
for storing response projection fields (for deduplication purposes): https://github.com/kobylynskyi/graphql-java-codegen/blob/7364f7dd7d5696f73667f713e3a8e30a526d2326/src/main/java/com/kobylynskyi/graphql/codegen/model/graphql/GraphQLResponseProjection.java#L13To your 2nd point:
What do you mean by
hard code adding every fields
? Alsotake in a list of response projection and internally combine into one
- how does this become beneficial? Can you provide an example? Also, note that even today you can do the following:And with a “constructor” thing it will make a code cleaner by extending
proj2
by reusingproj1
:Do you see how we can make projections more reusable? Please provide code samples if you can.
Hi @kobylynskyi ,
There are two comments on your idea:
Please let me know your comment. Thanks.