question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Order of array with null keys

See original GitHub issue

Hi All

I have a query that returns an object witch contains an array. The items of the array have a predefined keys function that return null

For some of the objects the order of the array is not retained. (Actually it is reversed)

I have checked that the server returns the data in the correct order but the object returned from useQuery have them in the reverse order.

Find below the actual query. In the below query combinations in 2 of the 5 object returned are given in the reversed order. Also urql dev tools shows them in the correct order (When viewed inside explorer)

Any idea?

#import "./PurchasedScratchCardFragment.graphql"
#import "../../../graphql/AmountFragment.graphql"

query ScratchCards {
  scratchCards {
    id
    name
    background {
      width
      height
    }
    grid {
      rows
      columns
      x
      y
      width
      height
    }
    coverSmall {
      width
      height
    }
    coverLarge {
      width
      height
    }
    price {
      ...AmountFragment
    }
    mask {
      x
      y
    }
    maximumCombination {
      win {
        ...AmountFragment
      }
    }
    minimumCombination {
      win {
        ...AmountFragment
      }
    }
    combinations {
      count
      symbol
      profitability
      win {
        ...AmountFragment
      }
    }
    symbolIndexes
    purchases {
      ...PurchasedScratchCardFragment
    }
  }
}

And this is the relevant keys section

        keys: {
          ScratchCardMask: () => null,
          ScratchCardCombination: () => null,
          ScratchCardDimensions: () => null,
          ScratchCardGrid: () => null,
          Amount: () => null,
        }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zenioscommented, May 25, 2020

@kitten you were right i was doing a sort somewhere having the impression that sort does not modify the original array.

Really sorry!

0reactions
kittencommented, May 25, 2020

No worries! Glad we figured it out

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Sort Empty key & value in lower order if its null in php
i Need when [comment]='' Field is Null Then it Should be sort & it would result in lower order. Array Structure [0] =>...
Read more >
Sort an Array with NULL values coming last in JavaScript
To sort an array with NULL values coming last, call the `sort()` method on the array, passing it a function. The function defines...
Read more >
Sorting an array objects by property having null value in ...
Our function should sort the array such that all the objects having keys mapped to null are pushed to the end of the...
Read more >
Java 8 - How to sort List and Arrays with null values
We are going to sort list of Customer objects which contains null values according to their name in alphabetical order · Comparator. ·...
Read more >
Order of array with null keys #835 - urql-graphql/urql - GitHub
The items of the array have a predefined keys function that return null For some of the objects the order of the array...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found