Skip to content

Commit

Permalink
v1.5.0 Add types for this.db and this.context (#69)
Browse files Browse the repository at this point in the history
Co-authored-by: Charles Burgess <consulting@cvburgess.com>
  • Loading branch information
astorije and cvburgess authored Aug 9, 2021
1 parent 2bce444 commit 4e4ab7a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.5.0 - 08-09-2021

- Add types for `this.db` and `this.context` ( Thanks @astorije )

## v1.4.1 - 04-09-2021

- Support GraphQL versions >= v14
Expand Down
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ declare module "knex" {
}
}

export class SQLDataSource extends DataSource {
export class SQLDataSource<TContext = any> extends DataSource<TContext> {
protected context: TContext;
protected knex: Knex;
protected db: Knex;
constructor(config: Knex.Config | Knex);
}
14 changes: 13 additions & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ import { expectError, expectType } from "tsd";
import Knex from "knex";
import { SQLDataSource } from "./index";

interface MyTestContext {
foo: string;
}

type MyRow = { id: string; value: number };
class MyTestDataSource extends SQLDataSource {
class MyTestDataSource extends SQLDataSource<MyTestContext> {
public testKnexExists() {
expectType<Knex>(this.knex);
}

public testDbExists() {
expectType<Knex>(this.db);
}

public testContextExists() {
expectType<MyTestContext>(this.context);
}

public async testCacheFunctionPassesResult() {
expectType<MyRow[]>(
await this.knex<MyRow>("mytable")
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "datasource-sql",
"version": "1.4.1",
"version": "1.5.0",
"description": "SQL DataSource for Apollo GraphQL projects",
"main": "index.js",
"typings": "index.d.ts",
"types": "index.d.ts",
"scripts": {
"lint": "prettier '**/*.js' && eslint '**/*.js'",
"lint:fix": "prettier --write '**/*.{js,ts}' && eslint --fix '**/*.js'",
Expand Down

0 comments on commit 4e4ab7a

Please # to comment.