UNPKG

@graphql-mesh/raml

Version:
49 lines (45 loc) 1.67 kB
'use strict'; const store = require('@graphql-mesh/store'); const raml = require('@omnigraph/raml'); class RAMLHandler { constructor({ name, config, baseDir, fetchFn, store: store$1, pubsub, logger }) { this.name = name; this.config = config; this.baseDir = baseDir; this.fetch = fetchFn; this.bundleStoreProxy = store$1.proxy('jsonSchemaBundle', store.PredefinedProxyOptions.JsonWithoutValidation); this.pubsub = pubsub; this.logger = logger; } async getDereferencedBundle() { return this.bundleStoreProxy.getWithSet(() => { var _a; return raml.createBundle(this.name, { ...this.config, cwd: this.baseDir, fetch: this.fetch, logger: this.logger, ignoreErrorResponses: this.config.ignoreErrorResponses, selectQueryOrMutationField: (_a = this.config.selectQueryOrMutationField) === null || _a === void 0 ? void 0 : _a.map(({ type, fieldName }) => ({ type: type.toLowerCase(), fieldName, })), }); }); } async getMeshSource() { const bundle = await this.getDereferencedBundle(); const schema = await raml.getGraphQLSchemaFromBundle(bundle, { cwd: this.baseDir, fetch: this.fetch, pubsub: this.pubsub, logger: this.logger, baseUrl: this.config.baseUrl, operationHeaders: this.config.operationHeaders, }); return { schema, }; } } module.exports = RAMLHandler;