Closed flexbox closed 2 years ago
Hey @flexbox,
That output from Gatsby doesn't look normal. Can you share your gatsby-source-prismic
plugin options from gatsby-config.js
? My initial guess is that Gatsby is inferring the types rather than using the Custom Type schemas from the schemas
plugin option.
In case you didn't already provide your schemas, here's some documentation on how to do so: https://github.com/angeloashmore/gatsby-source-prismic#providing-json-schemas
And how to query Rich Text fields: https://github.com/angeloashmore/gatsby-source-prismic#query-rich-text-fields
If you're using the <RichText>
component from prismic-reactjs
, you will need to query for the raw
field within a Rich Text field and pass that value to <RichText>
.
// gatsby-config.js
const {
prismicRepo,
releaseID,
accessToken,
} = require("./prismic-configuration")
const siteConfig = require("./siteConfig")
const linkResolver = require("./src/utils/linkResolver")
const reponame = process.env.PRISMIC_REPO_NAME || prismicRepo
const apiKey = process.env.PRISMIC_API_KEY || accessToken
const prismicReleaseID = process.env.PRISMIC_RELEASE_ID || releaseID
const blogPostSchema = require("./custom_types/blog_post.json")
const faqSchema = require("./custom_types/faq.json")
const gastbySourcePrismicConfig = {
resolve: "gatsby-source-prismic",
options: {
repositoryName: reponame,
accessToken: apiKey,
releaseID: prismicReleaseID,
prismicToolbar: true,
linkResolver: () => (doc) => linkResolver(doc),
schemas: {
blogPostSchema: blogPostSchema,
faqSchema: faqSchema,
},
},
}
module.exports = {
siteMetadata: {
...siteConfig,
},
plugins: [
gastbySourcePrismicConfig,
`gatsby-transformer-sharp`, // Needed for dynamic images
`gatsby-plugin-sharp`,
`gatsby-plugin-sitemap`,
...
]
}
And with your input I made some progress
prismicBlogPost(uid: { eq: $uid }) {
...PrismicPostFragment
dataRaw { <------ changed to dataRaw
content {
type
text
dimensions {
width
height
}
spans { <----- added these missing part
start
end
type
}
alt
copyright
url
}
}
}
but now I have another error 😅
element.data is undefined
Hey @flexbox, I'm so sorry that I missed your reply in my notifications. That query and error shows that Gatsby does not have the correct schema loaded.
dataRaw
is normally a JSON field which does not allow querying for fields within it. Because it allows you to do so, it means Gatsby is inferring the type.
My guess is that your Blog Post custom type's API ID is actually blog_post
and not blogPostSchema
. Can you update your gatsby-config.js
to use the following?
schemas: {
blog_post: blogPostSchema,
faq: faqSchema,
},
There's a call out to this issue in the README:
Note: The names of your schemas in the schemas object should be exactly the same as your custom type's API ID. For example, if your API ID is "blog-post", your key should be "blog-post", not "blog_post".
You can confirm your custom type's API ID by querying for its type
field.
Thanks! Let me know if this fixes the issue.
I'm going to close this issue as it is Gatsby-specific, but feel free to reply here and I'll check back. Or we can continue in the gatsby-source-prismic
repo as well.
Thanks!
Thank you for your time @angeloashmore and your answer 🚀 I need to work back on the project but as a freelance priorities changed 😅
Hey!
I am in the process of migrating from
gatsby-source-prismic-graphql
togatsby-source-prismic
I am almost done but I have a weird issue with
RichText render={content}
I got this data from the GraphQL query
And the error is this one
Do you have an idea on how to fix the problem?