@graphql-mesh/merger-bare 0.14.2 → 0.15.0-alpha-8832b647f.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 (4) hide show
  1. package/index.d.ts +22 -1
  2. package/index.js +46 -33
  3. package/index.mjs +48 -35
  4. package/package.json +3 -4
package/index.d.ts CHANGED
@@ -4,5 +4,26 @@ export default class BareMerger implements MeshMerger {
4
4
  name: string;
5
5
  private logger;
6
6
  constructor(options: MeshMergerOptions);
7
- getUnifiedSchema({ rawSources, typeDefs, resolvers, transforms }: MeshMergerContext): Promise<GraphQLSchema>;
7
+ handleSingleSource({ rawSources: [rawSource], typeDefs, resolvers }: MeshMergerContext): {
8
+ schema: GraphQLSchema;
9
+ name: string;
10
+ executor?: import("@graphql-tools/utils").Executor<Record<string, any>, Record<string, any>>;
11
+ transforms: import("@graphql-mesh/types").MeshTransform<any>[];
12
+ contextVariables: Record<string, string>;
13
+ handler: import("@graphql-mesh/types").MeshHandler;
14
+ batch: boolean;
15
+ merge?: Record<string, import("@graphql-tools/delegate").MergedTypeConfig<any, any, Record<string, any>>>;
16
+ };
17
+ getUnifiedSchema({ rawSources, typeDefs, resolvers }: MeshMergerContext): Promise<{
18
+ schema: GraphQLSchema;
19
+ name: string;
20
+ executor?: import("@graphql-tools/utils").Executor<Record<string, any>, Record<string, any>>;
21
+ transforms: import("@graphql-mesh/types").MeshTransform<any>[];
22
+ contextVariables: Record<string, string>;
23
+ handler: import("@graphql-mesh/types").MeshHandler;
24
+ batch: boolean;
25
+ merge?: Record<string, import("@graphql-tools/delegate").MergedTypeConfig<any, any, Record<string, any>>>;
26
+ } | {
27
+ schema: GraphQLSchema;
28
+ }>;
8
29
  }
package/index.js CHANGED
@@ -1,62 +1,75 @@
1
1
  'use strict';
2
2
 
3
- const wrap = require('@graphql-tools/wrap');
4
3
  const utils = require('@graphql-mesh/utils');
5
4
  const schema = require('@graphql-tools/schema');
5
+ const utils$1 = require('@graphql-tools/utils');
6
+ const graphql = require('graphql');
6
7
 
