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

Problem sorting on fields using contentful #2024

Closed
jole78 opened this issue Sep 5, 2017 · 2 comments
Closed

Problem sorting on fields using contentful #2024

jole78 opened this issue Sep 5, 2017 · 2 comments

Comments

@jole78
Copy link

jole78 commented Sep 5, 2017

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"}.↵In field "fields": Expected type "ContentfulPersonConnectionSortByFieldsEnum", found "sort_order"."

Any ideas??

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

@KyleAMathews
Copy link
Contributor

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 graphql/graphiql#587

@jole78
Copy link
Author

jole78 commented Sep 5, 2017

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!!

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

No branches or pull requests

2 participants