Socket
Socket
Sign inDemoInstall

apollo-datasource-http

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-datasource-http - npm Package Compare versions

Comparing version 0.11.0 to 0.12.0

2

dist/src/http-data-source.d.ts

@@ -61,3 +61,3 @@ /// <reference types="node" />

protected onCacheKeyCalculation(request: Request): string;
protected onRequest?(request: Request): void;
protected onRequest?(request: Request): Promise<void>;
protected onResponse<TResult = unknown>(_request: Request, response: Response<TResult>): Response<TResult>;

@@ -64,0 +64,0 @@ protected onError?(_error: Error, requestOptions: Request): void;

@@ -103,12 +103,12 @@ "use strict";

}
async performRequest(options, cacheKey) {
this.onRequest?.(options);
async performRequest(request, cacheKey) {
await this.onRequest?.(request);
try {
const responseData = await this.pool.request({
method: options.method,
origin: options.origin,
path: options.path,
body: options.body,
headers: options.headers,
signal: options.signal,
method: request.method,
origin: request.origin,
path: request.path,
body: request.body,
headers: request.headers,
signal: request.signal,
});

@@ -130,9 +130,9 @@ responseData.body.setEncoding('utf8');

};
this.onResponse(options, response);
if (options.requestCache && this.isResponseCacheable(options, response)) {
response.maxTtl = Math.max(options.requestCache.maxTtl, options.requestCache.maxTtlIfError);
this.onResponse(request, response);
if (request.requestCache && this.isResponseCacheable(request, response)) {
response.maxTtl = Math.max(request.requestCache.maxTtl, request.requestCache.maxTtlIfError);
const cachedResponse = JSON.stringify(response);
this.cache
.set(cacheKey, cachedResponse, {
ttl: options.requestCache?.maxTtl,
ttl: request.requestCache?.maxTtl,
})

@@ -142,3 +142,3 @@ .catch((err) => this.logger?.error(err));

.set(`staleIfError:${cacheKey}`, cachedResponse, {
ttl: options.requestCache?.maxTtlIfError,
ttl: request.requestCache?.maxTtlIfError,
})

@@ -150,4 +150,4 @@ .catch((err) => this.logger?.error(err));

catch (error) {
this.onError?.(error, options);
if (options.requestCache) {
this.onError?.(error, request);
if (request.requestCache) {
const cacheItem = await this.cache.get(`staleIfError:${cacheKey}`);

@@ -154,0 +154,0 @@ if (cacheItem) {

{
"name": "apollo-datasource-http",
"version": "0.11.0",
"version": "0.12.0",
"author": "Dustin Deus <deusdustin@gmail.com>",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -69,3 +69,3 @@ # Apollo HTTP Data Source

onRequest(request: Request): void {
async onRequest(request: Request): Promise<void> {
// manipulate request before it is send

@@ -72,0 +72,0 @@ // for example assign a AbortController signal to all requests and abort

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc