UNPKG

@graphql-mesh/soap

Version:
59 lines (55 loc) 2.06 kB
'use strict'; const store = require('@graphql-mesh/store'); const soap = require('@omnigraph/soap'); const utils = require('@graphql-mesh/utils'); class SoapHandler { constructor({ config, store: store$1, baseDir, importFn, logger }) { this.config = config; this.soapSDLProxy = store$1.proxy('schemaWithAnnotations.graphql', store.PredefinedProxyOptions.GraphQLSchemaWithDiffing); this.baseDir = baseDir; this.importFn = importFn; this.logger = logger; } async getMeshSource({ fetchFn }) { let schema; if (this.config.source.endsWith('.graphql')) { schema = await utils.readFileOrUrl(this.config.source, { allowUnknownExtensions: true, cwd: this.baseDir, fetch: fetchFn, importFn: this.importFn, logger: this.logger, }); } else { schema = await this.soapSDLProxy.getWithSet(async () => { const soapLoader = new soap.SOAPLoader({ fetch: fetchFn, }); const wsdlLocation = this.config.source; const wsdl = await utils.readFileOrUrl(wsdlLocation, { allowUnknownExtensions: true, cwd: this.baseDir, fetch: fetchFn, importFn: this.importFn, logger: this.logger, }); const object = await soapLoader.loadWSDL(wsdl); soapLoader.loadedLocations.set(wsdlLocation, object); return soapLoader.buildSchema(); }); } // Create executor lazily for faster startup let executor; return { schema, executor(...args) { if (!executor) { executor = soap.createExecutorFromSchemaAST(schema, fetchFn); } return executor(...args); }, }; } } module.exports = SoapHandler;