data not showing up from GraphQL query
See original GitHub issueI’m attempting to use gatsby-image
to pull in a single hero image inside of a component. My graphql query is following the instructions from the gatsby-image
README with the $hero
variable coming from frontmatter via context
in createPage
.
export default ({ data }) => {
return (
<div className="heroImg">
<Img sizes={data.file.childImageSharp.sizes} />
</div>
)
}
export const query = graphql`
query heroImageQuery($hero: String!) {
file(relativePath: { eq: $hero }) {
childImageSharp {
sizes(maxHeight: 350) {
...GatsbyImageSharpSizes_withWebp_tracedSVG
}
}
}
}
`
The issue is that data
is undefined. Not sure what I’m doing wrong here. If I run the query directly in GraphiQL with the image path hard coded from the value in $hero
it works fine.
query heroImageQuery {
file(relativePath: { eq: "images/heroes/portland-or-sign.jpg" }) {
childImageSharp {
sizes(maxHeight: 350) {
src
}
}
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Graphql query result returning correctly in the UI, but data ...
javascript - Graphql query result returning correctly in the UI, but data showing as "undefined" inside app - Stack Overflow. Stack Overflow ...
Read more >Five Common Problems in GraphQL Apps (And How to Fix ...
Schema duplication; Server/client data mismatch; Superfluous database calls; Poor performance; Boilerplate overdose. I'm willing to bet your app ...
Read more >GraphQL Queries to fetch data - Hasura
Try out GraphQL Query using GraphiQL. Simple and nested GraphQL query examples with parameters, arguments and variables to fetch data dynamically.
Read more >GraphQL schema basics
This schema defines a hierarchy of types with fields that are populated from your back-end data stores. The schema also specifies exactly which...
Read more >Queries and Mutations - GraphQL
On this page, you'll learn in detail about how to query a GraphQL server. Fields#. At its simplest, GraphQL is about asking for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@melissamcewen I ended up running the graphQL query in the template and passing the result down to my component via props so the component could use the data. Hope that helps.
@ataylorme how did you fix this? I’m running into the same problem