Skip to content

Commit c0ade15

Browse files
v1.4.0 TS Support (#61)
Co-authored-by: Charles Burgess <[email protected]>
1 parent e8ec8f1 commit c0ade15

File tree

6 files changed

+1384
-51
lines changed

6 files changed

+1384
-51
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.4.0 - 03-27-2021
4+
5+
- Add Typescript types ( Thanks @freshollie )
6+
37
## v1.3.1 - 12-11-2020
48

59
- Various dependency security updates via dependabot

index.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

index.test-d.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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());

0 commit comments

Comments
 (0)