Gatsby: Problem sorting on fields using contentful

Created on 5 Sep 2017  路  2Comments  路  Source: gatsbyjs/gatsby

Hey,

dunnow if this problem lies within contentful source plugin or in gatsby graphql but...

I have setup a content type called Person on contentful which has a field called sort_order which lets me sort persons...go figure.

So, running this query in the graphiql editor works fine...it returns the nodes in order.

  allContentfulPerson(sort: {fields: sort_order}) {
    edges {
      node {
        id
      }
    }
  }

response:

{
  "data": {
    "allContentfulPerson": {
      "edges": [
        {
          "node": {
            "id": "c1hg38X3g6U8GU6WYyAiCyO"
          }
        },
        {
          "node": {
            "id": "c5qkbSSBgzYuUcEw6qaOSmY"
          }
        },
        {
          "node": {
            "id": "c4ZamiQP07eas6c2eKSu4MA"
          }
        },
        {
          "node": {
            "id": "c5HcLEQSUPScemwkUqk6KGU"
          }
        },
        {
          "node": {
            "id": "c488zNxYiNyMUUqeAAkCcIi"
          }
        }
      ]
    }
  }
}

but if i copy that query into a page...something like:

export const pageQuery = graphql`
    query MedarbetarPageQuery {
        allContentfulPerson(sort: { fields: sort_order }) {
            edges {
                node { ....etc

I get this error:

"Argument "sort" has invalid value {fields: "sort_order"}.鈫礗n field "fields": Expected type "ContentfulPersonConnectionSortByFieldsEnum", found "sort_order"."

Any ideas??

"gatsby-source-contentful": "1.3.7",
"gatsby": "1.8.4"

Most helpful comment

Fields is a list so the query should be [sort_order]. I don't know why GraphiQL isn't enforcing that. I've filed an issue there https://github.com/graphql/graphiql/issues/587

All 2 comments

Fields is a list so the query should be [sort_order]. I don't know why GraphiQL isn't enforcing that. I've filed an issue there https://github.com/graphql/graphiql/issues/587

Thanks @KyleAMathews that worked like a charm...!! Agree that graphiql should have picked that up. Really getting used to copy/paste queries from graphiql to react components and they should work the same. Thanks again Kyle and great work with gatsby!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

theduke picture theduke  路  3Comments

jimfilippou picture jimfilippou  路  3Comments

rossPatton picture rossPatton  路  3Comments

signalwerk picture signalwerk  路  3Comments

mikestopcontinues picture mikestopcontinues  路  3Comments