@graphql-mesh/merger-bare 0.14.2 → 0.15.0-alpha-73f64556a.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.d.ts +22 -1
- package/index.js +34 -33
- package/index.mjs +36 -35
- 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
|
-
|
|
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,63 @@
|
|
|
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
|
-
|
|
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
|
+
return {
|
|
28
|
+
...rawSource,
|
|
29
|
+
schema: schema$1,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async getUnifiedSchema({ rawSources, typeDefs, resolvers }) {
|
|
33
|
+
if (rawSources.length === 1) {
|
|
34
|
+
return this.handleSingleSource({ rawSources, typeDefs, resolvers });
|
|
35
|
+
}
|
|
13
36
|
const sourceMap = new Map();
|
|
14
37
|
this.logger.debug(`Applying transforms for each source`);
|
|
15
38
|
const schemas = rawSources.map(source => {
|
|
16
39
|
let schema = source.schema;
|
|
17
40
|
let sourceLevelSchema = source.schema;
|
|
18
|
-
|
|
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
|
-
}
|
|
41
|
+
schema = utils.applySchemaTransforms(schema, undefined, schema, source.transforms);
|
|
29
42
|
// After that step, it will be considered as root level schema
|
|
30
43
|
sourceLevelSchema = schema;
|
|
31
44
|
sourceMap.set(source, sourceLevelSchema);
|
|
32
45
|
return schema;
|
|
33
46
|
});
|
|
34
47
|
this.logger.debug(`Merging sources`);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
}
|
|
48
|
+
const unifiedSchema = schema.mergeSchemas({
|
|
49
|
+
schemas,
|
|
50
|
+
typeDefs,
|
|
51
|
+
resolvers,
|
|
52
|
+
});
|
|
54
53
|
this.logger.debug(`Attaching sources to the unified schema`);
|
|
55
54
|
unifiedSchema.extensions = unifiedSchema.extensions || {};
|
|
56
55
|
Object.defineProperty(unifiedSchema.extensions, 'sourceMap', {
|
|
57
56
|
get: () => sourceMap,
|
|
58
57
|
});
|
|
59
|
-
return
|
|
58
|
+
return {
|
|
59
|
+
schema: unifiedSchema,
|
|
60
|
+
};
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
|
package/index.mjs
CHANGED
|
@@ -1,60 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
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
|
+
return {
|
|
26
|
+
...rawSource,
|
|
27
|
+
schema,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async getUnifiedSchema({ rawSources, typeDefs, resolvers }) {
|
|
31
|
+
if (rawSources.length === 1) {
|
|
32
|
+
return this.handleSingleSource({ rawSources, typeDefs, resolvers });
|
|
33
|
+
}
|
|
11
34
|
const sourceMap = new Map();
|
|
12
35
|
this.logger.debug(`Applying transforms for each source`);
|
|
13
36
|
const schemas = rawSources.map(source => {
|
|
14
37
|
let schema = source.schema;
|
|
15
38
|
let sourceLevelSchema = source.schema;
|
|
16
|
-
|
|
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
|
-
}
|
|
39
|
+
schema = applySchemaTransforms(schema, undefined, schema, source.transforms);
|
|
27
40
|
// After that step, it will be considered as root level schema
|
|
28
41
|
sourceLevelSchema = schema;
|
|
29
42
|
sourceMap.set(source, sourceLevelSchema);
|
|
30
43
|
return schema;
|
|
31
44
|
});
|
|
32
45
|
this.logger.debug(`Merging sources`);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
}
|
|
46
|
+
const unifiedSchema = mergeSchemas({
|
|
47
|
+
schemas,
|
|
48
|
+
typeDefs,
|
|
49
|
+
resolvers,
|
|
50
|
+
});
|
|
52
51
|
this.logger.debug(`Attaching sources to the unified schema`);
|
|
53
52
|
unifiedSchema.extensions = unifiedSchema.extensions || {};
|
|
54
53
|
Object.defineProperty(unifiedSchema.extensions, 'sourceMap', {
|
|
55
54
|
get: () => sourceMap,
|
|
56
55
|
});
|
|
57
|
-
return
|
|
56
|
+
return {
|
|
57
|
+
schema: unifiedSchema,
|
|
58
|
+
};
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/merger-bare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0-alpha-73f64556a.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "*"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@graphql-mesh/types": "0.
|
|
10
|
-
"@graphql-mesh/utils": "0.37.0",
|
|
9
|
+
"@graphql-mesh/types": "0.78.0-alpha-73f64556a.0",
|
|
10
|
+
"@graphql-mesh/utils": "0.37.1-alpha-73f64556a.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": {
|