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

Spec: JSON object response keys should match request order #539

Open
olirice opened this issue Jul 4, 2024 · 0 comments
Open

Spec: JSON object response keys should match request order #539

olirice opened this issue Jul 4, 2024 · 0 comments
Assignees
Labels
GraphQL spec Relates to compliance with GraphQL spec

Comments

@olirice
Copy link
Contributor

olirice commented Jul 4, 2024

The GraphQL spec notes

Since the result of evaluating a selection set is ordered, the serialized Map of results should preserve this order by writing the map entries in the same order as those fields were requested as defined by selection set execution. Producing a serialized response where fields are represented in the same order in which they appear in the request improves human readability during debugging and enables more efficient parsing of responses if the order of properties can be anticipated.

Serialization formats which represent an ordered map should preserve the order of requested fields as defined by [CollectFields](https://spec.graphql.org/October2021/#CollectFields())() in the Execution section. Serialization formats which only represent unordered maps but where order is still implicit in the serialization’s textual order (such as JSON) should preserve the order of requested fields textually.

For example, if the request was { name, age }, a GraphQL service responding in JSON should respond with { "name": "Mark", "age": 30 } and should not respond with { "age": 30, "name": "Mark" }.

While JSON Objects are specified as an [unordered collection of key-value pairs](https://tools.ietf.org/html/rfc7159#section-4) the pairs are represented in an ordered manner. In other words, while the JSON strings { "name": "Mark", "age": 30 } and { "age": 30, "name": "Mark" } encode the same value, they also have observably different property orderings.

pg_graphql currently serializes with jsonb for efficiency.

Technically

Serialization formats which only represent unordered maps but where order is still implicit in the serialization’s textual order (such as JSON) should preserve the order of requested fields textually.

would not include JSONB. However, 90% of the users of this lib are accessing values as JSON via PostgREST so thats not a great answer.

This task is to check (and document here) the performance impact of using JSON vs JSONB

If the impact is small enough, updating the transpiler to make sure responses are all in the correct order

@olirice olirice added the triage-required Pending triage from maintainers label Jul 4, 2024
@olirice olirice self-assigned this Jul 4, 2024
@olirice olirice added GraphQL spec Relates to compliance with GraphQL spec and removed triage-required Pending triage from maintainers labels Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GraphQL spec Relates to compliance with GraphQL spec
Projects
None yet
Development

No branches or pull requests

1 participant