@graphql-tools/load 7.7.2-alpha-25f2d2c4.0 → 7.7.2-alpha-20220809152812-1a2a11ba

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/cjs/documents.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadDocumentsSync = exports.loadDocuments = exports.NON_OPERATION_KINDS = exports.OPERATION_KINDS = void 0;
4
- const graphql_1 = require("@graphql-tools/graphql");
4
+ const graphql_1 = require("graphql");
5
5
  const load_typedefs_js_1 = require("./load-typedefs.js");
6
6
  /**
7
7
  * Kinds of AST nodes that are included in executable documents
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.filterKind = void 0;
4
- const graphql_1 = require("@graphql-tools/graphql");
4
+ const graphql_1 = require("graphql");
5
5
  const process_1 = require("process");
6
6
  /**
7
7
  * @internal
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.collectSourcesSync = exports.collectSources = void 0;
27
27
  const utils_1 = require("@graphql-tools/utils");
28
- const graphql_1 = require("@graphql-tools/graphql");
28
+ const graphql_1 = require("graphql");
29
29
  const load_file_js_1 = require("./load-file.js");
30
30
  const helpers_js_1 = require("../utils/helpers.js");
31
31
  const custom_loader_js_1 = require("../utils/custom-loader.js");
package/cjs/schema.js CHANGED
@@ -1,33 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadSchemaSync = exports.loadSchema = void 0;
4
- const load_typedefs_js_1 = require("./load-typedefs.js");
5
- const graphql_1 = require("@graphql-tools/graphql");
6
- const documents_js_1 = require("./documents.js");
4
+ const load_typedefs_1 = require("./load-typedefs");
5
+ const graphql_1 = require("graphql");
6
+ const documents_1 = require("./documents");
7
7
  const schema_1 = require("@graphql-tools/schema");
8
+ const utils_1 = require("@graphql-tools/utils");
9
+ const merge_1 = require("@graphql-tools/merge");
8
10
  /**
9
11
  * Asynchronously loads a schema from the provided pointers.
10
12
  * @param schemaPointers Pointers to the sources to load the schema from
11
13
  * @param options Additional options
12
14
  */
