@graphql-mesh/transport-http-callback 0.4.1-alpha-20241011172526-4330ea086b58a90097ddaf17e6185c66ffe75e04 → 0.5.0-alpha-20241014101654-80a8ea90f673a820a74998c37b869ba3c41858ed
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/index.js +28 -19
- package/esm/index.js +28 -19
- package/package.json +3 -3
package/cjs/index.js
CHANGED
@@ -72,7 +72,7 @@ exports.default = {
|
|
72
72
|
throw new Error(`Subgraph does not look like configured correctly. Check your subgraph setup.`);
|
73
73
|
};
|
74
74
|
const reqAbortCtrl = new AbortController();
|
75
|
-
|
75
|
+
const subFetchCall$ = (0, utils_1.mapMaybePromise)(fetch(transportEntry.location, {
|
76
76
|
method: 'POST',
|
77
77
|
headers: {
|
78
78
|
'Content-Type': 'application/json',
|
@@ -86,29 +86,38 @@ exports.default = {
|
|
86
86
|
},
|
87
87
|
body: fetchBody,
|
88
88
|
signal: reqAbortCtrl.signal,
|
89
|
-
}, execReq.context, execReq.info), res => {
|
90
|
-
|
91
|
-
|
89
|
+
}, execReq.context, execReq.info), res => (0, utils_1.mapMaybePromise)(res.text(), resText => {
|
90
|
+
let resJson;
|
91
|
+
try {
|
92
|
+
resJson = JSON.parse(resText);
|
92
93
|
}
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
if (resJson.errors.length === 1) {
|
97
|
-
stopSubscription((0, utils_2.createGraphQLError)(resJson.errors[0].message, resJson.errors[0]));
|
98
|
-
}
|
99
|
-
else {
|
100
|
-
stopSubscription(new AggregateError(resJson.errors.map(err => (0, utils_2.createGraphQLError)(err.message, err)), resJson.errors.map(err => err.message).join('\n')));
|
101
|
-
}
|
94
|
+
catch (e) {
|
95
|
+
if (!res.ok) {
|
96
|
+
stopSubscription(new Error(`Subscription request failed with an HTTP Error: ${res.status} ${resText}`));
|
102
97
|
}
|
103
|
-
else
|
104
|
-
|
105
|
-
stopSubscription();
|
98
|
+
else {
|
99
|
+
stopSubscription(e);
|
106
100
|
}
|
107
|
-
|
108
|
-
|
101
|
+
return;
|
102
|
+
}
|
103
|
+
logger.debug(`Subscription request received`, resJson);
|
104
|
+
if (resJson.errors) {
|
105
|
+
if (resJson.errors.length === 1) {
|
106
|
+
stopSubscription((0, utils_2.createGraphQLError)(resJson.errors[0].message, resJson.errors[0]));
|
107
|
+
}
|
108
|
+
else {
|
109
|
+
stopSubscription(new AggregateError(resJson.errors.map(err => (0, utils_2.createGraphQLError)(err.message, err)), resJson.errors.map(err => err.message).join('\n')));
|
110
|
+
}
|
111
|
+
}
|
112
|
+
else if (resJson.data != null) {
|
113
|
+
pushFn(resJson.data);
|
114
|
+
stopSubscription();
|
115
|
+
}
|
116
|
+
}), e => {
|
109
117
|
logger.debug(`Subscription request failed`, e);
|
110
118
|
stopSubscription(e);
|
111
|
-
})
|
119
|
+
});
|
120
|
+
execReq.context?.waitUntil?.(subFetchCall$);
|
112
121
|
return new repeater_1.Repeater((push, stop) => {
|
113
122
|
pushFn = push;
|
114
123
|
stopSubscription = stop;
|
package/esm/index.js
CHANGED
@@ -70,7 +70,7 @@ export default {
|
|
70
70
|
throw new Error(`Subgraph does not look like configured correctly. Check your subgraph setup.`);
|
71
71
|
};
|
72
72
|
const reqAbortCtrl = new AbortController();
|
73
|
-
|
73
|
+
const subFetchCall$ = mapMaybePromise(fetch(transportEntry.location, {
|
74
74
|
method: 'POST',
|
75
75
|
headers: {
|
76
76
|
'Content-Type': 'application/json',
|
@@ -84,29 +84,38 @@ export default {
|
|
84
84
|
},
|
85
85
|
body: fetchBody,
|
86
86
|
signal: reqAbortCtrl.signal,
|
87
|
-
}, execReq.context, execReq.info), res => {
|
88
|
-
|
89
|
-
|
87
|
+
}, execReq.context, execReq.info), res => mapMaybePromise(res.text(), resText => {
|
88
|
+
let resJson;
|
89
|
+
try {
|
90
|
+
resJson = JSON.parse(resText);
|
90
91
|
}
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
if (resJson.errors.length === 1) {
|
95
|
-
stopSubscription(createGraphQLError(resJson.errors[0].message, resJson.errors[0]));
|
96
|
-
}
|
97
|
-
else {
|
98
|
-
stopSubscription(new AggregateError(resJson.errors.map(err => createGraphQLError(err.message, err)), resJson.errors.map(err => err.message).join('\n')));
|
99
|
-
}
|
92
|
+
catch (e) {
|
93
|
+
if (!res.ok) {
|
94
|
+
stopSubscription(new Error(`Subscription request failed with an HTTP Error: ${res.status} ${resText}`));
|
100
95
|
}
|
101
|
-
else
|
102
|
-
|
103
|
-
stopSubscription();
|
96
|
+
else {
|
97
|
+
stopSubscription(e);
|
104
98
|
}
|
105
|
-
|
106
|
-
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
logger.debug(`Subscription request received`, resJson);
|
102
|
+
if (resJson.errors) {
|
103
|
+
if (resJson.errors.length === 1) {
|
104
|
+
stopSubscription(createGraphQLError(resJson.errors[0].message, resJson.errors[0]));
|
105
|
+
}
|
106
|
+
else {
|
107
|
+
stopSubscription(new AggregateError(resJson.errors.map(err => createGraphQLError(err.message, err)), resJson.errors.map(err => err.message).join('\n')));
|
108
|
+
}
|
109
|
+
}
|
110
|
+
else if (resJson.data != null) {
|
111
|
+
pushFn(resJson.data);
|
112
|
+
stopSubscription();
|
113
|
+
}
|
114
|
+
}), e => {
|
107
115
|
logger.debug(`Subscription request failed`, e);
|
108
116
|
stopSubscription(e);
|
109
|
-
})
|
117
|
+
});
|
118
|
+
execReq.context?.waitUntil?.(subFetchCall$);
|
110
119
|
return new Repeater((push, stop) => {
|
111
120
|
pushFn = push;
|
112
121
|
stopSubscription = stop;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@graphql-mesh/transport-http-callback",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.5.0-alpha-20241014101654-80a8ea90f673a820a74998c37b869ba3c41858ed",
|
4
4
|
"sideEffects": false,
|
5
5
|
"peerDependencies": {
|
6
6
|
"graphql": "*",
|
@@ -9,8 +9,8 @@
|
|
9
9
|
"dependencies": {
|
10
10
|
"@graphql-mesh/cross-helpers": "^0.4.6",
|
11
11
|
"@graphql-mesh/string-interpolation": "^0.5.6",
|
12
|
-
"@graphql-mesh/transport-common": "0.7.7
|
13
|
-
"@graphql-mesh/utils": "0.102.6
|
12
|
+
"@graphql-mesh/transport-common": "^0.7.7",
|
13
|
+
"@graphql-mesh/utils": "^0.102.6",
|
14
14
|
"@graphql-tools/utils": "^10.5.3",
|
15
15
|
"@repeaterjs/repeater": "^3.0.6",
|
16
16
|
"@whatwg-node/fetch": "^0.9.18"
|