-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove FragmentMatcher abstraction from apollo-cache-inmemory.
Correctly matching fragments against abstract types like unions or interfaces requires knowledge of the schema, which can be obtained in multiple ways. Previously, we provided two different FragmentMatcher implementations: the HeuristicFragmentMatcher, which would attempt to match fragments without any knowledge of the schema; and the IntrospectionFragmentMatcher, which would consume an introspection query result to obtain information about possible subtypes. This commit removes the FragmentMatcher abstraction and both of its implementations. Instead, you can skip the introspection query step and simply pass a possibleTypes map to the InMemoryCache constructor: new InMemoryCache({ addTypename: true, freezeResults: true, possibleTypes: { Animal: ["Cat", "Dog", "MiniatureHorse", "Frog"], Test: ["PassingTest", "FailingTest", "SkippedTest"], }, }) When you provide this information, assuming it is correct and complete, the cache does not need to make any heuristic guesses, so there's really no point in ever having other FragmentMatcher implementations. More importantly, to maintain backwards compability with the existing FragmentMatcher interface, the cache was forced to construct temporary data stores to trick the FragmentMatcher into doing the right thing. This commit is a breaking change that removes all that awkward logic. Of course, you have to get the possibleTypes map from somewhere, and schema introspection is still a fine way of doing that. However, the possibleTypes map is relatively easy to write by hand, if you're just prototyping/experimenting. Once you're ready to generate it automatically from your schema, it can be easily imported from a generated module. If the possibleTypes option is not specified, the cache will behave like the old HeuristicFragmentMatcher, which is adequate as long as you're not using fragments with abstract constraints.
- Loading branch information
Showing
19 changed files
with
276 additions
and
677 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
Oops, something went wrong.