@graphql-tools/load 7.6.0 → 7.7.0-alpha-b76ec274.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.
Files changed (45) hide show
  1. package/cjs/documents.js +39 -0
  2. package/cjs/filter-document-kind.js +35 -0
  3. package/cjs/index.js +7 -0
  4. package/cjs/load-typedefs/collect-sources.js +195 -0
  5. package/cjs/load-typedefs/load-file.js +86 -0
  6. package/cjs/load-typedefs/options.js +10 -0
  7. package/cjs/load-typedefs/parse.js +62 -0
  8. package/cjs/load-typedefs.js +84 -0
  9. package/cjs/package.json +1 -0
  10. package/cjs/schema.js +86 -0
  11. package/cjs/utils/custom-loader.js +50 -0
  12. package/cjs/utils/helpers.js +42 -0
  13. package/cjs/utils/pointers.js +31 -0
  14. package/cjs/utils/queue.js +32 -0
  15. package/esm/documents.js +34 -0
  16. package/esm/filter-document-kind.js +31 -0
  17. package/esm/index.js +4 -0
  18. package/esm/load-typedefs/collect-sources.js +167 -0
  19. package/esm/load-typedefs/load-file.js +81 -0
  20. package/esm/load-typedefs/options.js +6 -0
  21. package/esm/load-typedefs/parse.js +58 -0
  22. package/esm/load-typedefs.js +79 -0
  23. package/esm/schema.js +81 -0
  24. package/esm/utils/custom-loader.js +44 -0
  25. package/esm/utils/helpers.js +35 -0
  26. package/esm/utils/pointers.js +27 -0
  27. package/esm/utils/queue.js +26 -0
  28. package/package.json +33 -12
  29. package/{documents.d.ts → typings/documents.d.ts} +1 -1
  30. package/{filter-document-kind.d.ts → typings/filter-document-kind.d.ts} +0 -0
  31. package/typings/index.d.ts +4 -0
  32. package/{load-typedefs → typings/load-typedefs}/collect-sources.d.ts +1 -1
  33. package/{load-typedefs → typings/load-typedefs}/load-file.d.ts +1 -1
  34. package/{load-typedefs → typings/load-typedefs}/options.d.ts +1 -1
  35. package/{load-typedefs → typings/load-typedefs}/parse.d.ts +0 -0
  36. package/{load-typedefs.d.ts → typings/load-typedefs.d.ts} +0 -0
  37. package/{schema.d.ts → typings/schema.d.ts} +1 -1
  38. package/{utils → typings/utils}/custom-loader.d.ts +0 -0
  39. package/{utils → typings/utils}/helpers.d.ts +0 -0
  40. package/{utils → typings/utils}/pointers.d.ts +1 -1
  41. package/{utils → typings/utils}/queue.d.ts +0 -0
  42. package/README.md +0 -8
  43. package/index.d.ts +0 -4
  44. package/index.js +0 -691
  45. package/index.mjs +0 -658
