-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby): Schema rebuilding #19092
Merged
Merged
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
c795e47
Refactor example-value to support fast incremental rebuilding
vladar cefa829
Detect node structure changes incrementally (to avoid expensive check…
vladar 62687b8
Track metadata for inference in the redux
vladar bfde835
New `rebuildWithTypes` API for incremental schema rebuilding
vladar 6fa5089
Schema hot reloading for `develop`
vladar 5d17926
Move things around for better cohesion
vladar b703768
Replace old `getExampleValue` with new APIs based on inference metadata
vladar 2194c98
Cleanup / rename things for consistency
vladar d0de33b
Proper handling of ADD_FIELD_TO_NODE action
vladar 6df4358
Make sure stale inferred fields are removed from the schema
vladar 1c697a5
More tests to and related fixes to conflict reporting
vladar 066cca3
Clear derived TypeComposers and InputTypeComposers on type rebuild
vladar 2df65cd
More tests for schema rebuilding
vladar def3963
Delete empty inferred type
vladar c731ba2
Refactor: use functions for field names generated out of a type name
vladar 896a28c
More tests + switched to inline snapshots for tests readability
vladar c8eaa56
Support adding / deleting child convenience fields on parent type
vladar 7f50feb
Added nested extension test
freiksenet c52a0a6
Apply extensions and other special logic to all nested types
vladar 58d6da0
Make sure all derived types are processed on rebuild (including recur…
vladar 7cf7898
Re-using common method in schema-hot-reloader
vladar 565caa6
Test conflicts during rebuild-schema
vladar 28c3ce6
Test incremental example value building
vladar 69b2a1e
Tests for compatibility with schema customization
vladar 586e4df
Parent type processing should not mess with child structure
vladar f163551
Fix typo in comments
vladar ee8b840
Moved `createSchemaCustomization` API call before node sourcing
vladar bfe9b20
Do not collect inference metadata for types with @dontInfer directive…
vladar 5c41164
Use constants vs literal strings for extension names when analyzing t…
vladar 3f54f2c
Develop: reload eslint config on schema rebuild
vladar 9e7eea0
Re-run queries on schema rebuild
vladar 5dfb0f0
Fix loki tests
freiksenet 609c059
Fix eslint error
vladar bff333b
Example value: do not return empty object
vladar 178b269
Updating tests structure
vladar 8ca59e4
Split tests for sitepage and schema rebuild to separate files
vladar 99df433
Tests for rebuilding types with existing relations
vladar d2806c4
Step back and use full schema rebuild (which is relatively fast with …
vladar 74d0bd6
Fix eslint errors
vladar 305f2f7
Fix invalid test
vladar cf70e81
Take a list of types for inference from metadata vs node store
vladar 68cc607
Handle DELETE_NODES action
vladar 4a72c53
Cleaning up a little bit
vladar dc66d60
Fix loki reducer for DELETE_NODES action
vladar 6ab53ed
More descriptive naming for eslint graphql schema reload
vladar ef7cda7
Fix invalid webpack compiler hook argument
vladar 207f66b
Better detection of changed types to avoid unnecessary rebuilds
vladar e56380b
Add missing snapshot
vladar 55ca80e
Add new tests to clarify updating of ___NODE fields
vladar b66bbe7
Be a bit more defensive with haveEqualFields args
vladar 8801594
Re-run schema customization on __refresh
vladar fa8b8f6
Rebuild schema on schema customization in develop (i.e. called via __…
vladar ed356ce
Add support for node update
vladar f756d9e
Fix rebuildWithSitePage extensions
vladar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true and probably something we should just look into to debounce
API_RUNNING_QUEUE_EMPTY
event elsewhere (most systems that listen to that are also potentially expensive operations, so having global debounce would help)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, missed this comment, sorry. It makes sense. But I suggest doing this in a separate PR