Process typePolicies lazily, upon first access by getTypePolicy.
Process typePolicies lazily, upon first access by getTypePolicy.

Passing typePolicies to the InMemoryCache constructor is something that
typically happens during application startup, so it's important that the
processing of typePolicies does not become a performance problem.

Fortunately, we don't have to do all the processing of typePolicies until
we actually look up a given type policy for the first time, which might
occur much later in the lifetime of the application for some types.

Once we implement inheritance of typePolicies, there will often be
supertype-subtype relationships among the types listed in typePolicies.
Without the laziness introduced by this commit, it would be necessary
either to keep typePolicies in supertypes-before-subtypes (topological)
order, or for addTypePolicies somehow to sort the types topologically.

Fortunately, that careful ordering/sorting becomes completely unnecessary
thanks to the laziness, because none of the types can be used until all of
them have been registered.

apollographql/apollo-client,apollographql/apollo-client