7
8
  class BareMerger {
8
9
  constructor(options) {
9
10
  this.name = 'bare';
10
11
  this.logger = options.logger;
11
12
  }
12
- async getUnifiedSchema({ rawSources, typeDefs, resolvers, transforms }) {
13
+ handleSingleSource({ rawSources: [rawSource], typeDefs, resolvers }) {
14
+ let schema$1 = rawSource.schema;
15
+ if (typeDefs.length > 0 || utils$1.asArray(resolvers).length > 0) {
16
+ for (const typeDef of typeDefs) {
17
+ schema$1 = graphql.extendSchema(schema$1, typeDef);
18
+ }
19
+ for (const resolversObj of utils$1.asArray(resolvers)) {
20
+ schema.addResolversToSchema({
21
+ schema: schema$1,
22
+ resolvers: resolversObj,
23
+ updateResolversInPlace: true,
24
+ });
25
+ }
26
+ }
27
+ this.logger.debug(`Attaching a dummy sourceMap to the final schema`);
28
+ schema$1.extensions = schema$1.extensions || {};
29
+ Object.defineProperty(schema$1.extensions, 'sourceMap', {
30
+ get: () => {
31
+ return {
32
+ get() {
33
+ // We should return a version of the schema only with the source-level transforms
34
+ return utils.applySchemaTransforms(schema$1, rawSource, schema$1, rawSource.transforms);
35
+ },
36
+ };
37
+ },
38
+ });
39
+ return {
40
+ ...rawSource,
41
+ schema: schema$1,
42
+ };
43
+ }
44
+ async getUnifiedSchema({ rawSources, typeDefs, resolvers }) {
45
+ if (rawSources.length === 1) {
46
+ return this.handleSingleSource({ rawSources, typeDefs, resolvers });
47
+ }
13
48
  const sourceMap = new Map();
14
49
  this.logger.debug(`Applying transforms for each source`);
15
50
  const schemas = rawSources.map(source => {
16
51
  let schema = source.schema;
17
52
  let sourceLevelSchema = source.schema;
18
- const handlerLevelTransformGroups = utils.groupTransforms(source.transforms || []);
19
- if (handlerLevelTransformGroups.wrapTransforms.length > 0 || source.executor) {
20
- schema = wrap.wrapSchema({
21
- batch: true,
22
- ...source,
23
- schema,
24
- });
25
- }
26
- else {
27
- schema = utils.applySchemaTransforms(schema, undefined, schema, handlerLevelTransformGroups.noWrapTransforms);
28
- }
53
+ schema = utils.applySchemaTransforms(schema, undefined, schema, source.transforms);
29
54
  // After that step, it will be considered as root level schema
30
55
  sourceLevelSchema = schema;
31
56
  sourceMap.set(source, sourceLevelSchema);
32
57
  return schema;
33
58
  });
34
59
  this.logger.debug(`Merging sources`);
35
- let unifiedSchema = schemas.length === 1 && !(typeDefs === null || typeDefs === void 0 ? void 0 : typeDefs.length) && !resolvers
36
- ? schemas[0]
37
- : schema.mergeSchemas({
38
- schemas,
39
- typeDefs,
40
- resolvers,
41
- });
42
- this.logger.debug(`Handling root level transforms`);
43
- const rootLevelTransformGroups = utils.groupTransforms(transforms || []);
44
- if (rootLevelTransformGroups.wrapTransforms.length > 0) {
45
- unifiedSchema = wrap.wrapSchema({
46
- schema: unifiedSchema,
47
- batch: true,
48
- transforms,
49
- });
50
- }
51
- else {
52
- unifiedSchema = utils.applySchemaTransforms(unifiedSchema, undefined, unifiedSchema, rootLevelTransformGroups.noWrapTransforms);
53
- }
60
+ const unifiedSchema = schema.mergeSchemas({
61
+ schemas,
62
+ typeDefs,
63
+ resolvers,
64
+ });
54
65
  this.logger.debug(`Attaching sources to the unified schema`);
55
66
  unifiedSchema.extensions = unifiedSchema.extensions || {};
56
67
  Object.defineProperty(unifiedSchema.extensions, 'sourceMap', {
57
68
  get: () => sourceMap,
58
69
  });
59
- return unifiedSchema;
70
+ return {
71
+ schema: unifiedSchema,
72
+ };
60
73
  }
61
74
  }
62
75
 
package/index.mjs CHANGED
@@ -1,60 +1,73 @@
1
- import { wrapSchema } from '@graphql-tools/wrap';
2
- import { groupTransforms, applySchemaTransforms } from '@graphql-mesh/utils';
3
- import { mergeSchemas } from '@graphql-tools/schema';
1
+ import { applySchemaTransforms } from '@graphql-mesh/utils';
2
+ import { addResolversToSchema, mergeSchemas } from '@graphql-tools/schema';
3
+ import { asArray } from '@graphql-tools/utils';
4
+ import { extendSchema } from 'graphql';
4
5
 
5
6
  class BareMerger {
6
7
  constructor(options) {
7
8
  this.name = 'bare';
8
9
  this.logger = options.logger;
9
10
  }
10
- async getUnifiedSchema({ rawSources, typeDefs, resolvers, transforms }) {
11
+ handleSingleSource({ rawSources: [rawSource], typeDefs, resolvers }) {
12
+ let schema = rawSource.schema;
13
+ if (typeDefs.length > 0 || asArray(resolvers).length > 0) {
14
+ for (const typeDef of typeDefs) {
15
+ schema = extendSchema(schema, typeDef);
16
+ }
17
+ for (const resolversObj of asArray(resolvers)) {
18
+ addResolversToSchema({
19
+ schema,
20
+ resolvers: resolversObj,
21
+ updateResolversInPlace: true,
22
+ });
23
+ }
24
+ }
25
+ this.logger.debug(`Attaching a dummy sourceMap to the final schema`);
26
+ schema.extensions = schema.extensions || {};
27
+ Object.defineProperty(schema.extensions, 'sourceMap', {
28
+ get: () => {
29
+ return {
30
+ get() {
31
+ // We should return a version of the schema only with the source-level transforms
32
+ return applySchemaTransforms(schema, rawSource, schema, rawSource.transforms);
33
+ },
34
+ };
35
+ },
36
+ });
37
+ return {
38
+ ...rawSource,
39
+ schema,
40
+ };
41
+ }
42
+ async getUnifiedSchema({ rawSources, typeDefs, resolvers }) {
43
+ if (rawSources.length === 1) {
44
+ return this.handleSingleSource({ rawSources, typeDefs, resolvers });
45
+ }
11
46
  const sourceMap = new Map();
12
47
  this.logger.debug(`Applying transforms for each source`);
13
48
  const schemas = rawSources.map(source => {
14
49
  let schema = source.schema;
15
50
  let sourceLevelSchema = source.schema;
16
- const handlerLevelTransformGroups = groupTransforms(source.transforms || []);
17
- if (handlerLevelTransformGroups.wrapTransforms.length > 0 || source.executor) {
18
- schema = wrapSchema({
19
- batch: true,
20
- ...source,
21
- schema,
22
- });
23
- }
24
- else {
25
- schema = applySchemaTransforms(schema, undefined, schema, handlerLevelTransformGroups.noWrapTransforms);
26
- }
51
+ schema = applySchemaTransforms(schema, undefined, schema, source.transforms);
27
52
  // After that step, it will be considered as root level schema
28
53
  sourceLevelSchema = schema;
29
54
  sourceMap.set(source, sourceLevelSchema);
30
55
  return schema;
31
56
  });
32
57
  this.logger.debug(`Merging sources`);
33
- let unifiedSchema = schemas.length === 1 && !(typeDefs === null || typeDefs === void 0 ? void 0 : typeDefs.length) && !resolvers
34
- ? schemas[0]
35
- : mergeSchemas({
36
- schemas,
37
- typeDefs,
38
- resolvers,
39
- });
40
- this.logger.debug(`Handling root level transforms`);
41
- const rootLevelTransformGroups = groupTransforms(transforms || []);
42
- if (rootLevelTransformGroups.wrapTransforms.length > 0) {
43
- unifiedSchema = wrapSchema({
44
- schema: unifiedSchema,
45
- batch: true,
46
- transforms,
47
- });
48
- }
49
- else {
50
- unifiedSchema = applySchemaTransforms(unifiedSchema, undefined, unifiedSchema, rootLevelTransformGroups.noWrapTransforms);
51
- }
58
+ const unifiedSchema = mergeSchemas({
59
+ schemas,
60
+ typeDefs,
61
+ resolvers,
62
+ });
52
63
  this.logger.debug(`Attaching sources to the unified schema`);
53
64
  unifiedSchema.extensions = unifiedSchema.extensions || {};
54
65
  Object.defineProperty(unifiedSchema.extensions, 'sourceMap', {
55
66
  get: () => sourceMap,
56
67
  });
57
- return unifiedSchema;
68
+ return {
69
+ schema: unifiedSchema,
70
+ };
58
71
  }
59
72
  }
60
73
 
package/package.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
2
  "name": "@graphql-mesh/merger-bare",
3
- "version": "0.14.2",
3
+ "version": "0.15.0-alpha-8832b647f.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "*"
7
7
  },
8
8
  "dependencies": {
9
- "@graphql-mesh/types": "0.77.1",
10
- "@graphql-mesh/utils": "0.37.0",
9
+ "@graphql-mesh/types": "0.78.0-alpha-8832b647f.0",
10
+ "@graphql-mesh/utils": "0.37.1-alpha-8832b647f.0",
11
11
  "@graphql-tools/schema": "8.5.0",
12
12
  "@graphql-tools/utils": "8.8.0",
13
- "@graphql-tools/wrap": "8.5.0",
14
13
  "tslib": "^2.4.0"
15
14
  },
16
15
  "repository": {