Wp-graphql: orderby error

Created on 18 Jan 2019  路  2Comments  路  Source: wp-graphql/wp-graphql

Hi, experts, I just tried orderby feature, but got errors below. is that a known bug? Thanks for your help.

Query:

query Posts($orderby: [PostObjectsConnectionOrderbyInput],
  $status: PostStatusEnum
){
  posts(where: {status: $status, orderby: $orderby }){
    edges {
      node {
        id
      }
    }
  }
}

variables

{
  "orderby": {
    "field": "DATE",
    "order": "ASC"
  }
}

Error:

{
  "errors": [
    {
      "message": "Variable \"$orderby\" got invalid value {\"field\":\"DATE\",\"order\":\"ASC\"}.\nIn element #field: Expected \"PostObjectsConnectionOrderbyInput\", found not an object.\nIn element #order: Expected \"PostObjectsConnectionOrderbyInput\", found not an object.",
      "category": "graphql",
      "locations": [
        {
          "line": 29,
          "column": 13
        }
      ]
    }
  ]
}

Most helpful comment

@jimmyshen007 hey, you just need to update your variables to be an array, since you're telling the query to expect a list of inputs

change to:

{
  "orderby": [
    {
      "field": "DATE",
      "order": "ASC"
    }
  ]
}

All 2 comments

@jimmyshen007 hey, you just need to update your variables to be an array, since you're telling the query to expect a list of inputs

change to:

{
  "orderby": [
    {
      "field": "DATE",
      "order": "ASC"
    }
  ]
}

Cool! Thanks Jason. works for me!

Was this page helpful?
0 / 5 - 0 ratings