From 1e9476d60b34a8b32cbc2b2e122ebdbdf4a6fac0 Mon Sep 17 00:00:00 2001 From: Max Gudkov <> Date: Mon, 5 Sep 2022 12:15:54 +1200 Subject: [PATCH 1/2] boolean query type --- src/http-data-source.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http-data-source.ts b/src/http-data-source.ts index be3ab2d..cd434f8 100644 --- a/src/http-data-source.ts +++ b/src/http-data-source.ts @@ -43,7 +43,7 @@ export type RequestOptions = Omit, 'origin' | 'path' | 'method' export type Request = { context: Dictionary - query: Dictionary + query: Dictionary body: T signal?: AbortSignal | EventEmitter | null json?: boolean @@ -107,7 +107,7 @@ export abstract class HTTPDataSource extends DataSource { this.logger = options?.logger } - private buildQueryString(query: Dictionary): string { + private buildQueryString(query: Dictionary): string { const params = new URLSearchParams() for (const key in query) { if (Object.prototype.hasOwnProperty.call(query, key)) { From 21d975db8d346ea8a8203bf5605ce0a71c385360 Mon Sep 17 00:00:00 2001 From: Max Gudkov <> Date: Mon, 5 Sep 2022 12:53:22 +1200 Subject: [PATCH 2/2] add test --- test/http-data-source.test.ts | 43 ++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/test/http-data-source.test.ts b/test/http-data-source.test.ts index f820fcf..d0b333b 100644 --- a/test/http-data-source.test.ts +++ b/test/http-data-source.test.ts @@ -1,7 +1,7 @@ import anyTest, { TestInterface } from 'ava' import http from 'http' import { createGzip, createDeflate, createBrotliCompress } from 'zlib' -import { Readable } from 'stream'; +import { Readable } from 'stream' import { setGlobalDispatcher, Agent, Pool } from 'undici' import AbortController from 'abort-controller' import querystring from 'querystring' @@ -267,7 +267,7 @@ test('Should be able to pass query params', async (t) => { const server = http.createServer((req, res) => { t.is(req.method, 'GET') - t.is(req.url, '/?a=1&b=2') + t.is(req.url, '/?a=1&b=2&c=false') res.writeHead(200, { 'content-type': 'application/json', }) @@ -291,7 +291,8 @@ test('Should be able to pass query params', async (t) => { query: { a: 1, b: '2', - c: undefined, + c: false, + e: undefined, }, }) } @@ -1770,13 +1771,13 @@ test('Should be able to decode gzip compression', async (t) => { const server = http.createServer((req, res) => { if (req.headers['accept-encoding'] === 'gzip') { - res.writeHead(200, { + res.writeHead(200, { 'content-encoding': 'gzip', - 'content-type': 'application/json' - }); - const stream = Readable.from([JSON.stringify(wanted)]); - stream.pipe(createGzip()).pipe(res); - } else{ + 'content-type': 'application/json', + }) + const stream = Readable.from([JSON.stringify(wanted)]) + stream.pipe(createGzip()).pipe(res) + } else { res.writeHead(200, { 'content-type': 'application/json', }) @@ -1824,13 +1825,13 @@ test('Should be able to decode deflate compression', async (t) => { const server = http.createServer((req, res) => { if (req.headers['accept-encoding'] === 'deflate') { - res.writeHead(200, { + res.writeHead(200, { 'content-encoding': 'deflate', - 'content-type': 'application/json' - }); - const stream = Readable.from([JSON.stringify(wanted)]); - stream.pipe(createDeflate()).pipe(res); - } else{ + 'content-type': 'application/json', + }) + const stream = Readable.from([JSON.stringify(wanted)]) + stream.pipe(createDeflate()).pipe(res) + } else { res.writeHead(200, { 'content-type': 'application/json', }) @@ -1878,13 +1879,13 @@ test('Should be able to decode brotli compression', async (t) => { const server = http.createServer((req, res) => { if (req.headers['accept-encoding'] === 'br') { - res.writeHead(200, { + res.writeHead(200, { 'content-encoding': 'br', - 'content-type': 'application/json' - }); - const stream = Readable.from([JSON.stringify(wanted)]); - stream.pipe(createBrotliCompress()).pipe(res); - } else{ + 'content-type': 'application/json', + }) + const stream = Readable.from([JSON.stringify(wanted)]) + stream.pipe(createBrotliCompress()).pipe(res) + } else { res.writeHead(200, { 'content-type': 'application/json', })