@graphql-tools/utils 10.0.11 → 10.0.12

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.
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDescriptionNode = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function getDescriptionNode(obj) {
6
+ if (obj.astNode?.description) {
7
+ return {
8
+ ...obj.astNode.description,
9
+ block: true,
10
+ };
11
+ }
12
+ if (obj.description) {
13
+ return {
14
+ kind: graphql_1.Kind.STRING,
15
+ value: obj.description,
16
+ block: true,
17
+ };
18
+ }
19
+ }
20
+ exports.getDescriptionNode = getDescriptionNode;
@@ -5,6 +5,7 @@ const graphql_1 = require("graphql");
5
5
  const astFromType_js_1 = require("./astFromType.js");
6
6
  const astFromValue_js_1 = require("./astFromValue.js");
7
7
  const astFromValueUntyped_js_1 = require("./astFromValueUntyped.js");
8
+ const descriptionFromObject_js_1 = require("./descriptionFromObject.js");
8
9
  const get_directives_js_1 = require("./get-directives.js");
9
10
  const helpers_js_1 = require("./helpers.js");
10
11
  const rootTypes_js_1 = require("./rootTypes.js");
@@ -112,30 +113,17 @@ function astFromSchema(schema, pathToDirectivesInExtensions) {
112
113
  // ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
113
114
  directives: directives,
114
115
  };
115
- // This code is so weird because it needs to support GraphQL.js 14
116
- // In GraphQL.js 14 there is no `description` value on schemaNode
117
- schemaNode.description =
118
- (schema.astNode?.description ??
119
- schema.description != null)
120
- ? {
121
- kind: graphql_1.Kind.STRING,
122
- value: schema.description,
123
- block: true,
124
- }
125
- : undefined;
116
+ const descriptionNode = (0, descriptionFromObject_js_1.getDescriptionNode)(schema);
117
+ if (descriptionNode) {
118
+ schemaNode.description = descriptionNode;
119
+ }
126
120
  return schemaNode;
127
121
  }
128
122
  exports.astFromSchema = astFromSchema;
