UNPKG

@graphql-mesh/raml

Version:
47 lines (44 loc) 1.67 kB
import { PredefinedProxyOptions } from '@graphql-mesh/store'; import { createBundle, getGraphQLSchemaFromBundle } from '@omnigraph/raml'; class RAMLHandler { constructor({ name, config, baseDir, fetchFn, store, pubsub, logger }) { this.name = name; this.config = config; this.baseDir = baseDir; this.fetch = fetchFn; this.bundleStoreProxy = store.proxy('jsonSchemaBundle', PredefinedProxyOptions.JsonWithoutValidation); this.pubsub = pubsub; this.logger = logger; } async getDereferencedBundle() { return this.bundleStoreProxy.getWithSet(() => { var _a; return 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 getGraphQLSchemaFromBundle(bundle, { cwd: this.baseDir, fetch: this.fetch, pubsub: this.pubsub, logger: this.logger, baseUrl: this.config.baseUrl, operationHeaders: this.config.operationHeaders, }); return { schema, }; } } export default RAMLHandler;