File tree Expand file tree Collapse file tree 6 files changed +1384
-51
lines changed Expand file tree Collapse file tree 6 files changed +1384
-51
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+ ## v1.4.0 - 03-27-2021
4
+
5
+ - Add Typescript types ( Thanks @freshollie )
6
+
3
7
## v1.3.1 - 12-11-2020
4
8
5
9
- Various dependency security updates via dependabot
Original file line number Diff line number Diff line change
1
+ import Knex from "knex" ;
2
+ import { DataSource } from "apollo-datasource" ;
3
+
4
+ declare module "knex" {
5
+ interface QueryBuilder < TRecord extends { } = any , TResult = any > {
6
+ cache : ( ttl ?: number ) => QueryBuilder < TRecord , TResult > ;
7
+ }
8
+ }
9
+
10
+ export class SQLDataSource extends DataSource {
11
+ protected knex : Knex ;
12
+ constructor ( config : Knex . Config | Knex ) ;
13
+ }
Original file line number Diff line number Diff line change
1
+ import { expectError , expectType } from "tsd" ;
2
+ import Knex from "knex" ;
3
+ import { SQLDataSource } from "./index" ;
4
+
5
+ type MyRow = { id : string ; value : number } ;
6
+ class MyTestDataSource extends SQLDataSource {
7
+ public testKnexExists ( ) {
8
+ expectType < Knex > ( this . knex ) ;
9
+ }
10
+
11
+ public async testCacheFunctionPassesResult ( ) {
12
+ expectType < MyRow [ ] > (
13
+ await this . knex < MyRow > ( "mytable" )
14
+ . select ( "id" , "value" )
15
+ . where ( "id" , "1" )
16
+ . cache ( )
17
+ ) ;
18
+ }
19
+
20
+ public async testCacheFunctionAcceptsTTL ( ) {
21
+ expectType < MyRow [ ] > (
22
+ await this . knex < MyRow > ( "mytable" )
23
+ . select ( "id" , "value" )
24
+ . where ( "id" , "1" )
25
+ . cache ( 5 )
26
+ ) ;
27
+ }
28
+ }
29
+
30
+ new MyTestDataSource ( {
31
+ connection : {
32
+ port : 80 ,
33
+ host : "somethimg"
34
+ }
35
+ } ) ;
36
+
37
+ new MyTestDataSource (
38
+ Knex ( {
39
+ connection : {
40
+ port : 80 ,
41
+ host : "something"
42
+ }
43
+ } )
44
+ ) ;
45
+
46
+ expectError ( new MyTestDataSource ( "something not knex config" ) ) ;
47
+ expectError ( new MyTestDataSource ( ) ) ;
You can’t perform that action at this time.
0 commit comments