Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Boolean query type support #52

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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: 2 additions & 2 deletions src/http-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type RequestOptions = Omit<Partial<Request>, 'origin' | 'path' | 'method'

export type Request<T = unknown> = {
context: Dictionary<string>
query: Dictionary<string | number>
query: Dictionary<string | number | boolean>
body: T
signal?: AbortSignal | EventEmitter | null
json?: boolean
Expand Down Expand Up @@ -107,7 +107,7 @@ export abstract class HTTPDataSource<TContext = any> extends DataSource {
this.logger = options?.logger
}

private buildQueryString(query: Dictionary<string | number>): string {
private buildQueryString(query: Dictionary<string | number | boolean>): string {
const params = new URLSearchParams()
for (const key in query) {
if (Object.prototype.hasOwnProperty.call(query, key)) {
Expand Down
43 changes: 22 additions & 21 deletions test/http-data-source.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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',
})
Expand All @@ -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,
},
})
}
Expand Down Expand Up @@ -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',
})
Expand Down Expand Up @@ -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',
})
Expand Down Expand Up @@ -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',
})
Expand Down