Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gatsby-plugin-schema-snapshot Issue with Contentful LongText fields #19674

Closed
ryanwiemer opened this issue Nov 20, 2019 · 9 comments · Fixed by #28483
Closed

gatsby-plugin-schema-snapshot Issue with Contentful LongText fields #19674

ryanwiemer opened this issue Nov 20, 2019 · 9 comments · Fixed by #28483
Labels
topic: GraphQL Related to Gatsby's GraphQL layer type: bug An issue or pull request relating to a bug in Gatsby

Comments

@ryanwiemer
Copy link
Contributor

Description

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)
  }
}

Steps to reproduce

  1. Select a project that uses at least one LongText field in Contentful
  2. Install gatsby-plugin-schema-snapshot and add it to the gatsby-config.js
  3. Run gatsby build and view the snapshot file created
  4. See how the LongText field is defined as a string rather than an object
@LekoArts LekoArts added the topic: GraphQL Related to Gatsby's GraphQL layer label Nov 26, 2019
@LekoArts
Copy link
Contributor

cc @vladar @stefanprobst

@stefanprobst
Copy link
Contributor

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?

@ryanwiemer
Copy link
Contributor Author

@stefanprobst yes, contentfulPostBodyTextNode.body is defined as String without gatsby-plguin-schema-snapshot.

contentfulPostBodyTextNode

@ryanwiemer
Copy link
Contributor Author

@stefanprobst is there any other useful info I can provide for this particular ticket?

@vladar
Copy link
Contributor

vladar commented Dec 18, 2019

Can you make a minimum reproduction? Then I can take a look. It is hard to help without actual code at hand.

@vladar vladar added the status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. label Dec 18, 2019
@ryanwiemer
Copy link
Contributor Author

@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.

Reproducible Test Case

  1. Clone this starter: git clone https://github.com/ryanwiemer/gatsby-starter-gcn
  2. Use the snapshot branch which has all dependencies updated and gatsby-plugin-schema-snapshot already set up.
  3. Sign up and create a new empty Contentful space
  4. Run setup script: yarn setup to create the relevant content model and dummy content
  5. Confirm everything works using yarn develop
  6. Log into Contentful and delete or archive the dummy content.
  7. Run yarn develop and you should receive an error:
Cannot query field "childMarkdownRemark" on type "contentfulPostBodyTextNode".

GraphQL request:30:9
29 |       body {
30 |         childMarkdownRemark {
   |         ^
31 |           timeToRead

@vladar
Copy link
Contributor

vladar commented Dec 19, 2019

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.

@vladar vladar removed the status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. label Dec 19, 2019
@vladar
Copy link
Contributor

vladar commented Dec 19, 2019

@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)
}

@github-actions
Copy link

github-actions bot commented Jan 9, 2020

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’s 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! 💪💜

@github-actions github-actions bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Jan 9, 2020
@vladar vladar added not stale type: bug An issue or pull request relating to a bug in Gatsby and removed stale? Issue that may be closed soon due to the original author not responding any more. labels Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: GraphQL Related to Gatsby's GraphQL layer type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants