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

Order of input object values #1524

Closed
kinglozzer opened this issue Feb 8, 2024 · 1 comment
Closed

Order of input object values #1524

kinglozzer opened this issue Feb 8, 2024 · 1 comment
Labels

Comments

@kinglozzer
Copy link

When InputObjectType values are parsed, they’re re-ordered to match the order they are set in the schema definition:

$fields = $type->getFields();
foreach ($fields as $fieldName => $field) {
if (array_key_exists($fieldName, $value)) {

We (Silverstripe framework) pass sort order args as input objects, e.g:

Query:

query ($sort: SortFields) {
  readObjects(sort: $sort) {
    created,
    name
  }
}

Variables:

{
  "sort": {
    "created": "ASC",
    "name": "ASC"
  }
}

If name was defined first in the schema for SortFields, the objects returned will come back in the wrong order as that is what comes through “first” in the resulting query.

Is this something that could be changed in this library? Are we misunderstanding how this ordering works/should we be using a different approach to ensure the order of these sort fields is preserved?

Thanks!

@LastDragon-ru
Copy link
Contributor

Is this something that could be changed in this library?

According to the spec

Input object fields may be provided in any syntactic order and maintain identical semantic mean

These two operations are semantically identical:

{
  nearestThing(location: { lon: 12.43, lat: -53.211 })
}
{
  nearestThing(location: { lat: -53.211, lon: 12.43 })
}

should we be using a different approach to ensure the order of these sort fields is preserved?

You can use array, but you probably will need to add some check to make sure that only one field passed (until @oneOf, #619). You can also check my package to see how we a doing it.

{
  "sort": [
    {"created": "ASC"},
    {"name": "ASC"}
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants