Replies: 1 comment 2 replies
-
Hi! Thanks for the detailed question. Yes, this is definitely what The existing alias support is backward ... IIRC I built it when I was at GitHub and we had internal queries that needed special handling on the server, so we controlled both client and server in that case 😅 I did find a way to make it work, where you split the current lookahead based on the currently-executing alias: https://gist.github.com/rmosolgo/364a1023d9167376160a45ea847e1d89 I'm sure that's not exactly what you had in mind, but hopefully it gives a clue -- using Would an approach like that work for you? |
Beta Was this translation helpful? Give feedback.
-
I'm looking to do some aggressive pre-fetching of data for my GraphQL queries. As far as I can see, the right way to do this is to use "lookahead" values to tell me the shape of the query beyond the current field. This will let me know all the queries that I need to run up-front. I can then store that data and have the graphql-ruby library go through and marshal the data that I've pre-fetched, resolving any additional fields as needed (which may perform additional data fetches, depending on the fields).
This seems to be pretty straightforward in the regular case. That is, with a query like:
I can see how I would construct the SQL query and wire everything together to do this.
However, once aliases are involved, I can't see how to do it. That is, a query like this seems harder:
I think my problem boils down to: alias information is not available on lookahead values.
In the documentation about lookahead there is a bit about aliases, but it seems to require you to know the aliases ahead of time. I can't see any way to get the alias of a given selection, and the code for
alias_selection
doesn't give me hope that this is easy. This doesn't make sense to me, because the client decides the aliases. I can't enumerate all possible aliases ahead of time, because any client can decide to use any name they like for a field, right?Am I missing something? Apart from this issue with aliases, the lookahead mechanism seems perfect for what I'm trying to do.
Beta Was this translation helpful? Give feedback.
All reactions