apollo-datasource-http
Advanced tools
Comparing version 0.16.0 to 0.16.1
@@ -26,6 +26,6 @@ /// <reference types="node" /> | ||
export declare type RequestOptions = Omit<Partial<Request>, 'origin' | 'path' | 'method'>; | ||
export declare type Request = { | ||
export declare type Request<T = unknown> = { | ||
context: Dictionary<string>; | ||
query: Dictionary<string | number>; | ||
body: any; | ||
body: T; | ||
signal?: AbortSignal | EventEmitter | null; | ||
@@ -32,0 +32,0 @@ json?: boolean; |
@@ -133,4 +133,10 @@ "use strict"; | ||
var _a, _b, _c, _d, _e; | ||
await ((_a = this.onRequest) === null || _a === void 0 ? void 0 : _a.call(this, request)); | ||
try { | ||
if (request.body !== null && typeof request.body === 'object') { | ||
if (request.headers['content-type'] === undefined) { | ||
request.headers['content-type'] = 'application/json; charset=utf-8'; | ||
} | ||
request.body = JSON.stringify(request.body); | ||
} | ||
await ((_a = this.onRequest) === null || _a === void 0 ? void 0 : _a.call(this, request)); | ||
const requestOptions = { | ||
@@ -140,12 +146,6 @@ method: request.method, | ||
path: request.path, | ||
body: request.body, | ||
headers: request.headers, | ||
signal: request.signal, | ||
body: request.body, | ||
}; | ||
if (request.json === true) { | ||
if (requestOptions.headers['content-type'] === undefined) { | ||
requestOptions.headers['content-type'] = 'application/json; charset=utf-8'; | ||
} | ||
requestOptions.body = JSON.stringify(requestOptions.body); | ||
} | ||
const responseData = await this.pool.request(requestOptions); | ||
@@ -159,3 +159,3 @@ responseData.body.setEncoding('utf8'); | ||
if ((_b = responseData.headers['content-type']) === null || _b === void 0 ? void 0 : _b.includes('application/json')) { | ||
if (data !== '') { | ||
if (data.length && typeof data === 'string') { | ||
json = secure_json_parse_1.default.parse(data); | ||
@@ -162,0 +162,0 @@ } |
{ | ||
"name": "apollo-datasource-http", | ||
"version": "0.16.0", | ||
"version": "0.16.1", | ||
"author": "Dustin Deus <deusdustin@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -92,2 +92,10 @@ # Apollo HTTP Data Source | ||
async createMovie() { | ||
return this.post('/movies', { | ||
body: { | ||
name: 'Dude Where\'s My Car', | ||
} | ||
}) | ||
} | ||
async getMovie(id) { | ||
@@ -94,0 +102,0 @@ return this.get(`/movies/${id}`, { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33300
150