File tree Expand file tree Collapse file tree 3 files changed +12
-4
lines changed
Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 1+ const crypto = require ( "crypto" ) ;
12const { DataSource } = require ( "apollo-datasource" ) ;
23const { InMemoryLRUCache } = require ( "apollo-server-caching" ) ;
34const 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 } ) ;
Original file line number Diff line number Diff line change 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" : {
You can’t perform that action at this time.
0 commit comments