gatsby-uc / gatsby-uc/plugins

feat(gatsby-source-strapi): Generated Types

Open
#433 7 comments 2 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
JavaScript
Stars
57
Forks
37
PR merge metrics
No merged PRs in 30d

Description

The Readme states the following limitation:

> At the moment, fields that do not have at least one populated instance will not be created in the GraphQL schema. This can break your site when field values get removed. You may workaround with an extra content entry with all fields filled out.

The fact that a site can break (does not build successfully) in those situations has turned out to be very annoying to me, even if it can be avoided by the mentioned workaround. And it makes optional fields on single types practically infeasible.

I think it should be feasible and would greatly improve the quality of the plugin. I didn't find any feature request or discussion on this topic, so I am raising it here.

## Describe the solution you'd like

The plugin could explicitly generate data types based on the strapi schemas (which are already fetched [here](https://github.com/gatsby-uc/plugins/blob/f87a34e17df74fe0503a939f97a81a16a5c76941/packages/gatsby-source-strapi/src/gatsby-node.js#L40) I think) before generating the nodes, e.g. using the `createTypes` hook (see [Gatsby docs](https://www.gatsbyjs.com/docs/reference/graphql-data-layer/schema-customization/#creating-type-definitions)).

## Describe alternatives you've considered

The alternative suggested in the Readme (create "an extra content entry with all fields filled out") feels like a hack. It doesn't work for single-types. It would feel more intuitive, if an optional field in Strapi, could be treated as an optional field in Gatsby, too.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.