Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

FIX: Ordering of fields (WIP) #51

Closed
wants to merge 1 commit into from

Conversation

freshtonic
Copy link
Contributor

NOTE: this is a WIP commit to solicit feedback only. It is far from complete.

The GraphQL spec says the order of the fields in the output should match
the order specified in the query.

Maps in Elixir do not provide a way to traverse the keys in source
order and maps are currently used to hold fields in query definitions
and during execution.

This means order of fields in the output is non-deterministic right now.

The fix for this is to use keyword lists instead of maps in query
definitions and during execution.

A further complication is that Poison (used in the plug) cannot encode
keyword lists, so we'd need to have some alternative solution for
transforming the literal query results into JSON.

The GraphQL spec says the order of the fields in the output should match
the order specified in the query.

Maps in Elixir do not provide a way to traverse the keys in source
order and maps are currently used to hold fields in query definitions
and during execution.

This means order of fields in the output is non-deterministic right now.

The fix for this is to use keyword lists instead of maps in query
definitions and during execution.

A further complication is that Poison (used in the plug) cannot encode
keyword lists, so we'd need to have some alternative solution for
transforming the literal query results into JSON.
@joshprice
Copy link
Member

I couldn't find where in the spec the order matters, but this: http://facebook.github.io/graphql/#sec-Evaluating-a-grouped-field-set states the opposite

@freshtonic
Copy link
Contributor Author

I assumed from the GitHub issue that that was the case without checking the
facts. No worries then 😀

On Saturday, 23 January 2016, Josh Price notifications@github.com wrote:

I couldn't find where in the spec the order matters, but found this:
http://facebook.github.io/graphql/#sec-Evaluating-a-grouped-field-set
which states the opposite


Reply to this email directly or view it on GitHub
#51 (comment)
.

James

@joshprice
Copy link
Member

Might be worth double-checking the spec since I have a hunch that section I
linked to doesn't actually apply to the fields.

On Sat, Jan 23, 2016 at 2:56 PM, James Sadler notifications@github.com
wrote:

I assumed from the GitHub issue that that was the case without checking the
facts. No worries the mn 😀

On Saturday, 23 January 2016, Josh Price notifications@github.com wrote:

I couldn't find where in the spec the order matters, but found this:
http://facebook.github.io/graphql/#sec-Evaluating-a-grouped-field-set
which states the opposite


Reply to this email directly or view it on GitHub
<
#51 (comment)

.

James


Reply to this email directly or view it on GitHub
#51 (comment)
.

@freshtonic
Copy link
Contributor Author

So I double checked the spec and I couldn't find anything that says order matters.

See: https://facebook.github.io/graphql/#sec-Objects

GraphQL Objects represent a list of named fields, each of which yield a value of a specific type. Object values are serialized as unordered maps, where the queried field names (or aliases) are the keys and the result of evaluating the field is the value.

@freshtonic freshtonic closed this Jan 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants