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

[v2][gatsby-transformer-json] Querying images with relative path result in null #6367

Closed
fabe opened this issue Jul 10, 2018 · 4 comments
Closed

Comments

@fabe
Copy link
Contributor

fabe commented Jul 10, 2018

Description

I'm trying to use gatsby-image with gatsby-transformer-json by querying an image via its relative path:

content/index.json
{
  "image": "../images/example.jpg"
}

The image is successfully found and the GraphQL schema sees image as a type File, including the childImageSharp. However, when using GraphiQL and trying to access any property, image always returns null without errors.

screen shot 2018-07-10 at 10 19 13 am

Steps to reproduce

Example repo: https://github.com/fabe/test-gatsby-json-image

Use GraphiQL to query the image specified in the JSON content file.

{
  contentJson {
    image {
      id
    }
  }
}

Environment

  System:
    OS: macOS High Sierra 10.13.5
    CPU: x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 8.11.3 - /usr/local/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 5.6.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 67.0.3396.99
    Firefox: 61.0
    Safari: 11.1.1
  npmPackages:
    gatsby: next => 2.0.0-beta.20
    gatsby-image: ^2.0.0-beta.5 => 2.0.0-beta.5
    gatsby-plugin-sharp: ^2.0.0-beta.2 => 2.0.0-beta.2
    gatsby-source-filesystem: ^2.0.1-beta.3 => 2.0.1-beta.3
    gatsby-transformer-json: ^2.1.1-beta.2 => 2.1.1-beta.2
    gatsby-transformer-sharp: ^2.1.1-beta.3 => 2.1.1-beta.3
  npmGlobalPackages:
    gatsby-cli: 2.0.0-beta.2
@KyleAMathews
Copy link
Contributor

Hmm what happens if you have only one instance of gatsby-source-filesystem that's pointed at "src"? This shouldn't matter but perhaps theres a bug.

Also, can you verify that you can query "allFile" and see both files?

@fabe
Copy link
Contributor Author

fabe commented Jul 10, 2018

I'm getting the same result with only one instance pointed at src.

allFile works as expected, including the sharp processing:

screen shot 2018-07-10 at 11 11 00 am

@fabe
Copy link
Contributor Author

fabe commented Jul 16, 2018

It seems that gatsby-source-filesystem requires an absolute path to work, otherwise the images won't resolve correctly and show up as null, even though everything else works fine.

So instead of:

{
  resolve: `gatsby-source-filesystem`,
  options: {
    name: `content`,
    path: `./src/content`,
  },
},

use:

{
  resolve: `gatsby-source-filesystem`,
  options: {
    name: `content`,
    path: `${__dirname}/src/content`,
  },
},

Read the docs, I guess. 🤦‍♂️

@fabe fabe closed this as completed Jul 16, 2018
@codeincontext
Copy link

Damn, I did exactly the same thing and it took me days to work out why it was silently failing. Nice work @fabe

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

3 participants