@graphql-tools/executor-http 3.1.4 → 3.2.0-alpha-0d94d0b5930ac05920a55412bec7d913ccb626d1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/dist/index.cjs +31 -9
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +31 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# @graphql-tools/executor-http
|
|
2
2
|
|
|
3
|
+
## 3.2.0-alpha-0d94d0b5930ac05920a55412bec7d913ccb626d1
|
|
4
|
+
### Minor Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#2211](https://github.com/graphql-hive/gateway/pull/2211) [`3e4187b`](https://github.com/graphql-hive/gateway/commit/3e4187b340801fee45df8df891617afcfc8b4b30) Thanks [@ardatan](https://github.com/ardatan)! - Add `exposeHTTPDetailsInExtensions` flag to get `Response` details in the result extensions.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { buildHTTPExecutor } from '@graphql-tools/executor-http';
|
|
12
|
+
|
|
13
|
+
const executor = buildHTTPExecutor({
|
|
14
|
+
exposeHTTPDetailsInExtensions: true,
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Then in the result;
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
{
|
|
22
|
+
"data": {
|
|
23
|
+
"hello": "world"
|
|
24
|
+
},
|
|
25
|
+
"extensions": {
|
|
26
|
+
"request": {
|
|
27
|
+
"url": "http://localhost:4000/graphql",
|
|
28
|
+
"method": "POST",
|
|
29
|
+
"headers": {
|
|
30
|
+
"content-type": "application/json"
|
|
31
|
+
},
|
|
32
|
+
"body": "{\"query\":\"{ hello }\"}"
|
|
33
|
+
},
|
|
34
|
+
"response": {
|
|
35
|
+
"status": 200,
|
|
36
|
+
"statusText": "OK",
|
|
37
|
+
"headers": {
|
|
38
|
+
"content-type": "application/json"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
3
44
|
## 3.1.4
|
|
4
45
|
### Patch Changes
|
|
5
46
|
|
package/dist/index.cjs
CHANGED
|
@@ -684,7 +684,7 @@ function buildHTTPExecutor(options) {
|
|
|
684
684
|
return runInflightRequest();
|
|
685
685
|
}
|
|
686
686
|
function runInflightRequest() {
|
|
687
|
-
|
|
687
|
+
const result$ = promiseHelpers.handleMaybePromise(
|
|
688
688
|
() => fetchFn(
|
|
689
689
|
inflightRequestOptions.url,
|
|
690
690
|
{
|
|
@@ -702,15 +702,23 @@ function buildHTTPExecutor(options) {
|
|
|
702
702
|
upstreamErrorExtensions.response ||= {};
|
|
703
703
|
upstreamErrorExtensions.response.status = fetchResult.status;
|
|
704
704
|
upstreamErrorExtensions.response.statusText = fetchResult.statusText;
|
|
705
|
-
|
|
706
|
-
upstreamErrorExtensions.response
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
705
|
+
if (options?.exposeHTTPDetailsInExtensions) {
|
|
706
|
+
upstreamErrorExtensions.response.headers = Object.fromEntries(
|
|
707
|
+
fetchResult.headers.entries()
|
|
708
|
+
);
|
|
709
|
+
} else {
|
|
710
|
+
Object.defineProperty(
|
|
711
|
+
upstreamErrorExtensions.response,
|
|
712
|
+
"headers",
|
|
713
|
+
{
|
|
714
|
+
get() {
|
|
715
|
+
return Object.fromEntries(
|
|
716
|
+
fetchResult.headers.entries()
|
|
717
|
+
);
|
|
718
|
+
}
|
|
711
719
|
}
|
|
712
|
-
|
|
713
|
-
|
|
720
|
+
);
|
|
721
|
+
}
|
|
714
722
|
if (options?.retry != null && !fetchResult.status.toString().startsWith("2")) {
|
|
715
723
|
throw new Error(
|
|
716
724
|
fetchResult.statusText || `Upstream HTTP Error: ${fetchResult.status}`
|
|
@@ -794,6 +802,20 @@ function buildHTTPExecutor(options) {
|
|
|
794
802
|
),
|
|
795
803
|
handleError
|
|
796
804
|
);
|
|
805
|
+
if (options?.exposeHTTPDetailsInExtensions) {
|
|
806
|
+
return promiseHelpers.handleMaybePromise(
|
|
807
|
+
() => result$,
|
|
808
|
+
(result) => {
|
|
809
|
+
result.extensions ||= {};
|
|
810
|
+
result.extensions = Object.assign(
|
|
811
|
+
result.extensions,
|
|
812
|
+
upstreamErrorExtensions
|
|
813
|
+
);
|
|
814
|
+
return result;
|
|
815
|
+
}
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
return result$;
|
|
797
819
|
}
|
|
798
820
|
if (typeof inflightRequestOptions.body === "object") {
|
|
799
821
|
return runInflightRequest();
|
package/dist/index.d.cts
CHANGED
|
@@ -92,6 +92,14 @@ interface HTTPExecutorOptions {
|
|
|
92
92
|
* @default true
|
|
93
93
|
*/
|
|
94
94
|
deduplicateInflightRequests?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* This option allows you to include the response detauls in the result extensions when a request fails.
|
|
97
|
+
* This can be useful for debugging and error handling purposes, as it provides additional context about the response that led to the error.
|
|
98
|
+
* However, be cautious when enabling this option, as response headers may contain sensitive information.
|
|
99
|
+
*
|
|
100
|
+
* @default false
|
|
101
|
+
*/
|
|
102
|
+
exposeHTTPDetailsInExtensions?: boolean;
|
|
95
103
|
}
|
|
96
104
|
type HeadersConfig = Record<string, string>;
|
|
97
105
|
interface InflightRequestOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -92,6 +92,14 @@ interface HTTPExecutorOptions {
|
|
|
92
92
|
* @default true
|
|
93
93
|
*/
|
|
94
94
|
deduplicateInflightRequests?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* This option allows you to include the response detauls in the result extensions when a request fails.
|
|
97
|
+
* This can be useful for debugging and error handling purposes, as it provides additional context about the response that led to the error.
|
|
98
|
+
* However, be cautious when enabling this option, as response headers may contain sensitive information.
|
|
99
|
+
*
|
|
100
|
+
* @default false
|
|
101
|
+
*/
|
|
102
|
+
exposeHTTPDetailsInExtensions?: boolean;
|
|
95
103
|
}
|
|
96
104
|
type HeadersConfig = Record<string, string>;
|
|
97
105
|
interface InflightRequestOptions {
|
package/dist/index.js
CHANGED
|
@@ -682,7 +682,7 @@ function buildHTTPExecutor(options) {
|
|
|
682
682
|
return runInflightRequest();
|
|
683
683
|
}
|
|
684
684
|
function runInflightRequest() {
|
|
685
|
-
|
|
685
|
+
const result$ = handleMaybePromise(
|
|
686
686
|
() => fetchFn(
|
|
687
687
|
inflightRequestOptions.url,
|
|
688
688
|
{
|
|
@@ -700,15 +700,23 @@ function buildHTTPExecutor(options) {
|
|
|
700
700
|
upstreamErrorExtensions.response ||= {};
|
|
701
701
|
upstreamErrorExtensions.response.status = fetchResult.status;
|
|
702
702
|
upstreamErrorExtensions.response.statusText = fetchResult.statusText;
|
|
703
|
-
|
|
704
|
-
upstreamErrorExtensions.response
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
703
|
+
if (options?.exposeHTTPDetailsInExtensions) {
|
|
704
|
+
upstreamErrorExtensions.response.headers = Object.fromEntries(
|
|
705
|
+
fetchResult.headers.entries()
|
|
706
|
+
);
|
|
707
|
+
} else {
|
|
708
|
+
Object.defineProperty(
|
|
709
|
+
upstreamErrorExtensions.response,
|
|
710
|
+
"headers",
|
|
711
|
+
{
|
|
712
|
+
get() {
|
|
713
|
+
return Object.fromEntries(
|
|
714
|
+
fetchResult.headers.entries()
|
|
715
|
+
);
|
|
716
|
+
}
|
|
709
717
|
}
|
|
710
|
-
|
|
711
|
-
|
|
718
|
+
);
|
|
719
|
+
}
|
|
712
720
|
if (options?.retry != null && !fetchResult.status.toString().startsWith("2")) {
|
|
713
721
|
throw new Error(
|
|
714
722
|
fetchResult.statusText || `Upstream HTTP Error: ${fetchResult.status}`
|
|
@@ -792,6 +800,20 @@ function buildHTTPExecutor(options) {
|
|
|
792
800
|
),
|
|
793
801
|
handleError
|
|
794
802
|
);
|
|
803
|
+
if (options?.exposeHTTPDetailsInExtensions) {
|
|
804
|
+
return handleMaybePromise(
|
|
805
|
+
() => result$,
|
|
806
|
+
(result) => {
|
|
807
|
+
result.extensions ||= {};
|
|
808
|
+
result.extensions = Object.assign(
|
|
809
|
+
result.extensions,
|
|
810
|
+
upstreamErrorExtensions
|
|
811
|
+
);
|
|
812
|
+
return result;
|
|
813
|
+
}
|
|
814
|
+
);
|
|
815
|
+
}
|
|
816
|
+
return result$;
|
|
795
817
|
}
|
|
796
818
|
if (typeof inflightRequestOptions.body === "object") {
|
|
797
819
|
return runInflightRequest();
|
package/package.json
CHANGED