Skip to content

Commit ba0ccc0

Browse files
committed
v1.0.0 - fix redix
connects #31
1 parent 23e4965 commit ba0ccc0

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
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+
## v1.0.1 - 09-18-2019
4+
5+
- Fix issue with Redis keys and values
6+
37
## v1.0.0 - 09-17-2019
48

59
- Switch to an extended knex method (.cache) vs the old wrapper fns

index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const crypto = require("crypto");
12
const { DataSource } = require("apollo-datasource");
23
const { InMemoryLRUCache } = require("apollo-server-caching");
34
const Knex = require("knex");
@@ -32,13 +33,16 @@ class SQLDataSource extends DataSource {
3233
}
3334

3435
cacheQuery(ttl = 5, query) {
35-
const cacheKey = query.toString();
36+
const cacheKey = crypto
37+
.createHash("sha1")
38+
.update(query.toString())
39+
.digest("base64");
3640

3741
return this.cache.get(cacheKey).then(entry => {
38-
if (entry) return Promise.resolve(entry);
42+
if (entry) return Promise.resolve(JSON.parse(entry));
3943

4044
return query.then(rows => {
41-
if (rows) this.cache.set(cacheKey, rows, { ttl });
45+
if (rows) this.cache.set(cacheKey, JSON.stringify(rows), { ttl });
4246

4347
return Promise.resolve(rows);
4448
});

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": "1.0.0",
3+
"version": "1.0.1",
44
"description": "SQL DataSource for Apollo GraphQL projects",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)