Score:0

Paragraphs removed from graphql schema if not anywhere in content, which causes error for union type

ca flag

I'm making a headless Drupal site with Gatsby using paragraphs. I'm experienced with Drupal but relatively new with gatsby/graphql.

The issue I'm running into is that if our database does not actually have any instances of a paragraph, then it generates the schema without that (i guess it generates a minimal schema based on what exists, not what types are actually possible) and it errors out because it's not an allowed type in the schema when it gets to that paragraph in my graphql union type.

enter image description here

I'm getting around this currently by making sure there's a node with content with all the possible paragraphs (or referenced nodes for entity reference fields). Everything works then, but this is a bad solution, especially for a site that'll eventually be handed off to a client. I feel like there's gotta be a way to make them optional in graphql or not break the build if one paragraph doesn't exist in content.

I know I can customize the schema, but some content types have 10-20 possible paragraphs and that'd just get insane if I had to manually maintain the schema when it's so close to what I need automatically.

Any help would be greatly appreciated. Thanks!

Score:0
cn flag

This may help: https://medium.com/@Zepro/contentful-reference-fields-with-gatsby-js-graphql-9f14ed90bdf9

Just wrap your GraphQL fragments into a Node-type.

enter image description here

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.