package/index.js DELETED
@@ -1,691 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) { return e; } else {
9
- var n = {};
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () {
16
- return e[k];
17
- }
18
- });
19
- });
20
- }
21
- n['default'] = e;
22
- return n;
23
- }
24
- }
25
-
26
- const utils = require('@graphql-tools/utils');
27
- const process = require('process');
28
- const graphql = require('graphql');
29
- const pLimit = _interopDefault(require('p-limit'));
30
- const module$1 = require('module');
31
- const path = require('path');
32
- const schema = require('@graphql-tools/schema');
33
-
34
- function normalizePointers(unnormalizedPointerOrPointers) {
35
- const ignore = [];
36
- const pointerOptionMap = {};
37
- const handlePointer = (rawPointer, options = {}) => {
38
- if (rawPointer.startsWith('!')) {
39
- ignore.push(rawPointer.replace('!', ''));
40
- }
41
- else {
42
- pointerOptionMap[rawPointer] = options;
43
- }
44
- };
45
- for (const rawPointer of utils.asArray(unnormalizedPointerOrPointers)) {
46
- if (typeof rawPointer === 'string') {
47
- handlePointer(rawPointer);
48
- }
49
- else if (typeof rawPointer === 'object') {
50
- for (const [path, options] of Object.entries(rawPointer)) {
51
- handlePointer(path, options);
52
- }
53
- }
54
- else {
55
- throw new Error(`Invalid pointer '${rawPointer}'.`);
56
- }
57
- }
58
- return { ignore, pointerOptionMap };
59
- }
60
-
61
- function applyDefaultOptions(options) {
62
- options.cache = options.cache || {};
63
- options.cwd = options.cwd || process.cwd();
64
- options.sort = 'sort' in options ? options.sort : true;
65
- }
66
-
67
- async function loadFile(pointer, options) {
68
- var _a;
69
- let results = (_a = options.cache) === null || _a === void 0 ? void 0 : _a[pointer];
70
- if (!results) {
71
- results = [];
72
- const errors = [];
73
- await Promise.all(options.loaders.map(async (loader) => {
74
- try {
75
- const loaderResults = await loader.load(pointer, options);
76
- loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
77
- }
78
- catch (error) {
79
- if (process.env['DEBUG']) {
80
- console.error(error);
81
- }
82
- if (error instanceof utils.AggregateError) {
83
- for (const errorElement of error.errors) {
84
- errors.push(errorElement);
85
- }
86
- }
87
- else {
88
- errors.push(error);
89
- }
90
- }
91
- }));
92
- if (results.length === 0 && errors.length > 0) {
93
- if (errors.length === 1) {
94
- throw errors[0];
95
- }
96
- throw new utils.AggregateError(errors, `Failed to find any GraphQL type definitions in: ${pointer};\n - ${errors
97
- .map(error => error.message)
98
- .join('\n - ')}`);
99
- }
100
- if (options.cache) {
101
- options.cache[pointer] = results;
102
- }
103
- }
104
- return results;
105
- }
106
- function loadFileSync(pointer, options) {
107
- var _a;
108
- let results = (_a = options.cache) === null || _a === void 0 ? void 0 : _a[pointer];
109
- if (!results) {
110
- results = [];
111
- const errors = [];
112
- for (const loader of options.loaders) {
113
- try {
114
- // We check for the existence so it is okay to force non null
115
- const loaderResults = loader.loadSync(pointer, options);
116
- loaderResults === null || loaderResults === void 0 ? void 0 : loaderResults.forEach(result => results.push(result));
117
- }
118
- catch (error) {
119
- if (process.env['DEBUG']) {
120
- console.error(error);
121
- }
122
- if (error instanceof utils.AggregateError) {
123
- for (const errorElement of error.errors) {
124
- errors.push(errorElement);
125
- }
126
- }
127
- else {
128
- errors.push(error);
129
- }
130
- }
131
- }
132
- if (results.length === 0 && errors.length > 0) {
133
- if (errors.length === 1) {
134
- throw errors[0];
135
- }
136
- throw new utils.AggregateError(errors, `Failed to find any GraphQL type definitions in: ${pointer};\n - ${errors
137
- .map(error => error.message)
138
- .join('\n - ')}`);
139
- }
140
- if (options.cache) {
141
- options.cache[pointer] = results;
142
- }
143
- }
144
- return results;
145
- }
146
-
147
- /**
148
- * Converts a string to 32bit integer
149
- */
150
- function stringToHash(str) {
151
- let hash = 0;
152
- if (str.length === 0) {
153
- return hash;
154
- }
155
- let char;
156
- for (let i = 0; i < str.length; i++) {
157
- char = str.charCodeAt(i);
158
- // tslint:disable-next-line: no-bitwise
159
- hash = (hash << 5) - hash + char;
160
- // tslint:disable-next-line: no-bitwise
161
- hash = hash & hash;
162
- }
163
- return hash;
164
- }
165
- function useStack(...fns) {
166
- return (input) => {
167
- function createNext(i) {
168
- if (i >= fns.length) {
169
- return () => { };
170
- }
171
- return function next() {
172
- fns[i](input, createNext(i + 1));
173
- };
174
- }
175
- fns[0](input, createNext(1));
176
- };
177
- }
178
- function useLimit(concurrency) {
179
- return pLimit(concurrency);
180
- }
181
-
182
- function getCustomLoaderByPath(path$1, cwd) {
183
- try {
184
- const requireFn = module$1.createRequire(path.join(cwd, 'noop.js'));
185
- const requiredModule = requireFn(path$1);
186
- if (requiredModule) {
187
- if (requiredModule.default && typeof requiredModule.default === 'function') {
188
- return requiredModule.default;
189
- }
190
- if (typeof requiredModule === 'function') {
191
- return requiredModule;
192
- }
193
- }
194
- }
195
- catch (e) { }
196
- return null;
197
- }
198
- async function useCustomLoader(loaderPointer, cwd) {
199
- let loader;
200
- if (typeof loaderPointer === 'string') {
201
- loader = await getCustomLoaderByPath(loaderPointer, cwd);
202
- }
203
- else if (typeof loaderPointer === 'function') {
204
- loader = loaderPointer;
205
- }
206
- if (typeof loader !== 'function') {
207
- throw new Error(`Failed to load custom loader: ${loaderPointer}`);
208
- }
209
- return loader;
210
- }
211
- function useCustomLoaderSync(loaderPointer, cwd) {
212
- let loader;
213
- if (typeof loaderPointer === 'string') {
214
- loader = getCustomLoaderByPath(loaderPointer, cwd);
215
- }
216
- else if (typeof loaderPointer === 'function') {
217
- loader = loaderPointer;
218
- }
219
- if (typeof loader !== 'function') {
220
- throw new Error(`Failed to load custom loader: ${loaderPointer}`);
221
- }
222
- return loader;
223
- }
224
-
225
- function useQueue(options) {
226
- const queue = [];
227
- const limit = (options === null || options === void 0 ? void 0 : options.concurrency) ? pLimit(options.concurrency) : async (fn) => fn();
228
- return {
229
- add(fn) {
230
- queue.push(() => limit(fn));
231
- },
232
- runAll() {
233
- return Promise.all(queue.map(fn => fn()));
234
- },
235
- };
236
- }
237
- function useSyncQueue() {
238
- const queue = [];
239
- return {
240
- add(fn) {
241
- queue.push(fn);
242
- },
243
- runAll() {
244
- for (const fn of queue) {
245
- fn();
246
- }
247
- },
248
- };
249
- }
250
-
251
- const CONCURRENCY_LIMIT = 50;
252
- async function collectSources({ pointerOptionMap, options, }) {
253
- const sources = [];
254
- const queue = useQueue({ concurrency: CONCURRENCY_LIMIT });
255
- const { addSource, collect } = createHelpers({
256
- sources,
257
- stack: [collectDocumentString, collectCustomLoader, collectFallback],
258
- });
259
- for (const pointer in pointerOptionMap) {
260
- const pointerOptions = pointerOptionMap[pointer];
261
- collect({
262
- pointer,
263
- pointerOptions,
264
- pointerOptionMap,
265
- options,
266
- addSource,
267
- queue: queue.add,
268
- });
269
- }
270
- await queue.runAll();
271
- return sources;
272
- }
273
- function collectSourcesSync({ pointerOptionMap, options, }) {
274
- const sources = [];
275
- const queue = useSyncQueue();
276
- const { addSource, collect } = createHelpers({
277
- sources,
278
- stack: [collectDocumentString, collectCustomLoaderSync, collectFallbackSync],
279
- });
280
- for (const pointer in pointerOptionMap) {
281
- const pointerOptions = pointerOptionMap[pointer];
282
- collect({
283
- pointer,
284
- pointerOptions,
285
- pointerOptionMap,
286
- options,
287
- addSource,
288
- queue: queue.add,
289
- });
290
- }
291
- queue.runAll();
292
- return sources;
293
- }
294
- function createHelpers({ sources, stack }) {
295
- const addSource = ({ source }) => {
296
- sources.push(source);
297
- };
298
- const collect = useStack(...stack);
299
- return {
300
- addSource,
301
- collect,
302
- };
303
- }
304
- function addResultOfCustomLoader({ pointer, result, addSource, }) {
305
- if (graphql.isSchema(result)) {
306
- addSource({
307
- source: {
308
- location: pointer,
309
- schema: result,
310
- document: utils.getDocumentNodeFromSchema(result),
311
- },
312
- pointer,
313
- noCache: true,
314
- });
315
- }
316
- else if (result.kind && result.kind === graphql.Kind.DOCUMENT) {
317
- addSource({
318
- source: {
319
- document: result,
320
- location: pointer,
321
- },
322
- pointer,
323
- });
324
- }
325
- else if (result.document) {
326
- addSource({
327
- source: {
328
- location: pointer,
329
- ...result,
330
- },
331
- pointer,
332
- });
333
- }
334
- }
335
- function collectDocumentString({ pointer, pointerOptions, options, addSource, queue }, next) {
336
- if (utils.isDocumentString(pointer)) {
337
- return queue(() => {
338
- const source = utils.parseGraphQLSDL(`${stringToHash(pointer)}.graphql`, pointer, {
339
- ...options,
340
- ...pointerOptions,
341
- });
342
- addSource({
343
- source,
344
- pointer,
345
- });
346
- });
347
- }
348
- next();
349
- }
350
- function collectCustomLoader({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
351
- if (pointerOptions.loader) {
352
- return queue(async () => {
353
- await Promise.all(utils.asArray(pointerOptions.require).map(m => new Promise(function (resolve) { resolve(_interopNamespace(require(m))); })));
354
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
355
- // @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
356
- const loader = await useCustomLoader(pointerOptions.loader, options.cwd);
357
- const result = await loader(pointer, { ...options, ...pointerOptions }, pointerOptionMap);
358
- if (!result) {
359
- return;
360
- }
361
- addResultOfCustomLoader({ pointer, result, addSource });
362
- });
363
- }
364
- next();
365
- }
366
- function collectCustomLoaderSync({ pointer, pointerOptions, queue, addSource, options, pointerOptionMap }, next) {
367
- if (pointerOptions.loader) {
368
- return queue(() => {
369
- const cwdRequire = module$1.createRequire(options.cwd || process.cwd());
370
- for (const m of utils.asArray(pointerOptions.require)) {
371
- cwdRequire(m);
372
- }
373
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
374
- // @ts-ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
375
- const loader = useCustomLoaderSync(pointerOptions.loader, options.cwd);
376
- const result = loader(pointer, { ...options, ...pointerOptions }, pointerOptionMap);
377
- if (result) {
378
- addResultOfCustomLoader({ pointer, result, addSource });
379
- }
380
- });
381
- }
382
- next();
383
- }
384
- function collectFallback({ queue, pointer, options, pointerOptions, addSource }) {
385
- return queue(async () => {
386
- const sources = await loadFile(pointer, {
387
- ...options,
388
- ...pointerOptions,
389
- });
390
- if (sources) {
391
- for (const source of sources) {
392
- addSource({ source, pointer });
393
- }
394
- }
395
- });
396
- }
397
- function collectFallbackSync({ queue, pointer, options, pointerOptions, addSource }) {
398
- return queue(() => {
399
- const sources = loadFileSync(pointer, {
400
- ...options,
401
- ...pointerOptions,
402
- });
403
- if (sources) {
404
- for (const source of sources) {
405
- addSource({ source, pointer });
406
- }
407
- }
408
- });
409
- }
410
-
411
- /**
412
- * @internal
413
- */
414
- const filterKind = (content, filterKinds) => {
415
- if (content && content.definitions && content.definitions.length && filterKinds && filterKinds.length > 0) {
416
- const invalidDefinitions = [];
417
- const validDefinitions = [];
418
- for (const definitionNode of content.definitions) {
419
- if (filterKinds.includes(definitionNode.kind)) {
420
- invalidDefinitions.push(definitionNode);
421
- }
422
- else {
423
- validDefinitions.push(definitionNode);
424
- }
425
- }
426
- if (invalidDefinitions.length > 0) {
427
- if (process.env['DEBUG']) {
428
- for (const d of invalidDefinitions) {
429
- console.log(`Filtered document of kind ${d.kind} due to filter policy (${filterKinds.join(', ')})`);
430
- }
431
- }
432
- }
433
- return {
434
- kind: graphql.Kind.DOCUMENT,
435
- definitions: validDefinitions,
436
- };
437
- }
438
- return content;
439
- };
440
-
441
- function parseSource({ partialSource, options, pointerOptionMap, addValidSource }) {
442
- if (partialSource) {
443
- const input = prepareInput({
444
- source: partialSource,
445
- options,
446
- pointerOptionMap,
447
- });
448
- parseSchema(input);
449
- parseRawSDL(input);
450
- if (input.source.document) {
451
- useKindsFilter(input);
452
- useComments(input);
453
- collectValidSources(input, addValidSource);
454
- }
455
- }
456
- }
457
- //
458
- function prepareInput({ source, options, pointerOptionMap, }) {
459
- let specificOptions = {
460
- ...options,
461
- };
462
- if (source.location) {
463
- specificOptions = {
464
- ...specificOptions,
465
- ...pointerOptionMap[source.location],
466
- };
467
- }
468
- return { source: { ...source }, options: specificOptions };
469
- }
470
- function parseSchema(input) {
471
- if (input.source.schema) {
472
- input.source.rawSDL = utils.printSchemaWithDirectives(input.source.schema, input.options);
473
- }
474
- }
475
- function parseRawSDL(input) {
476
- if (input.source.rawSDL) {
477
- input.source.document = utils.parseGraphQLSDL(input.source.location, input.source.rawSDL, input.options).document;
478
- }
479
- }
480
- function useKindsFilter(input) {
481
- if (input.options.filterKinds) {
482
- input.source.document = filterKind(input.source.document, input.options.filterKinds);
483
- }
484
- }
485
- function useComments(input) {
486
- if (!input.source.rawSDL && input.source.document) {
487
- input.source.rawSDL = utils.printWithComments(input.source.document);
488
- utils.resetComments();
489
- }
490
- }
491
- function collectValidSources(input, addValidSource) {
492
- var _a;
493
- if (((_a = input.source.document) === null || _a === void 0 ? void 0 : _a.definitions) && input.source.document.definitions.length > 0) {
494
- addValidSource(input.source);
495
- }
496
- }
497
-
498
- const CONCURRENCY_LIMIT$1 = 100;
499
- /**
500
- * Asynchronously loads any GraphQL documents (i.e. executable documents like
501
- * operations and fragments as well as type system definitions) from the
502
- * provided pointers.
503
- * loadTypedefs does not merge the typeDefs when `#import` is used ( https://github.com/ardatan/graphql-tools/issues/2980#issuecomment-1003692728 )
504
- * @param pointerOrPointers Pointers to the sources to load the documents from
505
- * @param options Additional options
506
- */
507
- async function loadTypedefs(pointerOrPointers, options) {
508
- const { ignore, pointerOptionMap } = normalizePointers(pointerOrPointers);
509
- options.ignore = utils.asArray(options.ignore || []);
510
- options.ignore.push(...ignore);
511
- applyDefaultOptions(options);
512
- const sources = await collectSources({
513
- pointerOptionMap,
514
- options,
515
- });
516
- const validSources = [];
517
- // If we have few k of files it may be an issue
518
- const limit = useLimit(CONCURRENCY_LIMIT$1);
519
- await Promise.all(sources.map(partialSource => limit(() => parseSource({
520
- partialSource,
521
- options,
522
- pointerOptionMap,
523
- addValidSource(source) {
524
- validSources.push(source);
525
- },
526
- }))));
527
- return prepareResult({ options, pointerOptionMap, validSources });
528
- }
529
- /**
530
- * Synchronously loads any GraphQL documents (i.e. executable documents like
531
- * operations and fragments as well as type system definitions) from the
532
- * provided pointers.
533
- * @param pointerOrPointers Pointers to the sources to load the documents from
534
- * @param options Additional options
535
- */
536
- function loadTypedefsSync(pointerOrPointers, options) {
537
- const { ignore, pointerOptionMap } = normalizePointers(pointerOrPointers);
538
- options.ignore = utils.asArray(options.ignore || []).concat(ignore);
539
- applyDefaultOptions(options);
540
- const sources = collectSourcesSync({
541
- pointerOptionMap,
542
- options,
543
- });
544
- const validSources = [];
545
- for (const partialSource of sources) {
546
- parseSource({
547
- partialSource,
548
- options,
549
- pointerOptionMap,
550
- addValidSource(source) {
551
- validSources.push(source);
552
- },
553
- });
554
- }
555
- return prepareResult({ options, pointerOptionMap, validSources });
556
- }
557
- //
558
- function prepareResult({ options, pointerOptionMap, validSources, }) {
559
- const pointerList = Object.keys(pointerOptionMap);
560
- if (pointerList.length > 0 && validSources.length === 0) {
561
- throw new Error(`
562
- Unable to find any GraphQL type definitions for the following pointers:
563
- ${pointerList.map(p => `
564
- - ${p}
565
- `)}`);
566
- }
567
- return options.sort
568
- ? validSources.sort((left, right) => utils.compareStrings(left.location, right.location))
569
- : validSources;
570
- }
571
-
572
- /**
573
- * Kinds of AST nodes that are included in executable documents
574
- */
575
- const OPERATION_KINDS = [graphql.Kind.OPERATION_DEFINITION, graphql.Kind.FRAGMENT_DEFINITION];
576
- /**
577
- * Kinds of AST nodes that are included in type system definition documents
578
- */
579
- const NON_OPERATION_KINDS = Object.keys(graphql.Kind)
580
- .reduce((prev, v) => [...prev, graphql.Kind[v]], [])
581
- .filter(v => !OPERATION_KINDS.includes(v));
582
- /**
583
- * Asynchronously loads executable documents (i.e. operations and fragments) from
584
- * the provided pointers. The pointers may be individual files or a glob pattern.
585
- * The files themselves may be `.graphql` files or `.js` and `.ts` (in which
586
- * case they will be parsed using graphql-tag-pluck).
587
- * @param pointerOrPointers Pointers to the files to load the documents from
588
- * @param options Additional options
589
- */
590
- function loadDocuments(pointerOrPointers, options) {
591
- return loadTypedefs(pointerOrPointers, { noRequire: true, filterKinds: NON_OPERATION_KINDS, ...options });
592
- }
593
- /**
594
- * Synchronously loads executable documents (i.e. operations and fragments) from
595
- * the provided pointers. The pointers may be individual files or a glob pattern.
596
- * The files themselves may be `.graphql` files or `.js` and `.ts` (in which
597
- * case they will be parsed using graphql-tag-pluck).
598
- * @param pointerOrPointers Pointers to the files to load the documents from
599
- * @param options Additional options
600
- */
601
- function loadDocumentsSync(pointerOrPointers, options) {
602
- return loadTypedefsSync(pointerOrPointers, { noRequire: true, filterKinds: NON_OPERATION_KINDS, ...options });
603
- }
604
-
605
- /**
606
- * Asynchronously loads a schema from the provided pointers.
607
- * @param schemaPointers Pointers to the sources to load the schema from
608
- * @param options Additional options
609
- */
610
- async function loadSchema(schemaPointers, options) {
611
- var _a, _b;
612
- const sources = await loadTypedefs(schemaPointers, {
613
- ...options,
614
- filterKinds: OPERATION_KINDS,
615
- });
616
- const { schemas, typeDefs } = collectSchemasAndTypeDefs(sources);
617
- schemas.push(...((_a = options.schemas) !== null && _a !== void 0 ? _a : []));
618
- const mergeSchemasOptions = {
619
- ...options,
620
- schemas: schemas.concat((_b = options.schemas) !== null && _b !== void 0 ? _b : []),
621
- typeDefs,
622
- };
623
- const schema$1 = (typeDefs === null || typeDefs === void 0 ? void 0 : typeDefs.length) === 0 && (schemas === null || schemas === void 0 ? void 0 : schemas.length) === 1 ? schemas[0] : schema.mergeSchemas(mergeSchemasOptions);
624
- if (options === null || options === void 0 ? void 0 : options.includeSources) {
625
- includeSources(schema$1, sources);
626
- }
627
- return options.sort ? graphql.lexicographicSortSchema(schema$1) : schema$1;
628
- }
629
- /**
630
- * Synchronously loads a schema from the provided pointers.
631
- * @param schemaPointers Pointers to the sources to load the schema from
632
- * @param options Additional options
633
- */
634
- function loadSchemaSync(schemaPointers, options) {
635
- const sources = loadTypedefsSync(schemaPointers, {
636
- filterKinds: OPERATION_KINDS,
637
- ...options,
638
- });
639
- const { schemas, typeDefs } = collectSchemasAndTypeDefs(sources);
640
- const schema$1 = schema.mergeSchemas({
641
- schemas,
642
- typeDefs,
643
- ...options,
644
- });
645
- if (options === null || options === void 0 ? void 0 : options.includeSources) {
646
- includeSources(schema$1, sources);
647
- }
648
- return options.sort ? graphql.lexicographicSortSchema(schema$1) : schema$1;
649
- }
650
- function includeSources(schema, sources) {
651
- const finalSources = [];
652
- for (const source of sources) {
653
- if (source.rawSDL) {
654
- finalSources.push(new graphql.Source(source.rawSDL, source.location));
655
- }
656
- else if (source.document) {
657
- finalSources.push(new graphql.Source(graphql.print(source.document), source.location));
658
- }
659
- }
660
- schema.extensions = {
661
- ...schema.extensions,
662
- sources: finalSources,
663
- extendedSources: sources,
664
- };
665
- }
666
- function collectSchemasAndTypeDefs(sources) {
667
- const schemas = [];
668
- const typeDefs = [];
669
- for (const source of sources) {
670
- if (source.schema) {
671
- schemas.push(source.schema);
672
- }
673
- else if (source.document) {
674
- typeDefs.push(source.document);
675
- }
676
- }
677
- return {
678
- schemas,
679
- typeDefs,
680
- };
681
- }
682
-
683
- exports.NON_OPERATION_KINDS = NON_OPERATION_KINDS;
684
- exports.OPERATION_KINDS = OPERATION_KINDS;
685
- exports.filterKind = filterKind;
686
- exports.loadDocuments = loadDocuments;
687
- exports.loadDocumentsSync = loadDocumentsSync;
688
- exports.loadSchema = loadSchema;
689
- exports.loadSchemaSync = loadSchemaSync;
690
- exports.loadTypedefs = loadTypedefs;
691
- exports.loadTypedefsSync = loadTypedefsSync;