Skip to content

Commit

Permalink
Write a test for @CacheControl interaction between type and interface
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-scheer committed Aug 7, 2024
1 parent d8e6da5 commit b66f889
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,58 @@ describe('@cacheControl directives', () => {
);
});

it('interaction between type implementing interface, both with specified `maxAge`', async () => {
const schema = buildSchemaWithCacheControlSupport(`
type Query {
droid(id: ID!): Droid
named: Named
}
type Droid implements Named @cacheControl(maxAge: 30) {
id: ID!
name: String!
}
interface Named @cacheControl(maxAge: 60) {
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 }]]),
);
});

it('inheritMaxAge', async () => {
const schema = makeExecutableSchemaWithCacheControlSupport({
typeDefs: `#graphql
Expand Down

0 comments on commit b66f889

Please sign in to comment.