I'm trying to use GraphQL fragments on a Gatsby site, I tried to follow guides to create this fragment but Gatsby throws an error stating that my fragment does not exist
The fragment "PageFragment" does not exist.
I located my fragment in a folder called "graphql-fragments" located in the root of the Gatsby project, this folder contains one file called "pageFragment.js" which is my fragment pageFragment.js
import { graphql } from "gatsby";
export const PageFragment = graphql`
fragment PageFragment on SanityPage {
slug {
current
}
_rawContent(resolveReferences: { maxDepth: 20 })
_id
title
}
`;
I use this fragment on my index page where I also get my error
import React from "react"
import { graphql } from "gatsby";
export const query = graphql`
query FrontpageQuery {
page: sanityPage(_id: { regex: "/(drafts.|)frontpage/" }) {
...PageFragment
}
}
`;
const Home = () => {
return (
<div>
Hello world
</div>
)
}
export default Home
Running the graphQL query without the fragment works fine, so this works and I am getting the data I expect
export const query = graphql`
query FrontpageQuery {
page: sanityPage(_id: { regex: "/(drafts.|)frontpage/" }) {
slug {
current
}
_rawContent(resolveReferences: { maxDepth: 20 })
_id
title
}
}
`;
It seems like Gatsby is not finding my fragment, any clues to what I'm doing wrong? Running on Gatsby version 2.24.66