Variable $uid not provided for root slug

I'm using Gatsby with gatsby-prismic-source-graphql and automatically generating pages from my custom types with slugs built as /article/${uid}.

I'm getting an error in my query on the /article/ route:

Variable "$uid" of required type "String!" was not provided.

Obviously I don't expect the /article/ route to match any uid of my custom types. Is the expected behaviour to redirect to / ?

My query in article.js looks like this:

export const query = graphql`
  query PageQuery($uid: String!) {
    prismic {
      grid_image(uid: $uid, lang: "en-gb") {
        main_text
        title
        image
      }
    }
  }
`

and my pages config in gatsby-config.js:

pages: [{
  type: 'Grid_image',
  match: '/article/:uid',
  path: '/article',
  component: require.resolve('./src/pages/article.js'),
}],

Routes that do have uid's are working as expected with the correct data coming through e.g. at /articles/foo

Any ideas?

Hello @mrjib, welcome to the Prismic Community forum.

I just answered to a similar question in this thread. Give it a look and let me know if that helps!

1 Like

Hi @Pau. Sorry I didn’t see that thread!

The solution was to move my article page to the template folder and add validation checks to ensure preview routes were built correctly.

Could you point me to some docs that cover the plugin configuration and having a specific template folder? I noticed on the plugin docs on Gatsby (https://www.gatsbyjs.org/packages/gatsby-source-prismic-graphql/) that the pages all resolved to the templates folder but it isn’t said explicity that it’s necessary.

Thanks for the help!

I’m glad you found the solution!

That’s a good observation, because it is true. Dynamic pages can only be created under the templates folder.