I recently tried using gatsby-plugin-schema-snapshot to create an explicit snapshot of the schema for a project that uses gatsby-source-contentful. This works as expected with the exception of LongText fields in Contentful. Per the documentation LongText fields should actually be an object rather than a string.
Generated type using gatsby-plugin-schema-snapshot for a field named body which is a LongText field in Contentful.
type contentfulPostBodyTextNode implements Node @dontInfer {
body: String
}
This causes the following part of the query to fail if the actual content doesn't exist:
body {
childMarkdownRemark {
timeToRead
html
excerpt(pruneLength: 320)
}
}
gatsby-plugin-schema-snapshot and add it to the gatsby-config.jsgatsby build and view the snapshot file createdcc @vladar @stefanprobst
Thanks, I'll look into this! If you check the field type for contentfulPostBodyTextNode.body in the graphiql ide (without gatsby-plugin-schema-snapshot) - is it defined as String?
@stefanprobst yes, contentfulPostBodyTextNode.body is defined as String without gatsby-plguin-schema-snapshot.

@stefanprobst is there any other useful info I can provide for this particular ticket?
Can you make a minimum reproduction? Then I can take a look. It is hard to help without actual code at hand.
@vladar
Sure, no problem. Apologies for the multi-step process but it is necessary since this involves Contentful. Let me know if this is helpful or if you need anything else.
git clone https://github.com/ryanwiemer/gatsby-starter-gcnsnapshot branch which has all dependencies updated and gatsby-plugin-schema-snapshot already set up.yarn setup to create the relevant content model and dummy contentyarn developyarn develop and you should receive an error:GraphQL request:30:9
29 | body {
30 | childMarkdownRemark {
| ^
31 | timeToRead
````
OK, I think I know what is going on here. Our printDefinitions won't print @childOf directive. As a result, convenience child fields (like childMarkdownRemark in this case) are not included in schema snapshots and still depend on the presence of data.
I do see related warnings in the console:
warn The type `contentfulPostBodyTextNode` does not explicitly define the field
`childMarkdownRemark`.
On types with the `@dontInfer` directive, or with the `infer` extension set to `false`,
automatically adding fields for children types is deprecated.
@ryanwiemer We should address this in the core but in the meantime, you could use @childOf directive manually for all types producing a warning like the one above.
Following worked for me with your repro:
// in site's gatsby-node.js:
exports.createSchemaCustomization = ({ actions }) => {
const typeDefs = `
type contentfulPostBodyTextNode implements Node
@childOf(types: ["ContentfulPost"]) {
id: ID!
}
type contentfulPageMetaDescriptionTextNode implements Node
@childOf(types: ["ContentfulPage"]) {
id: ID!
}
type contentfulPageBodyTextNode implements Node
@childOf(types: ["ContentfulPage"]) {
id: ID!
}
type contentfulPostMetaDescriptionTextNode implements Node
@childOf(types: ["ContentfulPost"]) {
id: ID!
}
type MarkdownRemark implements Node
@childOf(types: [
"contentfulPostBodyTextNode",
"contentfulPostMetaDescriptionTextNode",
"contentfulPageBodyTextNode",
"contentfulPageMetaDescriptionTextNode"
]) {
id: ID!
}
`
actions.createTypes(typeDefs)
}
Hiya!
This issue has gone quiet. Spooky quiet. 馃懟
We get a lot of issues, so we currently close issues after 30 days of inactivity. It鈥檚 been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!
Thanks for being a part of the Gatsby community! 馃挭馃挏
Most helpful comment
@ryanwiemer We should address this in the core but in the meantime, you could use
@childOfdirective manually for all types producing a warning like the one above.Following worked for me with your repro: