Skip to content

v1.5.0 Add types for this.db and this.context #69

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 4 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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