Skip to content

Commit

Permalink
fix: use global caching TTL by default in resolver caching config (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
smccammon-amplify committed Nov 10, 2023
1 parent f80b6c6 commit 3634639
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
64 changes: 64 additions & 0 deletions src/__tests__/resolvers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,5 +1077,69 @@ describe('Resolvers', () => {
}
`);
});

it('should fallback to global caching TTL', () => {
const api = new Api(
given.appSyncConfig({
caching: {
behavior: 'PER_RESOLVER_CACHING',
ttl: 300,
},
dataSources: {
myTable: {
name: 'myTable',
type: 'AMAZON_DYNAMODB',
config: { tableName: 'data' },
},
},
}),
plugin,
);
expect(
api.compileResolver({
dataSource: 'myTable',
kind: 'UNIT',
type: 'Query',
field: 'user',
caching: {
keys: ['$context.identity.sub', '$context.arguments.id'],
},
}),
).toMatchInlineSnapshot(`
Object {
"GraphQlResolverQueryuser": Object {
"DependsOn": Array [
"GraphQlSchema",
],
"Properties": Object {
"ApiId": Object {
"Fn::GetAtt": Array [
"GraphQlApi",
"ApiId",
],
},
"CachingConfig": Object {
"CachingKeys": Array [
"$context.identity.sub",
"$context.arguments.id",
],
"Ttl": 300,
},
"DataSourceName": Object {
"Fn::GetAtt": Array [
"GraphQlDsmyTable",
"Name",
],
},
"FieldName": "user",
"Kind": "UNIT",
"MaxBatchSize": undefined,
"TypeName": "Query",
},
"Type": "AWS::AppSync::Resolver",
},
}
`);
});
});
});
2 changes: 1 addition & 1 deletion src/resources/Resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class Resolver {
} else if (typeof this.config.caching === 'object') {
Properties.CachingConfig = {
CachingKeys: this.config.caching.keys,
Ttl: this.config.caching.ttl || this.config.caching.ttl || 3600,
Ttl: this.config.caching.ttl || this.api.config.caching?.ttl || 3600,
};
}
}
Expand Down

0 comments on commit 3634639

Please sign in to comment.