@naturalcycles/js-lib 14.266.1 → 14.267.0
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/dist/http/fetcher.js
CHANGED
|
@@ -142,6 +142,7 @@ class Fetcher {
|
|
|
142
142
|
const err = res.body.errors[0];
|
|
143
143
|
// todo: consider creating a new GraphQLError class for this
|
|
144
144
|
throw new error_util_1.HttpRequestError(err.message, {
|
|
145
|
+
...payload, // query and variables
|
|
145
146
|
errors: res.body.errors, // full errors payload returned
|
|
146
147
|
response: res.fetchResponse,
|
|
147
148
|
responseStatusCode: res.statusCode,
|
|
@@ -152,7 +153,11 @@ class Fetcher {
|
|
|
152
153
|
requestDuration: Date.now() - res.req.started,
|
|
153
154
|
});
|
|
154
155
|
}
|
|
155
|
-
|
|
156
|
+
const { data } = res.body;
|
|
157
|
+
if (opt.unwrapObject) {
|
|
158
|
+
return data[opt.unwrapObject];
|
|
159
|
+
}
|
|
160
|
+
return data;
|
|
156
161
|
}
|
|
157
162
|
// responseType=readableStream
|
|
158
163
|
/**
|
|
@@ -119,6 +119,18 @@ export interface FetcherRequest extends Omit<FetcherOptions, 'method' | 'headers
|
|
|
119
119
|
export interface FetcherGraphQLOptions extends FetcherOptions {
|
|
120
120
|
query: string;
|
|
121
121
|
variables?: AnyObject;
|
|
122
|
+
/**
|
|
123
|
+
* When querying singular entities, it may be convenient to specify 1st level object to unwrap.
|
|
124
|
+
* Example:
|
|
125
|
+
* {
|
|
126
|
+
* homePage: { ... }
|
|
127
|
+
* }
|
|
128
|
+
*
|
|
129
|
+
* unwrapObject: 'homePage'
|
|
130
|
+
*
|
|
131
|
+
* would return the contents of `{ ... }`
|
|
132
|
+
*/
|
|
133
|
+
unwrapObject?: string;
|
|
122
134
|
}
|
|
123
135
|
export interface FetcherOptions {
|
|
124
136
|
method?: HttpMethod;
|
package/dist-esm/http/fetcher.js
CHANGED
|
@@ -135,6 +135,7 @@ export class Fetcher {
|
|
|
135
135
|
const err = res.body.errors[0];
|
|
136
136
|
// todo: consider creating a new GraphQLError class for this
|
|
137
137
|
throw new HttpRequestError(err.message, {
|
|
138
|
+
...payload, // query and variables
|
|
138
139
|
errors: res.body.errors, // full errors payload returned
|
|
139
140
|
response: res.fetchResponse,
|
|
140
141
|
responseStatusCode: res.statusCode,
|
|
@@ -145,7 +146,11 @@ export class Fetcher {
|
|
|
145
146
|
requestDuration: Date.now() - res.req.started,
|
|
146
147
|
});
|
|
147
148
|
}
|
|
148
|
-
|
|
149
|
+
const { data } = res.body;
|
|
150
|
+
if (opt.unwrapObject) {
|
|
151
|
+
return data[opt.unwrapObject];
|
|
152
|
+
}
|
|
153
|
+
return data;
|
|
149
154
|
}
|
|
150
155
|
// responseType=readableStream
|
|
151
156
|
/**
|
package/package.json
CHANGED
|
@@ -155,6 +155,18 @@ export interface FetcherRequest
|
|
|
155
155
|
export interface FetcherGraphQLOptions extends FetcherOptions {
|
|
156
156
|
query: string
|
|
157
157
|
variables?: AnyObject
|
|
158
|
+
/**
|
|
159
|
+
* When querying singular entities, it may be convenient to specify 1st level object to unwrap.
|
|
160
|
+
* Example:
|
|
161
|
+
* {
|
|
162
|
+
* homePage: { ... }
|
|
163
|
+
* }
|
|
164
|
+
*
|
|
165
|
+
* unwrapObject: 'homePage'
|
|
166
|
+
*
|
|
167
|
+
* would return the contents of `{ ... }`
|
|
168
|
+
*/
|
|
169
|
+
unwrapObject?: string
|
|
158
170
|
}
|
|
159
171
|
|
|
160
172
|
export interface FetcherOptions {
|
package/src/http/fetcher.ts
CHANGED
|
@@ -214,6 +214,7 @@ export class Fetcher {
|
|
|
214
214
|
|
|
215
215
|
// todo: consider creating a new GraphQLError class for this
|
|
216
216
|
throw new HttpRequestError(err.message, {
|
|
217
|
+
...payload, // query and variables
|
|
217
218
|
errors: res.body.errors, // full errors payload returned
|
|
218
219
|
response: res.fetchResponse,
|
|
219
220
|
responseStatusCode: res.statusCode,
|
|
@@ -225,7 +226,12 @@ export class Fetcher {
|
|
|
225
226
|
})
|
|
226
227
|
}
|
|
227
228
|
|
|
228
|
-
|
|
229
|
+
const { data } = res.body
|
|
230
|
+
if (opt.unwrapObject) {
|
|
231
|
+
return (data as any)[opt.unwrapObject]
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return data
|
|
229
235
|
}
|
|
230
236
|
|
|
231
237
|
// responseType=readableStream
|