13
15
  async function loadSchema(schemaPointers, options) {
14
- var _a, _b;
15
- const sources = await (0, load_typedefs_js_1.loadTypedefs)(schemaPointers, {
16
+ const sources = await (0, load_typedefs_1.loadTypedefs)(schemaPointers, {
16
17
  ...options,
17
- filterKinds: documents_js_1.OPERATION_KINDS,
18
+ filterKinds: documents_1.OPERATION_KINDS,
18
19
  });
19
- const { schemas, typeDefs } = collectSchemasAndTypeDefs(sources);
20
- schemas.push(...((_a = options.schemas) !== null && _a !== void 0 ? _a : []));
21
- const mergeSchemasOptions = {
22
- ...options,
23
- schemas: schemas.concat((_b = options.schemas) !== null && _b !== void 0 ? _b : []),
24
- typeDefs,
25
- };
26
- const schema = (typeDefs === null || typeDefs === void 0 ? void 0 : typeDefs.length) === 0 && (schemas === null || schemas === void 0 ? void 0 : schemas.length) === 1 ? schemas[0] : (0, schema_1.mergeSchemas)(mergeSchemasOptions);
27
- if (options === null || options === void 0 ? void 0 : options.includeSources) {
28
- includeSources(schema, sources);
29
- }
30
- return options.sort ? (0, graphql_1.lexicographicSortSchema)(schema) : schema;
20
+ return getSchemaFromSources(sources, options);
31
21
  }
32
22
  exports.loadSchema = loadSchema;
33
23
  /**
@@ -36,20 +26,11 @@ exports.loadSchema = loadSchema;
36
26
  * @param options Additional options
37
27
  */
38
28
  function loadSchemaSync(schemaPointers, options) {
39
- const sources = (0, load_typedefs_js_1.loadTypedefsSync)(schemaPointers, {
40
- filterKinds: documents_js_1.OPERATION_KINDS,
29
+ const sources = (0, load_typedefs_1.loadTypedefsSync)(schemaPointers, {
30
+ filterKinds: documents_1.OPERATION_KINDS,
41
31
  ...options,
42
32
  });
43
- const { schemas, typeDefs } = collectSchemasAndTypeDefs(sources);
44
- const schema = (0, schema_1.mergeSchemas)({
45
- schemas,
46
- typeDefs,
47
- ...options,
48
- });
49
- if (options === null || options === void 0 ? void 0 : options.includeSources) {
50
- includeSources(schema, sources);
51
- }
52
- return options.sort ? (0, graphql_1.lexicographicSortSchema)(schema) : schema;
33
+ return getSchemaFromSources(sources, options);
53
34
  }
54
35
  exports.loadSchemaSync = loadSchemaSync;
55
36
  function includeSources(schema, sources) {
@@ -68,19 +49,42 @@ function includeSources(schema, sources) {
68
49
  extendedSources: sources,
69
50
  };
70
51
  }
71
- function collectSchemasAndTypeDefs(sources) {
72
- const schemas = [];
52
+ function getSchemaFromSources(sources, options) {
53
+ if (sources.length === 1 && sources[0].schema != null && options.typeDefs == null && options.resolvers == null) {
54
+ return options.sort ? (0, graphql_1.lexicographicSortSchema)(sources[0].schema) : sources[0].schema;
55
+ }
56
+ const { typeDefs, resolvers, schemaExtensions } = collectSchemaParts(sources);
57
+ const schema = (0, schema_1.mergeSchemas)({
58
+ ...options,
59
+ typeDefs,
60
+ resolvers,
61
+ schemaExtensions,
62
+ });
63
+ if (options === null || options === void 0 ? void 0 : options.includeSources) {
64
+ includeSources(schema, sources);
65
+ }
66
+ return options.sort ? (0, graphql_1.lexicographicSortSchema)(schema) : schema;
67
+ }
68
+ function collectSchemaParts(sources) {
73
69
  const typeDefs = [];
70
+ const resolvers = [];
71
+ const schemaExtensions = [];
74
72
  for (const source of sources) {
75
73
  if (source.schema) {
76
- schemas.push(source.schema);
74
+ typeDefs.push(source.schema);
75
+ resolvers.push((0, utils_1.getResolversFromSchema)(source.schema));
76
+ schemaExtensions.push((0, merge_1.extractExtensionsFromSchema)(source.schema));
77
77
  }
78
- else if (source.document) {
79
- typeDefs.push(source.document);
78
+ else {
79
+ const typeDef = source.document || source.rawSDL;
80
+ if (typeDef) {
81
+ typeDefs.push(typeDef);
82
+ }
80
83
  }
81
84
  }
82
85
  return {
83
- schemas,
84
86
  typeDefs,
87
+ resolvers,
88
+ schemaExtensions,
85
89
  };
86
90
  }
package/esm/documents.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Kind } from '@graphql-tools/graphql';
1
+ import { Kind } from 'graphql';
2
2
  import { loadTypedefs, loadTypedefsSync } from './load-typedefs.js';
3
3
  /**
4
4
  * Kinds of AST nodes that are included in executable documents
@@ -1,4 +1,4 @@
1
- import { Kind } from '@graphql-tools/graphql';
1
+ import { Kind } from 'graphql';
2
2
  import { env } from 'process';
3
3
  /**
4
4
  * @internal
@@ -1,5 +1,5 @@
1
1
  import { isDocumentString, parseGraphQLSDL, getDocumentNodeFromSchema, asArray } from '@graphql-tools/utils';
2
- import { isSchema, Kind } from '@graphql-tools/graphql';
2
+ import { isSchema, Kind } from 'graphql';
3
3
  import { loadFile, loadFileSync } from './load-file.js';
4
4
  import { stringToHash, useStack } from '../utils/helpers.js';
5
5
  import { useCustomLoader, useCustomLoaderSync } from '../utils/custom-loader.js';
package/esm/schema.js CHANGED
@@ -1,30 +1,20 @@
1
- import { loadTypedefs, loadTypedefsSync } from './load-typedefs.js';
2
- import { Source as GraphQLSource, print, lexicographicSortSchema, } from '@graphql-tools/graphql';
3
- import { OPERATION_KINDS } from './documents.js';
1
+ import { loadTypedefs, loadTypedefsSync } from './load-typedefs';
2
+ import { Source as GraphQLSource, print, lexicographicSortSchema } from 'graphql';
3
+ import { OPERATION_KINDS } from './documents';
4
4
  import { mergeSchemas } from '@graphql-tools/schema';
5
+ import { getResolversFromSchema } from '@graphql-tools/utils';
6
+ import { extractExtensionsFromSchema } from '@graphql-tools/merge';
5
7
  /**
6
8
  * Asynchronously loads a schema from the provided pointers.
7
9
  * @param schemaPointers Pointers to the sources to load the schema from
8
10
  * @param options Additional options
9
11
  */
10
12
  export async function loadSchema(schemaPointers, options) {
11
- var _a, _b;
12
13
  const sources = await loadTypedefs(schemaPointers, {
13
14
  ...options,
14
15
  filterKinds: OPERATION_KINDS,
15
16
  });
16
- const { schemas, typeDefs } = collectSchemasAndTypeDefs(sources);
17
- schemas.push(...((_a = options.schemas) !== null && _a !== void 0 ? _a : []));
18
- const mergeSchemasOptions = {
19
- ...options,
20
- schemas: schemas.concat((_b = options.schemas) !== null && _b !== void 0 ? _b : []),
21
- typeDefs,
22
- };
23
- 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);
24
- if (options === null || options === void 0 ? void 0 : options.includeSources) {
25
- includeSources(schema, sources);
26
- }
27
- return options.sort ? lexicographicSortSchema(schema) : schema;
17
+ return getSchemaFromSources(sources, options);
28
18
  }
29
19
  /**
30
20
  * Synchronously loads a schema from the provided pointers.
@@ -36,16 +26,7 @@ export function loadSchemaSync(schemaPointers, options) {
36
26
  filterKinds: OPERATION_KINDS,
37
27
  ...options,
38
28
  });
39
- const { schemas, typeDefs } = collectSchemasAndTypeDefs(sources);
40
- const schema = mergeSchemas({
41
- schemas,
42
- typeDefs,
43
- ...options,
44
- });
45
- if (options === null || options === void 0 ? void 0 : options.includeSources) {
46
- includeSources(schema, sources);
47
- }
48
- return options.sort ? lexicographicSortSchema(schema) : schema;
29
+ return getSchemaFromSources(sources, options);
49
30
  }
50
31
  function includeSources(schema, sources) {
51
32
  const finalSources = [];
@@ -63,19 +44,42 @@ function includeSources(schema, sources) {
63
44
  extendedSources: sources,
64
45
  };
65
46
  }
66
- function collectSchemasAndTypeDefs(sources) {
67
- const schemas = [];
47
+ function getSchemaFromSources(sources, options) {
48
+ if (sources.length === 1 && sources[0].schema != null && options.typeDefs == null && options.resolvers == null) {
49
+ return options.sort ? lexicographicSortSchema(sources[0].schema) : sources[0].schema;
50
+ }
51
+ const { typeDefs, resolvers, schemaExtensions } = collectSchemaParts(sources);
52
+ const schema = mergeSchemas({
53
+ ...options,
54
+ typeDefs,
55
+ resolvers,
56
+ schemaExtensions,
57
+ });
58
+ if (options === null || options === void 0 ? void 0 : options.includeSources) {
59
+ includeSources(schema, sources);
60
+ }
61
+ return options.sort ? lexicographicSortSchema(schema) : schema;
62
+ }
63
+ function collectSchemaParts(sources) {
68
64
  const typeDefs = [];
65
+ const resolvers = [];
66
+ const schemaExtensions = [];
69
67
  for (const source of sources) {
70
68
  if (source.schema) {
71
- schemas.push(source.schema);
69
+ typeDefs.push(source.schema);
70
+ resolvers.push(getResolversFromSchema(source.schema));
71
+ schemaExtensions.push(extractExtensionsFromSchema(source.schema));
72
72
  }
73
- else if (source.document) {
74
- typeDefs.push(source.document);
73
+ else {
74
+ const typeDef = source.document || source.rawSDL;
75
+ if (typeDef) {
76
+ typeDefs.push(typeDef);
77
+ }
75
78
  }
76
79
  }
77
80
  return {
78
- schemas,
79
81
  typeDefs,
82
+ resolvers,
83
+ schemaExtensions,
80
84
  };
81
85
  }
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@graphql-tools/load",
3
- "version": "7.7.2-alpha-25f2d2c4.0",
3
+ "version": "7.7.2-alpha-20220809152812-1a2a11ba",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
+ "peerDependencies": {
7
+ "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
8
+ },
6
9
  "dependencies": {
7
- "@graphql-tools/utils": "8.9.1-alpha-25f2d2c4.0",
8
- "@graphql-tools/schema": "8.5.2-alpha-25f2d2c4.0",
9
- "@graphql-tools/graphql": "0.1.0-alpha-25f2d2c4.0",
10
+ "@graphql-tools/utils": "8.9.1-alpha-20220809152812-1a2a11ba",
11
+ "@graphql-tools/schema": "9.0.0-alpha-20220809152812-1a2a11ba",
12
+ "@graphql-tools/merge": "8.3.2-alpha-20220809152812-1a2a11ba",
10
13
  "p-limit": "3.1.0",
11
14
  "tslib": "^2.4.0"
12
15
  },
@@ -1,5 +1,5 @@
1
1
  import { Source } from '@graphql-tools/utils';
2
- import { Kind } from '@graphql-tools/graphql';
2
+ import { Kind } from 'graphql';
3
3
  import { LoadTypedefsOptions, UnnormalizedTypeDefPointer } from './load-typedefs.cjs';
4
4
  declare type KindList = Array<typeof Kind[keyof typeof Kind]>;
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { Source } from '@graphql-tools/utils';
2
- import { Kind } from '@graphql-tools/graphql';
2
+ import { Kind } from 'graphql';
3
3
  import { LoadTypedefsOptions, UnnormalizedTypeDefPointer } from './load-typedefs.js';
4
4
  declare type KindList = Array<typeof Kind[keyof typeof Kind]>;
5
5
  /**
@@ -1,4 +1,4 @@
1
- import { DocumentNode } from '@graphql-tools/graphql';
1
+ import { DocumentNode } from 'graphql';
2
2
  /**
3
3
  * @internal
4
4
  */
@@ -1,4 +1,4 @@
1
- import { DocumentNode } from '@graphql-tools/graphql';
1
+ import { DocumentNode } from 'graphql';
2
2
  /**
3
3
  * @internal
4
4
  */
@@ -1,7 +1,7 @@
1
- import { LoadTypedefsOptions, UnnormalizedTypeDefPointer } from './load-typedefs.cjs';
2
- import { GraphQLSchema, BuildSchemaOptions } from '@graphql-tools/graphql';
3
- import { MergeSchemasConfig } from '@graphql-tools/schema';
4
- export declare type LoadSchemaOptions = BuildSchemaOptions & LoadTypedefsOptions & Partial<MergeSchemasConfig> & {
1
+ import { LoadTypedefsOptions, UnnormalizedTypeDefPointer } from './load-typedefs';
2
+ import { GraphQLSchema, BuildSchemaOptions } from 'graphql';
3
+ import { IExecutableSchemaDefinition } from '@graphql-tools/schema';
4
+ export declare type LoadSchemaOptions = BuildSchemaOptions & LoadTypedefsOptions & Partial<IExecutableSchemaDefinition> & {
5
5
  /**
6
6
  * Adds a list of Sources in to `extensions.sources`
7
7
  *
@@ -1,7 +1,7 @@
1
- import { LoadTypedefsOptions, UnnormalizedTypeDefPointer } from './load-typedefs.js';
2
- import { GraphQLSchema, BuildSchemaOptions } from '@graphql-tools/graphql';
3
- import { MergeSchemasConfig } from '@graphql-tools/schema';
4
- export declare type LoadSchemaOptions = BuildSchemaOptions & LoadTypedefsOptions & Partial<MergeSchemasConfig> & {
1
+ import { LoadTypedefsOptions, UnnormalizedTypeDefPointer } from './load-typedefs';
2
+ import { GraphQLSchema, BuildSchemaOptions } from 'graphql';
3
+ import { IExecutableSchemaDefinition } from '@graphql-tools/schema';
4
+ export declare type LoadSchemaOptions = BuildSchemaOptions & LoadTypedefsOptions & Partial<IExecutableSchemaDefinition> & {
5
5
  /**
6
6
  * Adds a list of Sources in to `extensions.sources`
7
7
  *