Alias field multiple times in one query doesn't seem to work #3669
Replies: 3 comments 6 replies
-
I am moving this to a discussion since I dont think this is a bug say. Do you have an example and examples of what errors you get back ? Read https://www.graphql-java.com/blog/deep-dive-merged-fields for some more background. I will come back with a more detailed reponse on aliases soon but if you can expand with examples that would be great |
Beta Was this translation helpful? Give feedback.
-
If you had
then this will fail with a validation error (as per spec)
but this will work because of aliasing
In this case the field is run twice by the engine. Are you not seeing this? |
Beta Was this translation helpful? Give feedback.
-
I think you need to stop using PropertyDataFetcher - it is basically looking into an object using the field name as the key You could use your own PropertyDataFetcher like DF that used alias then field name say if you wanted map like semantics BUT if you have arguments - you need code to interpret those arguments so I think custom DF code is what you need. Or are you talking about child DFs looking at a map created by the previous field? Can you give an expanded example please |
Beta Was this translation helpful? Give feedback.
-
The basic issue is that my schema has a generic field ("aggregate") which returns different things depending on arguments (it calculates various aggregation functions basically). Typically client will provide query with this field many times, with different arguments and different aliases.
But this doesn't seem to be supported by the default ExecutionStrategy, because it looks up DataFetcher based on field name and not field alias in query. The result is that the fetched data cannot return this field many times with the different variations. The data can only be provided with the original name, which therefore can only appear once (assuming Map<String,Object> with regular PropertyDataMatcher is used).
This basically seems like a design issue more than anything else. The assumption appears to be that the backend data returns the same data no matter the arguments, and so returning the same field many times in the same query with different arguments is simply not considered.
Have I understood it correctly? Or is there a way to have a query return the same field many times with different aliases and arguments that I have missed?
Beta Was this translation helpful? Give feedback.
All reactions