Unlock seamless workflows and faster delivery with our latest releases – get the details

Issue with getting data from an array in Sanity to Gatsby, but problem was resolved.

6 replies
Last updated: Apr 1, 2020
Hello, I am trying to get some data from an array (and then array data from that array) in sanity to Gatsby, but I can’t figure out how to get the data in GraphiQL
I’m calling my object containing an array in my document like so

{

title: "Audit levels",

name: "auditLevels",

type: "array",

of: [{ type: "acccessibilityAuditCollection" }]

},

my accessibilityAuditCollection looks like this

export default {

name: "acccessibilityAuditCollection",

title: "Accessibility audit product",

type: "document",


fields: [

{

name: "auditTitle",

title: "Title",

type: "string"

},

{

title: "Most sold product",

name: "released",

type: "boolean"

},

{

title: "Audit feature",

name: "smallAuditFeatures",

type: "array",

of: [{ type: "accessibilityAuditProductFeatures" }]

},

{

name: "auditButton",

title: "Audit level button text",

type: "string"

}

]

};

I can get all the data from my document except for the array object data, I’ve got this query in GraphiQL now (trying both all and the normal document fetch method)


query coursesPageQuery {

sanityAccessibilityAnalysis {

_rawAuditLevels

auditLevels {

auditButton

auditTitle

}

}

allSanityAccessibilityAnalysis {

nodes {

auditLevels {

auditTitle

auditButton

}

}

}

}
None of the fields return anything, any ideas? I’ve filled inn data into sanity (and ran graphql deploy)
Apr 1, 2020, 8:47 AM
acccessibilityAuditCollection is a document because I tried to change it to a document, it was originally an object and I’ve changed it back to an object, I saw no change from changing between object and document 🙂
Apr 1, 2020, 8:55 AM
Hey Andreas! Your document containing the
auditLevels
array is called
accessibilityAnalysis
, and it’s a document type, correct?
Have you tried adapting the query as follows?

allSanityAccessibilityAnalysis {
  edges {
    node {
      auditLevels {
        auditTitle
        auditButton
      }
    }
  }
}
Also, if the dataset is public and you have a playground, could you share the URL (in DM if you prefer)?
🙂
Apr 1, 2020, 10:29 AM
Btw, I see a spelling difference in your schema/queries between
acccessibilityAuditCollection
(acccessibility with 3x ‘c’) and
allSanityAccessibilityAnalysis
(accessibility with 2x ‘c’). Maybe that’s causing this?
Apr 1, 2020, 10:32 AM
Hello, There is only one of this document so I thought I did not need to use the “all” queries from graphiql, but as long as it works
Problem is that it still does not work, I tried your query, it did not work. “allSanityAccessibilityAnalysis” is the only accessibilityanalysis option avaialbe to my from graphiQL for the “all” options.

Been trying since yesterday to make this query work and have changed it allot during that time, but I just can’t get it to work at all
Apr 1, 2020, 11:27 AM
I solved the isseu, thank you Peter! Not sure how I solved it.I created new names for the auditLevels object, added new data, ran graphql deploy again and now it works
🙂
Apr 1, 2020, 11:32 AM
Looks like fortune is smiling upon you 😄 Glad you got it to work!
Apr 1, 2020, 11:36 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?