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

Return result keys in the same order as the request #5011

Open
rmosolgo opened this issue Jul 5, 2024 · 0 comments · May be fixed by #5060
Open

Return result keys in the same order as the request #5011

rmosolgo opened this issue Jul 5, 2024 · 0 comments · May be fixed by #5060

Comments

@rmosolgo
Copy link
Owner

rmosolgo commented Jul 5, 2024

The spec says that response maps should have keys in the same order that the query requested fields (https://spec.graphql.org/draft/#sec-Serialized-Map-Ordering), but GraphQL-Ruby doesn't do that. Instead, it creates a Hash to store the result and writes keys as soon as they're available. Consequently, results from GraphQL-Ruby violate the spec: instead of coming back in the order requested by the client, they come back in a library-determined order.

The simplest implementation would be to make a new, properly ordered Hash, something like:

field_indexes = {}
ast_nodes.each_with_index { |node, idx| field_indexes[node.name] = idx }
ordered_result = result.sort_by { |k,v| field_indexes[k] } 

But I'll have to check the memory and runtime impact of adding that.

Fixes #4252

@rmosolgo rmosolgo linked a pull request Aug 12, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant