Skip to content

Commit 4e4ab7a

Browse files
astorijecvburgess
andauthored
v1.5.0 Add types for this.db and this.context (#69)
Co-authored-by: Charles Burgess <[email protected]>
1 parent 2bce444 commit 4e4ab7a

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
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.5.0 - 08-09-2021
4+
5+
- Add types for `this.db` and `this.context` ( Thanks @astorije )
6+
37
## v1.4.1 - 04-09-2021
48

59
- Support GraphQL versions >= v14

index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ declare module "knex" {
77
}
88
}
99

10-
export class SQLDataSource extends DataSource {
10+
export class SQLDataSource<TContext = any> extends DataSource<TContext> {
11+
protected context: TContext;
1112
protected knex: Knex;
13+
protected db: Knex;
1214
constructor(config: Knex.Config | Knex);
1315
}

index.test-d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@ import { expectError, expectType } from "tsd";
22
import Knex from "knex";
33
import { SQLDataSource } from "./index";
44

5+
interface MyTestContext {
6+
foo: string;
7+
}
8+
59
type MyRow = { id: string; value: number };
6-
class MyTestDataSource extends SQLDataSource {
10+
class MyTestDataSource extends SQLDataSource<MyTestContext> {
711
public testKnexExists() {
812
expectType<Knex>(this.knex);
913
}
1014

15+
public testDbExists() {
16+
expectType<Knex>(this.db);
17+
}
18+
19+
public testContextExists() {
20+
expectType<MyTestContext>(this.context);
21+
}
22+
1123
public async testCacheFunctionPassesResult() {
1224
expectType<MyRow[]>(
1325
await this.knex<MyRow>("mytable")

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "datasource-sql",
3-
"version": "1.4.1",
3+
"version": "1.5.0",
44
"description": "SQL DataSource for Apollo GraphQL projects",
55
"main": "index.js",
6-
"typings": "index.d.ts",
6+
"types": "index.d.ts",
77
"scripts": {
88
"lint": "prettier '**/*.js' && eslint '**/*.js'",
99
"lint:fix": "prettier --write '**/*.{js,ts}' && eslint --fix '**/*.js'",

0 commit comments

Comments
 (0)