question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

data not showing up from GraphQL query

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
melissamcewencommented, Dec 26, 2017

@ataylorme how did you fix this? I’m running into the same problem

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found