@graphql-tools/load 7.5.14-alpha-7052f15d.0 → 7.6.0-alpha-b3ffd406.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/index.js CHANGED
@@ -30,7 +30,6 @@ const pLimit = _interopDefault(require('p-limit'));
30
30
  const module$1 = require('module');
31
31
  const path = require('path');
32
32
  const schema = require('@graphql-tools/schema');
33
- const merge = require('@graphql-tools/merge');
34
33
 
35
34
  function normalizePointers(unnormalizedPointerOrPointers) {
36
35
  const ignore = [];
@@ -609,11 +608,23 @@ function loadDocumentsSync(pointerOrPointers, options) {
609
608
  * @param options Additional options
610
609
  */
611
610
  async function loadSchema(schemaPointers, options) {
611
+ var _a, _b;
612
612
  const sources = await loadTypedefs(schemaPointers, {
613
613
  ...options,
614
614
  filterKinds: OPERATION_KINDS,
615
615
  });
616
- return getSchemaFromSources(sources, options);
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;
617
628
  }
618
629
  /**
619
630
  * Synchronously loads a schema from the provided pointers.
@@ -625,7 +636,16 @@ function loadSchemaSync(schemaPointers, options) {
625
636
  filterKinds: OPERATION_KINDS,
626
637
  ...options,
627
638
  });
628
- return getSchemaFromSources(sources, options);
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;
629
649
  }
630
650
  function includeSources(schema, sources) {
631
651
  const finalSources = [];
@@ -643,40 +663,20 @@ function includeSources(schema, sources) {
643
663
  extendedSources: sources,
644
664
  };
645
665
  }
646
- function getSchemaFromSources(sources, options) {
647
- const { typeDefs, resolvers, schemaExtensions } = collectSchemaParts(sources);
648
- const schema$1 = schema.mergeSchemas({
649
- ...options,
650
- typeDefs,
651
- resolvers,
652
- schemaExtensions,
653
- });
654
- if (options === null || options === void 0 ? void 0 : options.includeSources) {
655
- includeSources(schema$1, sources);
656
- }
657
- return options.sort ? graphql.lexicographicSortSchema(schema$1) : schema$1;
658
- }
659
- function collectSchemaParts(sources) {
666
+ function collectSchemasAndTypeDefs(sources) {
667
+ const schemas = [];
660
668
  const typeDefs = [];
661
- const resolvers = [];
662
- const schemaExtensions = [];
663
669
  for (const source of sources) {
664
670
  if (source.schema) {
665
- typeDefs.push(source.schema);
666
- resolvers.push(utils.getResolversFromSchema(source.schema));
667
- schemaExtensions.push(merge.extractExtensionsFromSchema(source.schema));
671
+ schemas.push(source.schema);
668
672
  }
669
- else {
670
- const typeDef = source.document || source.rawSDL;
671
- if (typeDef) {
672
- typeDefs.push(typeDef);
673
- }
673
+ else if (source.document) {
674
+ typeDefs.push(source.document);
674
675
  }
675
676
  }
676
677
  return {
678
+ schemas,
677
679
  typeDefs,
678
- resolvers,
679
- schemaExtensions,
680
680
  };
681
681
  }
682
682
 
package/index.mjs CHANGED
@@ -1,11 +1,10 @@
1
- import { asArray, AggregateError, isDocumentString, parseGraphQLSDL, getDocumentNodeFromSchema, printSchemaWithDirectives, printWithComments, resetComments, compareStrings, getResolversFromSchema } from '@graphql-tools/utils';
1
+ import { asArray, AggregateError, isDocumentString, parseGraphQLSDL, getDocumentNodeFromSchema, printSchemaWithDirectives, printWithComments, resetComments, compareStrings } from '@graphql-tools/utils';
2
2
  import { cwd, env } from 'process';
3
3
  import { isSchema, Kind, lexicographicSortSchema, Source, print } from 'graphql';
4
4
  import pLimit from 'p-limit';
5
5
  import { createRequire } from 'module';
6
6
  import { join } from 'path';
7
7
  import { mergeSchemas } from '@graphql-tools/schema';
8
- import { extractExtensionsFromSchema } from '@graphql-tools/merge';
9
8
 
10
9
  function normalizePointers(unnormalizedPointerOrPointers) {
11
10
  const ignore = [];
@@ -584,11 +583,23 @@ function loadDocumentsSync(pointerOrPointers, options) {
584
583
  * @param options Additional options
585
584
  */
586
585
  async function loadSchema(schemaPointers, options) {
586
+ var _a, _b;
587
587
  const sources = await loadTypedefs(schemaPointers, {
588
588
  ...options,
589
589
  filterKinds: OPERATION_KINDS,
590
590
  });
591
- return getSchemaFromSources(sources, options);
591
+ const { schemas, typeDefs } = collectSchemasAndTypeDefs(sources);
592
+ schemas.push(...((_a = options.schemas) !== null && _a !== void 0 ? _a : []));
593
+ const mergeSchemasOptions = {
594
+ ...options,
595
+ schemas: schemas.concat((_b = options.schemas) !== null && _b !== void 0 ? _b : []),
596
+ typeDefs,
597
+ };
598
+ const schema = (typeDefs === null || typeDefs === void 0 ? void 0 : typeDefs.length) === 0 && (schemas === null || schemas === void 0 ? void 0 : schemas.length) === 1 ? schemas[0] : mergeSchemas(mergeSchemasOptions);
599
+ if (options === null || options === void 0 ? void 0 : options.includeSources) {
600
+ includeSources(schema, sources);
601
+ }
602
+ return options.sort ? lexicographicSortSchema(schema) : schema;
592
603
  }
593
604
  /**
594
605
  * Synchronously loads a schema from the provided pointers.
@@ -600,7 +611,16 @@ function loadSchemaSync(schemaPointers, options) {
600
611
  filterKinds: OPERATION_KINDS,
601
612
  ...options,
602
613
  });
603
- return getSchemaFromSources(sources, options);
614
+ const { schemas, typeDefs } = collectSchemasAndTypeDefs(sources);
615
+ const schema = mergeSchemas({
616
+ schemas,
617
+ typeDefs,
618
+ ...options,
619
+ });
620
+ if (options === null || options === void 0 ? void 0 : options.includeSources) {
621
+ includeSources(schema, sources);
622
+ }
623
+ return options.sort ? lexicographicSortSchema(schema) : schema;
604
624
  }
605
625
  function includeSources(schema, sources) {
606
626
  const finalSources = [];
@@ -618,40 +638,20 @@ function includeSources(schema, sources) {
618
638
  extendedSources: sources,
619
639
  };
620
640
  }
621
- function getSchemaFromSources(sources, options) {
622
- const { typeDefs, resolvers, schemaExtensions } = collectSchemaParts(sources);
623
- const schema = mergeSchemas({
624
- ...options,
625
- typeDefs,
626
- resolvers,
627
- schemaExtensions,
628
- });
629
- if (options === null || options === void 0 ? void 0 : options.includeSources) {
630
- includeSources(schema, sources);
631
- }
632
- return options.sort ? lexicographicSortSchema(schema) : schema;
633
- }
634
- function collectSchemaParts(sources) {
641
+ function collectSchemasAndTypeDefs(sources) {
642
+ const schemas = [];
635
643
  const typeDefs = [];
636
- const resolvers = [];
637
- const schemaExtensions = [];
638
644
  for (const source of sources) {
639
645
  if (source.schema) {
640
- typeDefs.push(source.schema);
641
- resolvers.push(getResolversFromSchema(source.schema));
642
- schemaExtensions.push(extractExtensionsFromSchema(source.schema));
646
+ schemas.push(source.schema);
643
647
  }
644
- else {
645
- const typeDef = source.document || source.rawSDL;
646
- if (typeDef) {
647
- typeDefs.push(typeDef);
648
- }
648
+ else if (source.document) {
649
+ typeDefs.push(source.document);
649
650
  }
650
651
  }
651
652
  return {
653
+ schemas,
652
654
  typeDefs,
653
- resolvers,
654
- schemaExtensions,
655
655
  };
656
656
  }
657
657
 
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@graphql-tools/load",
3
- "version": "7.5.14-alpha-7052f15d.0",
3
+ "version": "7.6.0-alpha-b3ffd406.0",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@graphql-tools/merge": "8.2.13",
11
- "@graphql-tools/schema": "9.0.0-alpha-7052f15d.0",
12
- "@graphql-tools/utils": "8.6.12",
10
+ "@graphql-tools/schema": "8.4.0-alpha-b3ffd406.0",
11
+ "@graphql-tools/utils": "8.7.0-alpha-b3ffd406.0",
13
12
  "p-limit": "3.1.0",
14
- "tslib": "~2.4.0"
13
+ "tslib": "^2.4.0"
15
14
  },
16
15
  "repository": {
17
16
  "type": "git",
package/schema.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { LoadTypedefsOptions, UnnormalizedTypeDefPointer } from './load-typedefs';
2
2
  import { GraphQLSchema, BuildSchemaOptions } from 'graphql';
3
- import { IExecutableSchemaDefinition } from '@graphql-tools/schema';
4
- export declare type LoadSchemaOptions = BuildSchemaOptions & LoadTypedefsOptions & Partial<IExecutableSchemaDefinition> & {
3
+ import { MergeSchemasConfig } from '@graphql-tools/schema';
4
+ export declare type LoadSchemaOptions = BuildSchemaOptions & LoadTypedefsOptions & Partial<MergeSchemasConfig> & {
5
5
  /**
6
6
  * Adds a list of Sources in to `extensions.sources`
7
7
  *