Skip to content

Commit ea1fee3

Browse files
v2.1.0
- Resolve issue with .cache declaration (#84) Thanks @daniel-keller
1 parent 5208b32 commit ea1fee3

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v2.1.0 - 04-24-2023
4+
5+
- Resolve issue with .cache declaration (#84) Thanks @daniel-keller
6+
37
## v2.0.1 - 03-15-2022
48

59
- Update dependencies

index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ class SQLDataSource extends DataSource {
2222
}
2323

2424
this.knex = this.db;
25-
2625
const _this = this;
26+
27+
const cachefn = function(ttl) {
28+
return _this.cacheQuery(ttl, this);
29+
};
30+
2731
if (!this.db.cache) {
28-
Knex.QueryBuilder.extend("cache", function(ttl) {
29-
return _this.cacheQuery(ttl, this);
30-
});
32+
// Extend modifies Knex prototype to include cache method.
33+
// Does not retroactively add cache to existing connection.
34+
Knex.QueryBuilder.extend("cache", cachefn);
35+
// Must be manually added to existing knex connection.
36+
this.db.cache = cachefn;
3137
}
3238
}
3339

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "datasource-sql",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "SQL DataSource for Apollo GraphQL projects",
55
"main": "index.js",
66
"types": "index.d.ts",

0 commit comments

Comments
 (0)