0

Anyone out there that has made the jump from gatsby-source-prismic to gatsby-source-prismic-graphql and know if the query structure and naming are the same.

For example I'm currently using something like the below for gatsby-source-prismic.

  export const query = graphql`
    query pageQuery($uid: String!) {
      page: prismicPageTemplate(uid: { eq: $uid }) {
        uid
        type
        data {
          title
          body {
            ... on PrismicPageTemplateBodyQuestionSlice {
              slice_type
              primary {
                name
                title {
                  html
                  text
                }
              }
            }
         }
      }
    }
}

I've read the docs of both plugins and have also seen others ask similar questions. The docs for gatsby-source-prismic has this included as their naming convention

All documents are pulled from your repository and created as prismic${contentTypeName} and allPrismic${contentTypeName}, where ${contentTypeName} is the API ID of your document's content type.

Would I have to re-write all my queries if I wanted to switch to gatsby-source-prismic-graphql or do they use the same convention for their naming ?

me-me
  • 5,139
  • 13
  • 50
  • 91

2 Answers2

1

The only difference i've been noticing is that queries made with gatsby-source-prismic-graphql add a 'prismic' field at the start of the queries. eg.

{
  prismic {
    allHomepages {
      edges {
        node {
          title
          description
        }
      }
    }
  }
} 

Whereas with gatsby-source-prismic that field is not available. This is just a first approach, making a simple query. I'm not aware if more complex, ones that go deeper into the documents (for calling Slices, or Link fields) queries are similar or even more different for each other. So this would be my first guess.

Pawichi
  • 66
  • 5
  • 1
    Thanks Paulina. I have a feeling the slices might be different. I was holding out on the change because my project is huge. If you get to adding a slice please let me know what the outcome was. But this is really helpful thanks. – me-me Oct 08 '19 at 14:21
  • 1
    I also noticed from your post that allHomepages is different. This would be allPrismicHomePage in gatsby-source-prismic ? – me-me Oct 08 '19 at 17:58
0

Here’s a more complex version of the query. I added the query name and two slices:

query MyHomeQuery {
  prismic {
    allHomepages {
      edges {
        node {
         title
         description
          body {
            ... on PRISMIC_HomeBodyText {
              type
              label
            }
            ... on PRISMIC_HomeBodyImage_with_caption {
              type
              label
            }
          }
        }
      }
    }
  }
}

And you’re correct. The name in gatsby-source-prismic would be allPrismicHomePage

Pawichi
  • 66
  • 5
  • 1
    Thanks @paulina this is great. I also see they use Snake case (or snake_case) for their slices. PRISMIC_ Wow this would mean a pretty big re-write of ones queries in Graphql from gatsby-source-prismic. Crazy! thank you again for this. – me-me Oct 09 '19 at 18:49