Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write a test for @cacheControl interaction between type and interface #7912

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/many-shirts-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down