# Order of keys returned from apollo/client are changed

**URL:** <https://community.apollographql.com/t/order-of-keys-returned-from-apollo-client-are-changed/1344>\
**Category:** Client SDKs\
**Tags:** client, web\
**Created:** [September 10, 2021, 5:47pm UTC](https://community.apollographql.com/t/order-of-keys-returned-from-apollo-client-are-changed/1344 "2021-09-10T17:47:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Neel](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/tony_neel/32/885_2.png) [@Tony\_Neel](https://community.apollographql.com/u/Tony_Neel)\
**Post date:** [September 10, 2021, 5:47pm UTC](https://community.apollographql.com/t/order-of-keys-returned-from-apollo-client-are-changed/1344/1 "2021-09-10T17:47:24Z")

</div>

Hello,

I recently upgraded to using @apollo/client instead of @apollo/react-components and “@apollo/react-hooks”.

In doing so one of my implementation that depended on object key order was broken (for localization of json).

It seems the stored order of the keys in my returned data were changed to alphabetical order. Is there anything I can do to stop that from happening? Is this a bug that should be reported?

---

<div class="post-metadata">

**Author:** ![Tony\_Neel](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/tony_neel/32/885_2.png) [@Tony\_Neel](https://community.apollographql.com/u/Tony_Neel)\
**Post date:** [September 10, 2021, 6:19pm UTC](https://community.apollographql.com/t/order-of-keys-returned-from-apollo-client-are-changed/1344/2 "2021-09-10T18:19:48Z")

</div>

It appears changing the fetchPolicy to no-cache fixed this. Which is unfortunate since caching would have been nice.

---

<div class="post-metadata">

**Author:** ![kevin-lindsay-1](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/kevin-lindsay-1/32/694_2.png) [@kevin-lindsay-1](https://community.apollographql.com/u/kevin-lindsay-1)\
**Post date:** [September 11, 2021, 3:00pm UTC](https://community.apollographql.com/t/order-of-keys-returned-from-apollo-client-are-changed/1344/3 "2021-09-11T15:00:38Z")

</div>

Yeah my immediate guess is that the implementation of the cache uses a sorted map for a speed boost.

---

<div class="post-metadata">

**Author:** ![mindnektar](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/mindnektar/32/259_2.png) [@mindnektar](https://community.apollographql.com/u/mindnektar)\
**Post date:** [September 13, 2021, 7:32am UTC](https://community.apollographql.com/t/order-of-keys-returned-from-apollo-client-are-changed/1344/4 "2021-09-13T07:32:30Z")

</div>

Yep, and it causes naming consistency for the keys in the in-memory cache, no matter in what order the query variables are passed. You can check out the source code for an in-depth documentation: [apollo-client/object-canon.ts at main · apollographql/apollo-client · GitHub](https://github.com/apollographql/apollo-client/blob/main/src/cache/inmemory/object-canon.ts)

Aside from that, it is generally never a good idea to rely on a specific key order in javascript objects, see here for a good explanation why: [Does JavaScript guarantee object property order? - Stack Overflow](https://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order/38218582#38218582)

---

<div class="post-metadata">

**Author:** ![Tony\_Neel](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/tony_neel/32/885_2.png) [@Tony\_Neel](https://community.apollographql.com/u/Tony_Neel)\
**Post date:** [September 13, 2021, 2:47pm UTC](https://community.apollographql.com/t/order-of-keys-returned-from-apollo-client-are-changed/1344/5 "2021-09-13T14:47:55Z")

</div>

That is not the case anymore you can rely on it in es6 and later and I actually need it for localized objects.

In fact the graphql specification says that it will return in order when possible so this violates that contract. See here: [http://spec.graphql.org/](http://spec.graphql.org/) section 3.6

---

<div class="post-metadata">

**Author:** ![kevin-lindsay-1](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/kevin-lindsay-1/32/694_2.png) [@kevin-lindsay-1](https://community.apollographql.com/u/kevin-lindsay-1)\
**Post date:** [September 14, 2021, 12:05am UTC](https://community.apollographql.com/t/order-of-keys-returned-from-apollo-client-are-changed/1344/6 "2021-09-14T00:05:36Z")

</div>

Feel free to file a bug report in github.
