-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Alias nested fields #297
Comments
I'm curious to know more about your use case or what you mean when you talk about the schema blowing up. We actually considered adding something like this quite a while ago and decided against it because it added a lot of complexity and it was clear that the few use cases we had thought of were not worth it. For example, the query you suggest:
This is already valid GraphQL, aliasing the field Secondly, this would add quite a lot of complication to the execution logic. Currently the executor only need to consider a single object when executing one selection of fields within a I'd like to know more about what you mean by preventing a schema from blowing up. From what I understand from your proposal, this wouldn't make any alterations to the schema. You would still need to supply the full type for a "user" and for an "address". Instead this proposal just makes response formats more flexible, so a client of GraphQL could type |
re: my use case re: schema blow up ...ultimately we decided it was not a big deal to ask clients to fully type this out in exchange for keeping the whole thing simpler |
@leebyron I found this issue by searching for this feature, mostly to see if it was either already being considered or had been ruled out. My use case is aliasing relay connections to be able to do something like:
return
instead of
I could achieve the same result by adding the "lastComment" alias to the schema and implement it server-side, but I'd prefer to keep this client side. |
Yeah, unfortunately this could cause a host of problems. First and foremost would be it would break Relay. Relay depends on the edge/node structure for proper pagination through connections. If that's not a feature that you use, then you're certainly free to not use the Relay style connection models. They're a trade off between robust pagination and verbosity. Beyond anything Relay specific though, this creates a host of complexity problems for validation and execution of graphql queries. When weighing if this complexity is worth the value it produces, we've yet to see a case where true value is produced. Instead it's mostly being able to access "fooBar" instead "foo.bar" in the result, something that would be trivial for a client side transformation. |
I know this issue is old, but I landed on it trying to find a way to allow clients to control shape and I ended up creating graphql-leveler to make this possible. It provides the LevelerObjectType which is a drop-in replacement for GraphQLObjectType except that it adds a |
We also have this use case. In general flattening deeply nested queries in a similar syntax to Javascript destructuring would be brilliant. In the use case at hand it isn't to do with edges so much, though disposing of these as we aren't using Relay would be useful... Thanks so much. |
I also have this issue with Drupal GraphQL responses, which often includes nested "entity" objects. |
I have this use case. Would love to have one resolver that is flexible with params, then I can define one subfiled on a type, but alias it using params. Like etsy maybe could do a products resolver on a user like
|
Any progress with the support for aliasing nested queries just like in @acomito's use case? Is it possible? Thanks! |
Waiting for it too. |
I've noticed there's also the following solution: GraphQL Lodash https://github.com/APIs-guru/graphql-lodash, but I'm not sure if it is good or not. |
waiting for it, make it three |
Still waiting :D Thank you for all your work too |
It’s my first day looking at GraphQL and I already need this |
I just got here from a google search and we also have this scenario. In our case, we are using the Hasura GraphQL server and we have a few named queries. These are queries that we expose to our client app as a RESTful endpoint. We do this because we want our client app to only consume these specific object graph structure. If this request will be implemented, we can simplify the RESTful endpoint's response object structure by aliasing the nested fields. The main reason we are doing this is we want to reuse our existing GraphQL server and take advantge of the RESTful facade provided by Hasura. The client app is by design RESTful only. I'm not sure if my comment is valid for this issue thread but I am just interested on this feature and just sharing our use case. |
We have the exact same requirement... We also want to expose the REST endpoints by flattening some of the nested fields by giving an alias name to them. Do we have any updates for this? Example
Should give a response as
|
I really need this feature. Do we have any update on this? |
Would also like to see this feature. @prestifidibs any reason this is closed? Can we re-open it to get more eyes on it? |
I've needed this ever since I started working with GQL! Any updates? |
Currently, you can alias fields, but only on the same level.
But aliasing doesn't allow you to transform the response into different forms.
This feature would be helpful in order to remove code that imperatively maps these fields and/or prevent the graphql schema from blowing up.
The text was updated successfully, but these errors were encountered: