@graphql-mesh/merger-stitching
Version:
58 lines (57 loc) • 2.25 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const stitch_1 = require("@graphql-tools/stitch");
class StitchingMerger {
constructor(options) {
this.name = 'stitching';
this.logger = options.logger;
}
getUnifiedSchema(context) {
const { rawSources, typeDefs, resolvers } = context;
this.logger.debug(`Stitching the source schemas`);
const unifiedSchema = (0, stitch_1.stitchSchemas)({
subschemas: rawSources,
typeDefs,
resolvers,
resolverValidationOptions: {
requireResolversForAllFields: 'ignore',
requireResolversForArgs: 'ignore',
requireResolversForNonScalar: 'ignore',
requireResolversForResolveType: 'ignore',
requireResolversToMatchSchema: 'ignore',
},
typeMergingOptions: {
validationSettings: {
validationLevel: stitch_1.ValidationLevel.Off,
},
},
mergeDirectives: true,
});
this.logger.debug(`sourceMap is being generated and attached to the unified schema`);
unifiedSchema.extensions = unifiedSchema.extensions || {};
Object.assign(unifiedSchema.extensions, {
sourceMap: new Proxy({}, {
get: (_, pKey) => {
if (pKey === 'get') {
return (rawSource) => {
const stitchingInfo = unifiedSchema.extensions.stitchingInfo;
for (const [subschemaConfig, subschema] of stitchingInfo.subschemaMap) {
if (subschemaConfig.name === rawSource.name) {
return subschema.transformedSchema;
}
}
return undefined;
};
}
return () => {
throw new Error('Not Implemented');
};
},
}),
});
return {
schema: unifiedSchema,
};
}
}
exports.default = StitchingMerger;
;