mos
mos

Reputation: 83

Configure gatsby-source-filestystem to query a single json file

I'm trying to follow the readme from https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-json

I have a links.json that contains a list of (external) Links that I want to query. For each of these links, I want to create a page. Now I'm trying to query the links with

{
  allLinksJson {
    edges {
      node {
        value
      }
    }
  }
}

which fails. According to this post on github, apparently my gatsby-source-filesystem isn't configured correctly. I tried with

{
  resolve: `gatsby-source-filesystem`,
  options: {
    path: `${__dirname}/src/data/links.json`,
    name: "links",
  },
},

but it didn't work. Unfortunately I cannot find any articles or documentation about how to make this work. Any help would be appreciated.

Upvotes: 1

Views: 1036

Answers (1)

bluprince13
bluprince13

Reputation: 5001

You don't need the full path to the json file. You also need to include gatsby-transformer-json plugin.

  plugins: [
    'gatsby-plugin-react-helmet',
    `gatsby-transformer-json`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `./src/data/`,
      },
    }
  ]

Upvotes: 1

Related Questions