Skip to content

Commit

Permalink
Honor overwrite default maxAge with maxAge=0 (Fixes #22) (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
edorivai authored and Evans Hauser committed Jul 3, 2018
1 parent 2668edb commit eb17936
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,33 @@ describe('@cacheControl directives', () => {
expect(hints).toContainEqual({ path: ['droid'], maxAge: 60 });
});

it('should overwrite the default maxAge when maxAge=0 is specified on the type', async () => {
const schema = buildSchema(`
type Query {
droid(id: ID!): Droid
}
type Droid @cacheControl(maxAge: 0) {
id: ID!
name: String!
}
`);

const hints = await collectCacheControlHints(
schema,
`
query {
droid(id: 2001) {
name
}
}
`,
{ defaultMaxAge: 10 },
);

expect(hints).toContainEqual({ path: ['droid'], maxAge: 0 });
});

it('should override the maxAge from the target type with that specified on a field', async () => {
const schema = buildSchema(`
type Query {
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-cache-control-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function mergeHints(hint: CacheHint, otherHint: CacheHint | undefined): CacheHin
if (!otherHint) return hint;

return {
maxAge: otherHint.maxAge || hint.maxAge,
maxAge: otherHint.maxAge !== undefined ? otherHint.maxAge : hint.maxAge,
scope: otherHint.scope || hint.scope
};
}

0 comments on commit eb17936

Please sign in to comment.