Experimental Subschema empty interface#5184
Open
tomgasson wants to merge 2 commits intofacebook:mainfrom
Open
Conversation
Interfaces that are only reached via inline fragments on implementing types end up with missing or zero fields in the generated sub-schema. The snapshots capture the current (broken) behavior: - interface_empty_without_id: `interface Searchable` has zero fields - interface_only_inline_fragments: `interface Node` missing `createdAt` - interface_on_object_field: `interface FeedItem` missing `title` - interface_nested: `interface Event` missing `name`
Add a `backfill_empty_interfaces` option to UsedSchemaCollectionOptions. When enabled, after the IR walk completes, any interface that ended up with zero fields gets all its fields touched from the full schema. This handles the case where an interface is referenced as a return type (so it must exist in the sub-schema) but is only accessed via inline fragments on implementing types (so no fields were directly selected on it). Without this, the output contains `interface Foo` with no fields — invalid per the GraphQL spec. Interfaces that already have at least one field are left alone, so this only kicks in for the truly empty case. Enabled for experimental-regenerate-sub-schema.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In order to work out what part of our very large schema is actually being used by our products, we've been exploring using the subschema extraction. Our intent is to identify dead / unused schema and make our breaking changes detection & test selection more fine-grained (specific to the consuming product)
We've run into a problem of producing invalid schema.
schema
usage
output
which is invalid, since
Searchablehas no fields.Searchablebecause it appears as an output type ofQuery.search: Searchableand changing that would change the schema__typename(which is effectively what happens at runtime) because__is reservedThis PR implements a "fix": If we find empty interfaces, we force their fields existence (and hence their implementing concrete types to have those fields). This means we do have "unused fields", but only for these cases.
Not ideal, however this only occurs 12 times for us so is acceptable, and I expect it's not encountered in Meta's schema if it's not yet addressed.