diff --git a/.changeset/many-shirts-kneel.md b/.changeset/many-shirts-kneel.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/many-shirts-kneel.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/server/src/__tests__/plugin/cacheControl/cacheControlDirective.test.ts b/packages/server/src/__tests__/plugin/cacheControl/cacheControlDirective.test.ts index 8e543f086d6..a834d76663c 100644 --- a/packages/server/src/__tests__/plugin/cacheControl/cacheControlDirective.test.ts +++ b/packages/server/src/__tests__/plugin/cacheControl/cacheControlDirective.test.ts @@ -277,6 +277,81 @@ describe('@cacheControl directives', () => { ); }); + it('interaction between type implementing interface, both with specified `maxAge`', async () => { + const schema = buildSchemaWithCacheControlSupport(` + type Query { + named: Named + droid(id: ID!): Droid + alien(id: ID!): Alien + } + + interface Named @cacheControl(maxAge: 60) { + name: String! + } + + type Droid implements Named @cacheControl(maxAge: 30) { + id: ID! + name: String! + } + + type Alien implements Named { + id: ID! + name: String! + } + `); + + const hintsNamed = await collectCacheControlHints( + schema, + ` + query { + named { + ... on Droid { + id + name + } + } + } + `, + ); + + expect(hintsNamed).toStrictEqual( + new Map([['named', { maxAge: 60, scope: undefined }]]), + ); + + const hintsDroid = await collectCacheControlHints( + schema, + ` + query { + droid(id: 2001) { + id + name + } + } + `, + ); + + expect(hintsDroid).toStrictEqual( + new Map([['droid', { maxAge: 30, scope: undefined }]]), + ); + + const hintsAlien = await collectCacheControlHints( + schema, + ` + query { + alien(id: 3001) { + id + name + } + } + `, + { defaultMaxAge: 10 }, + ); + + expect(hintsAlien).toStrictEqual( + new Map([['alien', { maxAge: 10, scope: undefined }]]), + ); + }); + it('inheritMaxAge', async () => { const schema = makeExecutableSchemaWithCacheControlSupport({ typeDefs: `#graphql