graphql-elixir / graphql

GraphQL Elixir
Other
859 stars 47 forks source link

FIX: Ordering of fields (WIP) #51

Closed freshtonic closed 8 years ago

freshtonic commented 8 years ago

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.

joshprice commented 8 years ago

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 commented 8 years ago

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 https://github.com/joshprice/graphql-elixir/pull/51#issuecomment-174092969 .

James

joshprice commented 8 years ago

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 < https://github.com/joshprice/graphql-elixir/pull/51#issuecomment-174092969

.

James

— Reply to this email directly or view it on GitHub https://github.com/joshprice/graphql-elixir/pull/51#issuecomment-174126783 .

freshtonic commented 8 years ago

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.