@lenne.tech/nest-server 10.4.0 → 10.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "10.4.0",
3
+ "version": "10.4.1",
4
4
  "description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
5
5
  "keywords": [
6
6
  "node",
@@ -204,15 +204,19 @@ export class TestHelper {
204
204
 
205
205
  // Init
206
206
  let query = '';
207
+ let name: string = undefined;
207
208
 
208
209
  // Convert string to TestGraphQLConfig
209
- if ((typeof graphql === 'string' || graphql instanceof String) && /^[a-zA-Z]+$/.test(graphql as string)) {
210
+ if (
211
+ (typeof graphql === 'string' || graphql instanceof String)
212
+ && /^(?![a-zA-Z]+$).*$/.test((graphql as string).trim())
213
+ ) {
210
214
  // Use input as query
211
- query = graphql as string;
215
+ query = (graphql as string).trim();
212
216
  } else {
213
217
  // Use input as name
214
218
  if (typeof graphql === 'string' || graphql instanceof String) {
215
- graphql = { name: graphql } as any;
219
+ graphql = { name: (graphql as string).trim() } as any;
216
220
  }
217
221
 
218
222
  // Prepare config
@@ -225,6 +229,7 @@ export class TestHelper {
225
229
  },
226
230
  graphql,
227
231
  ) as TestGraphQLConfig;
232
+ name = graphql.name;
228
233
 
229
234
  // Init request
230
235
  const queryObj = {};
@@ -248,7 +253,11 @@ export class TestHelper {
248
253
  }
249
254
 
250
255
  // Create request payload query
251
- query = jsonToGraphQLQuery(queryObj, { pretty: true });
256
+ if (!graphql.fields?.length && !graphql.arguments) {
257
+ query = `${graphql.type} { ${graphql.name} }`;
258
+ } else {
259
+ query = jsonToGraphQLQuery(queryObj, { pretty: true });
260
+ }
252
261
  }
253
262
 
254
263
  if ((graphql as TestGraphQLConfig).type === TestGraphQLType.SUBSCRIPTION) {
@@ -298,7 +307,21 @@ export class TestHelper {
298
307
  expect(response.headers['content-type']).toMatch('application/json');
299
308
 
300
309
  // return data
301
- return response.body.data ? response.body.data[(graphql as TestGraphQLConfig).name] : response.body;
310
+ if (response.body) {
311
+ if (response.body.data) {
312
+ return name ? response.body.data[(graphql as TestGraphQLConfig).name] : response.body.data;
313
+ }
314
+ return response.body;
315
+ }
316
+ if (response.text) {
317
+ if (JSON.parse(response.text).data) {
318
+ return name
319
+ ? JSON.parse(response.text).data[(graphql as TestGraphQLConfig).name]
320
+ : JSON.parse(response.text).data;
321
+ }
322
+ return JSON.parse(response.text);
323
+ }
324
+ return undefined;
302
325
  }
303
326
 
304
327
  /**