UNPKG

@graphql-mesh/neo4j

Version:
77 lines (76 loc) 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const graphql_1 = require("graphql"); const store_1 = require("@graphql-mesh/store"); const utils_1 = require("@graphql-mesh/utils"); const neo4j_1 = require("@omnigraph/neo4j"); class Neo4JHandler { constructor({ name, config, baseDir, pubsub, store, logger, importFn, }) { this.name = name; this.config = config; this.baseDir = baseDir; this.pubsub = pubsub; this.schema = store.proxy('schema.graphql', store_1.PredefinedProxyOptions.GraphQLSchemaWithDiffing); this.logger = logger; this.importFn = importFn; } getCachedSchema(driver) { return this.schema.getWithSet(async () => { if (this.config.source) { const typeDefs = await (0, utils_1.readFileOrUrl)(this.config.source, { cwd: this.baseDir, allowUnknownExtensions: true, importFn: this.importFn, fetch: this.fetchFn, logger: this.logger, }); return (0, graphql_1.buildSchema)(typeDefs, { noLocation: true, assumeValid: true, assumeValidSDL: true, }); } else { return (0, neo4j_1.loadGraphQLSchemaFromNeo4J)(this.name, { driver, endpoint: this.config.endpoint, auth: { type: 'basic', username: this.config.username, password: this.config.password, }, logger: this.logger, pubsub: this.pubsub, database: this.config.database, }); } }); } async getMeshSource({ fetchFn }) { this.fetchFn = fetchFn; let driver; if (this.config.endpoint) { driver = (0, neo4j_1.getDriverFromOpts)({ endpoint: this.config.endpoint, auth: { type: 'basic', username: this.config.username, password: this.config.password, }, logger: this.logger, }); } const schema = await this.getCachedSchema(driver); const executor = await (0, neo4j_1.getNeo4JExecutor)({ schema, driver, pubsub: this.pubsub, logger: this.logger, }); return { schema, executor, }; } } exports.default = Neo4JHandler;