129
123
  function astFromDirective(directive, schema, pathToDirectivesInExtensions) {
130
124
  return {
131
125
  kind: graphql_1.Kind.DIRECTIVE_DEFINITION,
132
- description: directive.astNode?.description ??
133
- (directive.description
134
- ? {
135
- kind: graphql_1.Kind.STRING,
136
- value: directive.description,
137
- }
138
- : undefined),
126
+ description: (0, descriptionFromObject_js_1.getDescriptionNode)(directive),
139
127
  name: {
140
128
  kind: graphql_1.Kind.NAME,
141
129
  value: directive.name,
@@ -202,14 +190,7 @@ exports.getDeprecatableDirectiveNodes = getDeprecatableDirectiveNodes;
202
190
  function astFromArg(arg, schema, pathToDirectivesInExtensions) {
203
191
  return {
204
192
  kind: graphql_1.Kind.INPUT_VALUE_DEFINITION,
205
- description: arg.astNode?.description ??
206
- (arg.description
207
- ? {
208
- kind: graphql_1.Kind.STRING,
209
- value: arg.description,
210
- block: true,
211
- }
212
- : undefined),
193
+ description: (0, descriptionFromObject_js_1.getDescriptionNode)(arg),
213
194
  name: {
214
195
  kind: graphql_1.Kind.NAME,
215
196
  value: arg.name,
@@ -226,14 +207,7 @@ exports.astFromArg = astFromArg;
226
207
  function astFromObjectType(type, schema, pathToDirectivesInExtensions) {
227
208
  return {
228
209
  kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION,
229
- description: type.astNode?.description ??
230
- (type.description
231
- ? {
232
- kind: graphql_1.Kind.STRING,
233
- value: type.description,
234
- block: true,
235
- }
236
- : undefined),
210
+ description: (0, descriptionFromObject_js_1.getDescriptionNode)(type),
237
211
  name: {
238
212
  kind: graphql_1.Kind.NAME,
239
213
  value: type.name,
@@ -247,14 +221,7 @@ exports.astFromObjectType = astFromObjectType;
247
221
  function astFromInterfaceType(type, schema, pathToDirectivesInExtensions) {
248
222
  const node = {
249
223
  kind: graphql_1.Kind.INTERFACE_TYPE_DEFINITION,
250
- description: type.astNode?.description ??
251
- (type.description
252
- ? {
253
- kind: graphql_1.Kind.STRING,
254
- value: type.description,
255
- block: true,
256
- }
257
- : undefined),
224
+ description: (0, descriptionFromObject_js_1.getDescriptionNode)(type),
258
225
  name: {
259
226
  kind: graphql_1.Kind.NAME,
260
227
  value: type.name,
@@ -271,14 +238,7 @@ exports.astFromInterfaceType = astFromInterfaceType;
271
238
  function astFromUnionType(type, schema, pathToDirectivesInExtensions) {
272
239
  return {
273
240
  kind: graphql_1.Kind.UNION_TYPE_DEFINITION,
274
- description: type.astNode?.description ??
275
- (type.description
276
- ? {
277
- kind: graphql_1.Kind.STRING,
278
- value: type.description,
279
- block: true,
280
- }
281
- : undefined),
241
+ description: (0, descriptionFromObject_js_1.getDescriptionNode)(type),
282
242
  name: {
283
243
  kind: graphql_1.Kind.NAME,
284
244
  value: type.name,
@@ -292,14 +252,7 @@ exports.astFromUnionType = astFromUnionType;
292
252
  function astFromInputObjectType(type, schema, pathToDirectivesInExtensions) {
293
253
  return {
294
254
  kind: graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION,
295
- description: type.astNode?.description ??
296
- (type.description
297
- ? {
298
- kind: graphql_1.Kind.STRING,
299
- value: type.description,
300
- block: true,
301
- }
302
- : undefined),
255
+ description: (0, descriptionFromObject_js_1.getDescriptionNode)(type),
303
256
  name: {
304
257
  kind: graphql_1.Kind.NAME,
305
258
  value: type.name,
@@ -313,14 +266,7 @@ exports.astFromInputObjectType = astFromInputObjectType;
313
266
  function astFromEnumType(type, schema, pathToDirectivesInExtensions) {
314
267
  return {
315
268
  kind: graphql_1.Kind.ENUM_TYPE_DEFINITION,
316
- description: type.astNode?.description ??
317
- (type.description
318
- ? {
319
- kind: graphql_1.Kind.STRING,
320
- value: type.description,
321
- block: true,
322
- }
323
- : undefined),
269
+ description: (0, descriptionFromObject_js_1.getDescriptionNode)(type),
324
270
  name: {
325
271
  kind: graphql_1.Kind.NAME,
326
272
  value: type.name,
@@ -347,14 +293,7 @@ function astFromScalarType(type, schema, pathToDirectivesInExtensions) {
347
293
  }
348
294
  return {
349
295
  kind: graphql_1.Kind.SCALAR_TYPE_DEFINITION,
350
- description: type.astNode?.description ??
351
- (type.description
352
- ? {
353
- kind: graphql_1.Kind.STRING,
354
- value: type.description,
355
- block: true,
356
- }
357
- : undefined),
296
+ description: (0, descriptionFromObject_js_1.getDescriptionNode)(type),
358
297
  name: {
359
298
  kind: graphql_1.Kind.NAME,
360
299
  value: type.name,
@@ -367,14 +306,7 @@ exports.astFromScalarType = astFromScalarType;
367
306
  function astFromField(field, schema, pathToDirectivesInExtensions) {
368
307
  return {
369
308
  kind: graphql_1.Kind.FIELD_DEFINITION,
370
- description: field.astNode?.description ??
371
- (field.description
372
- ? {
373
- kind: graphql_1.Kind.STRING,
374
- value: field.description,
375
- block: true,
376
- }
377
- : undefined),
309
+ description: (0, descriptionFromObject_js_1.getDescriptionNode)(field),
378
310
  name: {
379
311
  kind: graphql_1.Kind.NAME,
380
312
  value: field.name,
@@ -389,14 +321,7 @@ exports.astFromField = astFromField;
389
321
  function astFromInputField(field, schema, pathToDirectivesInExtensions) {
390
322
  return {
391
323
  kind: graphql_1.Kind.INPUT_VALUE_DEFINITION,
392
- description: field.astNode?.description ??
393
- (field.description
394
- ? {
395
- kind: graphql_1.Kind.STRING,
396
- value: field.description,
397
- block: true,
398
- }
399
- : undefined),
324
+ description: (0, descriptionFromObject_js_1.getDescriptionNode)(field),
400
325
  name: {
401
326
  kind: graphql_1.Kind.NAME,
402
327
  value: field.name,
@@ -411,14 +336,7 @@ exports.astFromInputField = astFromInputField;
411
336
  function astFromEnumValue(value, schema, pathToDirectivesInExtensions) {
412
337
  return {
413
338
  kind: graphql_1.Kind.ENUM_VALUE_DEFINITION,
414
- description: value.astNode?.description ??
415
- (value.description
416
- ? {
417
- kind: graphql_1.Kind.STRING,
418
- value: value.description,
419
- block: true,
420
- }
421
- : undefined),
339
+ description: (0, descriptionFromObject_js_1.getDescriptionNode)(value),
422
340
  name: {
423
341
  kind: graphql_1.Kind.NAME,
424
342
  value: value.name,
@@ -0,0 +1,16 @@
1
+ import { Kind } from 'graphql';
2
+ export function getDescriptionNode(obj) {
3
+ if (obj.astNode?.description) {
4
+ return {
5
+ ...obj.astNode.description,
6
+ block: true,
7
+ };
8
+ }
9
+ if (obj.description) {
10
+ return {
11
+ kind: Kind.STRING,
12
+ value: obj.description,
13
+ block: true,
14
+ };
15
+ }
16
+ }
@@ -2,6 +2,7 @@ import { GraphQLDeprecatedDirective, isEnumType, isInputObjectType, isInterfaceT
2
2
  import { astFromType } from './astFromType.js';
3
3
  import { astFromValue } from './astFromValue.js';
4
4
  import { astFromValueUntyped } from './astFromValueUntyped.js';
5
+ import { getDescriptionNode } from './descriptionFromObject.js';
5
6
  import { getDirectivesInExtensions } from './get-directives.js';
6
7
  import { isSome } from './helpers.js';
7
8
  import { getRootTypeMap } from './rootTypes.js';
@@ -107,29 +108,16 @@ export function astFromSchema(schema, pathToDirectivesInExtensions) {
107
108
  // ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
108
109
  directives: directives,
109
110
  };
110
- // This code is so weird because it needs to support GraphQL.js 14
111
- // In GraphQL.js 14 there is no `description` value on schemaNode
112
- schemaNode.description =
113
- (schema.astNode?.description ??
114
- schema.description != null)
115
- ? {
116
- kind: Kind.STRING,
117
- value: schema.description,
118
- block: true,
119
- }
120
- : undefined;
111
+ const descriptionNode = getDescriptionNode(schema);
112
+ if (descriptionNode) {
113
+ schemaNode.description = descriptionNode;
114
+ }
121
115
  return schemaNode;
122
116
  }
123
117
  export function astFromDirective(directive, schema, pathToDirectivesInExtensions) {
124
118
  return {
125
119
  kind: Kind.DIRECTIVE_DEFINITION,
126
- description: directive.astNode?.description ??
127
- (directive.description
128
- ? {
129
- kind: Kind.STRING,
130
- value: directive.description,
131
- }
132
- : undefined),
120
+ description: getDescriptionNode(directive),
133
121
  name: {
134
122
  kind: Kind.NAME,
135
123
  value: directive.name,
@@ -193,14 +181,7 @@ export function getDeprecatableDirectiveNodes(entity, schema, pathToDirectivesIn
193
181
  export function astFromArg(arg, schema, pathToDirectivesInExtensions) {
194
182
  return {
195
183
  kind: Kind.INPUT_VALUE_DEFINITION,
196
- description: arg.astNode?.description ??
197
- (arg.description
198
- ? {
199
- kind: Kind.STRING,
200
- value: arg.description,
201
- block: true,
202
- }
203
- : undefined),
184
+ description: getDescriptionNode(arg),
204
185
  name: {
205
186
  kind: Kind.NAME,
206
187
  value: arg.name,
@@ -216,14 +197,7 @@ export function astFromArg(arg, schema, pathToDirectivesInExtensions) {
216
197
  export function astFromObjectType(type, schema, pathToDirectivesInExtensions) {
217
198
  return {
218
199
  kind: Kind.OBJECT_TYPE_DEFINITION,
219
- description: type.astNode?.description ??
220
- (type.description
221
- ? {
222
- kind: Kind.STRING,
223
- value: type.description,
224
- block: true,
225
- }
226
- : undefined),
200
+ description: getDescriptionNode(type),
227
201
  name: {
228
202
  kind: Kind.NAME,
229
203
  value: type.name,
@@ -236,14 +210,7 @@ export function astFromObjectType(type, schema, pathToDirectivesInExtensions) {
236
210
  export function astFromInterfaceType(type, schema, pathToDirectivesInExtensions) {
237
211
  const node = {
238
212
  kind: Kind.INTERFACE_TYPE_DEFINITION,
239
- description: type.astNode?.description ??
240
- (type.description
241
- ? {
242
- kind: Kind.STRING,
243
- value: type.description,
244
- block: true,
245
- }
246
- : undefined),
213
+ description: getDescriptionNode(type),
247
214
  name: {
248
215
  kind: Kind.NAME,
249
216
  value: type.name,
@@ -259,14 +226,7 @@ export function astFromInterfaceType(type, schema, pathToDirectivesInExtensions)
259
226
  export function astFromUnionType(type, schema, pathToDirectivesInExtensions) {
260
227
  return {
261
228
  kind: Kind.UNION_TYPE_DEFINITION,
262
- description: type.astNode?.description ??
263
- (type.description
264
- ? {
265
- kind: Kind.STRING,
266
- value: type.description,
267
- block: true,
268
- }
269
- : undefined),
229
+ description: getDescriptionNode(type),
270
230
  name: {
271
231
  kind: Kind.NAME,
272
232
  value: type.name,
@@ -279,14 +239,7 @@ export function astFromUnionType(type, schema, pathToDirectivesInExtensions) {
279
239
  export function astFromInputObjectType(type, schema, pathToDirectivesInExtensions) {
280
240
  return {
281
241
  kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
282
- description: type.astNode?.description ??
283
- (type.description
284
- ? {
285
- kind: Kind.STRING,
286
- value: type.description,
287
- block: true,
288
- }
289
- : undefined),
242
+ description: getDescriptionNode(type),
290
243
  name: {
291
244
  kind: Kind.NAME,
292
245
  value: type.name,
@@ -299,14 +252,7 @@ export function astFromInputObjectType(type, schema, pathToDirectivesInExtension
299
252
  export function astFromEnumType(type, schema, pathToDirectivesInExtensions) {
300
253
  return {
301
254
  kind: Kind.ENUM_TYPE_DEFINITION,
302
- description: type.astNode?.description ??
303
- (type.description
304
- ? {
305
- kind: Kind.STRING,
306
- value: type.description,
307
- block: true,
308
- }
309
- : undefined),
255
+ description: getDescriptionNode(type),
310
256
  name: {
311
257
  kind: Kind.NAME,
312
258
  value: type.name,
@@ -332,14 +278,7 @@ export function astFromScalarType(type, schema, pathToDirectivesInExtensions) {
332
278
  }
333
279
  return {
334
280
  kind: Kind.SCALAR_TYPE_DEFINITION,
335
- description: type.astNode?.description ??
336
- (type.description
337
- ? {
338
- kind: Kind.STRING,
339
- value: type.description,
340
- block: true,
341
- }
342
- : undefined),
281
+ description: getDescriptionNode(type),
343
282
  name: {
344
283
  kind: Kind.NAME,
345
284
  value: type.name,
@@ -351,14 +290,7 @@ export function astFromScalarType(type, schema, pathToDirectivesInExtensions) {
351
290
  export function astFromField(field, schema, pathToDirectivesInExtensions) {
352
291
  return {
353
292
  kind: Kind.FIELD_DEFINITION,
354
- description: field.astNode?.description ??
355
- (field.description
356
- ? {
357
- kind: Kind.STRING,
358
- value: field.description,
359
- block: true,
360
- }
361
- : undefined),
293
+ description: getDescriptionNode(field),
362
294
  name: {
363
295
  kind: Kind.NAME,
364
296
  value: field.name,
@@ -372,14 +304,7 @@ export function astFromField(field, schema, pathToDirectivesInExtensions) {
372
304
  export function astFromInputField(field, schema, pathToDirectivesInExtensions) {
373
305
  return {
374
306
  kind: Kind.INPUT_VALUE_DEFINITION,
375
- description: field.astNode?.description ??
376
- (field.description
377
- ? {
378
- kind: Kind.STRING,
379
- value: field.description,
380
- block: true,
381
- }
382
- : undefined),
307
+ description: getDescriptionNode(field),
383
308
  name: {
384
309
  kind: Kind.NAME,
385
310
  value: field.name,
@@ -393,14 +318,7 @@ export function astFromInputField(field, schema, pathToDirectivesInExtensions) {
393
318
  export function astFromEnumValue(value, schema, pathToDirectivesInExtensions) {
394
319
  return {
395
320
  kind: Kind.ENUM_VALUE_DEFINITION,
396
- description: value.astNode?.description ??
397
- (value.description
398
- ? {
399
- kind: Kind.STRING,
400
- value: value.description,
401
- block: true,
402
- }
403
- : undefined),
321
+ description: getDescriptionNode(value),
404
322
  name: {
405
323
  kind: Kind.NAME,
406
324
  value: value.name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "10.0.11",
3
+ "version": "10.0.12",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -0,0 +1,9 @@
1
+ import { type StringValueNode } from 'graphql';
2
+ interface ObjectWithDescription {
3
+ astNode?: {
4
+ description?: StringValueNode | null;
5
+ } | null;
6
+ description?: string | null;
7
+ }
8
+ export declare function getDescriptionNode(obj: ObjectWithDescription): StringValueNode | undefined;
9
+ export {};
@@ -0,0 +1,9 @@
1
+ import { type StringValueNode } from 'graphql';
2
+ interface ObjectWithDescription {
3
+ astNode?: {
4
+ description?: StringValueNode | null;
5
+ } | null;
6
+ description?: string | null;
7
+ }
8
+ export declare function getDescriptionNode(obj: ObjectWithDescription): StringValueNode | undefined;
9
+ export {};