-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby): Schema rebuilding (#19092)
* Refactor example-value to support fast incremental rebuilding * Detect node structure changes incrementally (to avoid expensive checks later) * Track metadata for inference in the redux * New `rebuildWithTypes` API for incremental schema rebuilding * Schema hot reloading for `develop` * Move things around for better cohesion * Replace old `getExampleValue` with new APIs based on inference metadata * Cleanup / rename things for consistency * Proper handling of ADD_FIELD_TO_NODE action * Make sure stale inferred fields are removed from the schema * More tests to and related fixes to conflict reporting * Clear derived TypeComposers and InputTypeComposers on type rebuild * More tests for schema rebuilding * Delete empty inferred type * Refactor: use functions for field names generated out of a type name * More tests + switched to inline snapshots for tests readability * Support adding / deleting child convenience fields on parent type * Added nested extension test * Apply extensions and other special logic to all nested types * Make sure all derived types are processed on rebuild (including recursive) * Re-using common method in schema-hot-reloader * Test conflicts during rebuild-schema * Test incremental example value building * Tests for compatibility with schema customization * Parent type processing should not mess with child structure * Fix typo in comments Co-Authored-By: Michael <184316+muescha@users.noreply.github.com> * Moved `createSchemaCustomization` API call before node sourcing * Do not collect inference metadata for types with @dontInfer directive (or infer:false extension) * Use constants vs literal strings for extension names when analyzing type defs * Develop: reload eslint config on schema rebuild * Re-run queries on schema rebuild * Fix loki tests * Fix eslint error * Example value: do not return empty object * Updating tests structure * Split tests for sitepage and schema rebuild to separate files * Tests for rebuilding types with existing relations * Step back and use full schema rebuild (which is relatively fast with inference metadata) * Fix eslint errors * Fix invalid test * Take a list of types for inference from metadata vs node store * Handle DELETE_NODES action * Cleaning up a little bit * Fix loki reducer for DELETE_NODES action * More descriptive naming for eslint graphql schema reload * Fix invalid webpack compiler hook argument * Better detection of changed types to avoid unnecessary rebuilds * Add missing snapshot * Add new tests to clarify updating of ___NODE fields * Be a bit more defensive with haveEqualFields args * Re-run schema customization on __refresh * Rebuild schema on schema customization in develop (i.e. called via __refresh) * Add support for node update * Fix rebuildWithSitePage extensions
- Loading branch information
Showing
46 changed files
with
3,699 additions
and
728 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const { debounce, cloneDeep } = require(`lodash`) | ||
const { emitter, store } = require(`../redux`) | ||
const { rebuild } = require(`../schema`) | ||
const { haveEqualFields } = require(`../schema/infer/inference-metadata`) | ||
const { updateStateAndRunQueries } = require(`../query/query-watcher`) | ||
const report = require(`gatsby-cli/lib/reporter`) | ||
|
||
const inferredTypesChanged = (inferenceMetadata, prevInferenceMetadata) => | ||
Object.keys(inferenceMetadata).filter( | ||
type => | ||
inferenceMetadata[type].dirty && | ||
!haveEqualFields(inferenceMetadata[type], prevInferenceMetadata[type]) | ||
).length > 0 | ||
|
||
const schemaChanged = (schemaCustomization, lastSchemaCustomization) => | ||
[`fieldExtensions`, `printConfig`, `thirdPartySchemas`, `types`].some( | ||
key => schemaCustomization[key] !== lastSchemaCustomization[key] | ||
) | ||
|
||
let lastMetadata | ||
let lastSchemaCustomization | ||
|
||
// API_RUNNING_QUEUE_EMPTY could be emitted multiple types | ||
// in a short period of time, so debounce seems reasonable | ||
const maybeRebuildSchema = debounce(async () => { | ||
const { inferenceMetadata, schemaCustomization } = store.getState() | ||
|
||
if ( | ||
!inferredTypesChanged(inferenceMetadata, lastMetadata) && | ||
!schemaChanged(schemaCustomization, lastSchemaCustomization) | ||
) { | ||
return | ||
} | ||
|
||
const activity = report.activityTimer(`rebuild schema`) | ||
activity.start() | ||
lastMetadata = cloneDeep(inferenceMetadata) | ||
lastSchemaCustomization = schemaCustomization | ||
await rebuild({ parentSpan: activity }) | ||
await updateStateAndRunQueries(false, { parentSpan: activity }) | ||
activity.end() | ||
}, 1000) | ||
|
||
module.exports = () => { | ||
const { inferenceMetadata, schemaCustomization } = store.getState() | ||
lastMetadata = cloneDeep(inferenceMetadata) | ||
lastSchemaCustomization = schemaCustomization | ||
emitter.on(`API_RUNNING_QUEUE_EMPTY`, maybeRebuildSchema) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,3 +265,5 @@ exports.startWatchDeletePage = () => { | |
} | ||
}) | ||
} | ||
|
||
exports.updateStateAndRunQueries = updateStateAndRunQueries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.