Skip to content

Commit

Permalink
Revert most of previous commit
Browse files Browse the repository at this point in the history
Turns out this would break using the cache control plugin (which is
installed by default) with old gateways. To be fair, it doesn't do much
with old gateways! But it would crash.

Do leave around the change to use the LRU cache for
info.cacheControl.cacheAnnotationFromType though, so 3.1.0 still
fixes #5532.
  • Loading branch information
glasser committed Jul 23, 2021
1 parent 3c91847 commit bb00b8b
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions packages/apollo-server-core/src/plugin/cacheControl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,26 @@ export function ApolloServerPluginCacheControl(
return 'CacheControl';
},

async serverWillStart() {
return {
async schemaDidLoadOrUpdate({ apiSchema }) {
// Set the size of the caches to be equal to the number of composite types
// and fields in the schema respectively. This generally means that the
// cache will always have room for all the cache hints in the active
// schema but we won't have a memory leak as schemas are replaced in a
// gateway.
typeAnnotationCache.max = Object.values(
apiSchema.getTypeMap(),
).filter(isCompositeType).length;
fieldAnnotationCache.max =
Object.values(apiSchema.getTypeMap())
.filter(isObjectType)
.flatMap((t) => Object.values(t.getFields())).length +
Object.values(apiSchema.getTypeMap())
.filter(isInterfaceType)
.flatMap((t) => Object.values(t.getFields())).length;
},
};
async serverWillStart({ schema }) {
// Set the size of the caches to be equal to the number of composite types
// and fields in the schema respectively. This generally means that the
// cache will always have room for all the cache hints in the active
// schema but we won't have a memory leak as schemas are replaced in a
// gateway. (Once we're comfortable breaking compatibility with
// versions of Gateway older than 0.35.0, we should also run this code
// from a schemaDidLoadOrUpdate instead of serverWillStart. Using
// schemaDidLoadOrUpdate throws when combined with old gateways.)
typeAnnotationCache.max = Object.values(schema.getTypeMap()).filter(
isCompositeType,
).length;
fieldAnnotationCache.max =
Object.values(schema.getTypeMap())
.filter(isObjectType)
.flatMap((t) => Object.values(t.getFields())).length +
Object.values(schema.getTypeMap())
.filter(isInterfaceType)
.flatMap((t) => Object.values(t.getFields())).length;
return undefined;
},

async requestDidStart(requestContext) {
Expand Down

0 comments on commit bb00b8b

Please sign in to comment.