@omnigraph/neo4j
Version:
73 lines (72 loc) • 2.6 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNeo4JExecutor = void 0;
const graphql_1 = require("graphql");
const delegate_1 = require("@graphql-tools/delegate");
const utils_1 = require("@graphql-tools/utils");
const driver_js_1 = require("./driver.js");
const schema_js_1 = require("./schema.js");
function filterIntrospectionDefinitions(node) {
if (!node.directives?.some(directive => directive.name.value === 'introspection')) {
return null;
}
return node;
}
async function getNeo4JExecutor(opts) {
const transportDirectives = (0, utils_1.getDirective)(opts.schema, opts.schema, 'transport');
if (!transportDirectives?.length) {
throw new Error('No transport directive found on the schema!');
}
const { location: endpoint, options: { database, auth }, } = transportDirectives[0];
let driver = opts.driver;
if (!driver) {
driver = (0, driver_js_1.getDriverFromOpts)({
endpoint,
auth,
logger: opts.logger,
});
}
let typeDefs = (0, utils_1.getDocumentNodeFromSchema)(opts.schema);
const astVisitor = {
enter: filterIntrospectionDefinitions,
};
typeDefs = (0, graphql_1.visit)(typeDefs, {
EnumTypeDefinition: astVisitor,
ObjectTypeDefinition: astVisitor,
InterfaceTypeDefinition: astVisitor,
UnionTypeDefinition: astVisitor,
InputObjectTypeDefinition: astVisitor,
FieldDefinition: astVisitor,
// DirectiveDefinition: astVisitor,
ScalarTypeDefinition: astVisitor,
EnumValueDefinition: astVisitor,
InputValueDefinition: astVisitor,
});
typeDefs.definitions.push(...(0, graphql_1.parse)(/* GraphQL */ `
directive @source(
subgraph: String
name: String
type: String
) on ENUM | OBJECT | INTERFACE | UNION | INPUT_OBJECT | FIELD_DEFINITION | SCALAR | ENUM_VALUE | INPUT_FIELD_DEFINITION
`).definitions);
const executableSchema = await (0, schema_js_1.getExecutableSchemaFromTypeDefsAndDriver)({
driver,
logger: opts.logger,
pubsub: opts.pubsub,
typeDefs,
});
const defaultExecutor = (0, delegate_1.createDefaultExecutor)(executableSchema);
const sessionConfig = {
database,
};
return function neo4JExecutor(args) {
return defaultExecutor({
...args,
context: {
...args.context,
sessionConfig,
},
});
};
}
exports.getNeo4JExecutor = getNeo4JExecutor;
;