You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-5Lines changed: 15 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,15 @@
2
2
3
3
This package combines the power of [Knex] with the ease of use of [Apollo DataSources].
4
4
5
-
**NOTE: THIS PACKAGE HAS OFFICIAL SUPPORT FOR POSTGRESQL AND SQLITE ONLY**
5
+
## BREAKING CHANGE IN v0.2.0
6
6
7
-
Other DBs will work, but they will return the default response from `knex.raw()` which may or may not be what you are expecting. I am working on support for other DBs, but if you want to open a PR, that helps!
7
+
Batching of queries is hacked together with `knex.raw()` - while this is not ideal, due to the way Knex works, I have not found a more consistent way to do this.
8
+
9
+
As such, when you use `getBatched` or `getBatchedAndCached` the result will not be the pretty, normalized output you may expect from Knex, it will be the raw output from your DB driver of choice as if you had run the query with `knex.raw()`.
10
+
11
+
**If you find a way to implement caching without using `knex.raw()` please open a PR!**
12
+
13
+
While I would love to spend more time investigating this, unfortunately my time is limited at the moment.
8
14
9
15
## Getting Started
10
16
@@ -33,7 +39,7 @@ class MyDatabase extends SQLDataSource {
33
39
constructor() {
34
40
super();
35
41
// Add your instance of Knex to the DataSource
36
-
this.knex= knex;
42
+
this.db= knex;
37
43
}
38
44
39
45
getUsers() {
@@ -43,13 +49,13 @@ class MyDatabase extends SQLDataSource {
43
49
// A promise without any caching or batching
44
50
return query;
45
51
46
-
// Batch the query with DataLoader
52
+
// Batch the query with DataLoader - RETURNS A RAW RESPONSE
47
53
returnthis.getBatched(query);
48
54
49
55
// Cache the result for 1 minute
50
56
returnthis.getCached(query, MINUTE);
51
57
52
-
// Batch the query and cache the result for 1 minute
58
+
// Batch the query and cache the result for 1 minute - RETURNS A RAW RESPONSE
53
59
returnthis.getBatchedAndCached(query, MINUTE);
54
60
}
55
61
}
@@ -85,6 +91,8 @@ This method accepts one parameter:
85
91
86
92
-`knexQuery`: <knexObject> A knex object that has not been then'd
87
93
94
+
**NOTE: This method will return the raw response from your DB driver.**
95
+
88
96
### Caching ( getCached )
89
97
90
98
If you were to make the same query over the course of multiple requests to your server you could also be making needless requests to your server - especially for expensive queries.
**NOTE: This method will return the raw response from your DB driver.**
128
+
119
129
### initialize
120
130
121
131
SQLDataSource creates a new SQLCache on every initialize call with the cache and context from Apollo Server so you never should be directly creating a new SQLCache.
0 commit comments