[Discussion] Feature: GraphQL schema snapshots for all data sources to solve undefined/empty data issues
See original GitHub issueDescription
Currently there are issues with GraphQL schemas produced from data sources where at the moment gatsby develop
or gatsby build
is executed the data shape is incomplete, parts are in an empty state or in a different type than they would be if the source data was filled out. Below are a few example issues…
- #3009 – WordPress data source with some properties set to
false
when empty even though they should be an object or null - #1517 & #2881– Contentful data source with some empty/undefined fields
It would be great if as the data shape evolves on the data source side, you could create test pages or pieces of content that are fully filled out, meaning no empty fields. Then on the Gatsby side you could run a cli command called something like gatsby snapshot-schemas
which would fetch the current data sources, run the source data through there regular plugin data normalization paths, run the data through the existing infer GraphQL schema code and then finally at the end take the schemas generated and save them off to a folder in /src
called schemas
.
On subsequent builds Gatsby could skip over inferring of the GraphQL schemas when it sees schemas defined in /src/schemas
. These schema snapshots could then committed into a sites repo and allow for data shape changes to require new snapshots instead of just data source changes. These schema snapshots open up many possibilities such as the validation of incoming data shape changes. Schema snapshot diffs could be shown in Gatsby CLI as well when gatsby snapshot-schemas
is ran again once initial schemas have been saved.
I would love some feedback on the idea itself from the contributors of the various source plugins. If the idea passes the smell test, I would like some feedback on what format the snapshots should be saved to. Maybe the GraphQL schema language using something like gestalt-graphql would be nice.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:49
- Comments:93 (47 by maintainers)
Top GitHub Comments
I’ve made some progress. Decided to go with gatsby specific approach for now (adding support for “forced types” in https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby/src/schema ) as I found it easier to work with than playing with graphql schema objects. I’ll try to clean up my code a bit so it would be more readable and create pull request this week to discuss it further there.
Just little sneak peak of results (imo quite promising): I’ve used https://github.com/gatsbyjs/gatsby-starter-blog and used frontmatter in posts to emulate some problems that can cause build errors caused by queries that don’t match schema:
Used type definitions:
Note: those don’t have to be full type definitions (f.e. in MarkdownRemark definition I just force type of frontmatter field to not rely on automatic type naming)
Here’s how frontmatter looks before using my changes (no
test
field, “bad” type offeaturedImage
field):And after:
@pieh have you had any time to refine this and start any development? 😁