fix(gatsby): don't fail validation on fragments that are not used #24032
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.
Description
Just having
gatsby-transformer-sharp
installed (not even in gatsby-config) and not having any image nodes cause query-compiler to fail validation because we use prevalidate rules that includeKnownTypeNamesRule
on every extracted graphql document. This PR removes that rule from prevalidation.We also later run full validation on constructed document that stitches query and used fragments, so this PR doesn't completely removes it - it just makes sure that we run it only on fragments that are actually used (I added 2 tests to verify it - one for not used fragment that is using unknown type - which passes validation and one for used fragment that is using unknown type which errors out as expected)
gatsby-transformer-sharp
already define schema forImageSharp
so we should not see errors like that when it's actually added to gatsby-config, so this PR is mostly about frustrating issues when package is installed, but not used--edit - I just noticed to original issue was about contentful and not transformer-sharp ... and for it would also help to use schema customization for generic types like asset (still reasonable thing to do), but this seems to help in other cases (as described above for example)
Related Issues
Fixes #15397