From af9ed33f7d2820abb602cad92ffb3c195410f2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Wed, 4 Aug 2021 06:06:47 +0000 Subject: [PATCH 1/4] Use property types instead of typings, as instructed by `tsd` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Astori --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1f9de11..05fff19 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.4.1", "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'", From a3ae3f8451ea540e27cc1ff922105a1075aa16b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Wed, 4 Aug 2021 06:11:30 +0000 Subject: [PATCH 2/4] Add type for `this.db` alias of `this.knex` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Astori --- index.d.ts | 1 + index.test-d.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/index.d.ts b/index.d.ts index c361cfa..ba78bdc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -9,5 +9,6 @@ declare module "knex" { export class SQLDataSource extends DataSource { protected knex: Knex; + protected db: Knex; constructor(config: Knex.Config | Knex); } diff --git a/index.test-d.ts b/index.test-d.ts index 23b13b4..3c0d5c3 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -8,6 +8,10 @@ class MyTestDataSource extends SQLDataSource { expectType(this.knex); } + public testDbExists() { + expectType(this.db); + } + public async testCacheFunctionPassesResult() { expectType( await this.knex("mytable") From a04cbe64549f28f1b8c913e70d0fd066bef979c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Wed, 4 Aug 2021 06:20:59 +0000 Subject: [PATCH 3/4] Add type for `this.context` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Astori --- index.d.ts | 3 ++- index.test-d.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index ba78bdc..19b1e35 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,7 +7,8 @@ declare module "knex" { } } -export class SQLDataSource extends DataSource { +export class SQLDataSource extends DataSource { + protected context: TContext; protected knex: Knex; protected db: Knex; constructor(config: Knex.Config | Knex); diff --git a/index.test-d.ts b/index.test-d.ts index 3c0d5c3..5424263 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -2,8 +2,12 @@ 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 { public testKnexExists() { expectType(this.knex); } @@ -12,6 +16,10 @@ class MyTestDataSource extends SQLDataSource { expectType(this.db); } + public testContextExists() { + expectType(this.context); + } + public async testCacheFunctionPassesResult() { expectType( await this.knex("mytable") From f02bac82ee9f54c900afb8c7e8c023d5e9ef751c Mon Sep 17 00:00:00 2001 From: Charles Burgess Date: Mon, 9 Aug 2021 10:51:18 -0400 Subject: [PATCH 4/4] bump version --- CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe50cc5..e5a6d13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package-lock.json b/package-lock.json index 6b49277..d7f8bc6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "datasource-sql", - "version": "1.4.1", + "version": "1.5.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "datasource-sql", - "version": "1.4.0", + "version": "1.5.0", "license": "MIT", "dependencies": { "apollo-datasource": "^0.6.3", diff --git a/package.json b/package.json index 05fff19..2ce9994 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasource-sql", - "version": "1.4.1", + "version": "1.5.0", "description": "SQL DataSource for Apollo GraphQL projects", "main": "index.js", "types": "index.d.ts",