UNPKG

inversify-graphql

Version:

Builds dependency-inverted GraphQL schemas with InversifyJS

62 lines 2.53 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.inversifySchema = void 0; const inv = __importStar(require("inversify")); const gql = __importStar(require("graphql")); const type_cache_1 = require("./type-cache"); const interfaces_private_1 = require("./interfaces-private"); function inversifySchema(container, config) { // create child container const thisContainer = new inv.Container(); thisContainer.parent = container; const types = new type_cache_1.TypeCache(thisContainer); thisContainer.bind(interfaces_private_1.ITypeCache).toConstantValue(types); let builtConfig; if (typeof config === 'function') { builtConfig = types.get(config).schema(); } else builtConfig = config; // resolve builders if (typeof builtConfig.query === 'function') { const builder = thisContainer.resolve(builtConfig.query); builtConfig.query = builder.build(); } if (typeof builtConfig.mutation === 'function') { const builder = thisContainer.resolve(builtConfig.mutation); builtConfig.mutation = builder.build(); } if (typeof builtConfig.subscription === 'function') { const builder = thisContainer.resolve(builtConfig.subscription); builtConfig.subscription = builder.build(); } // build schema return new gql.GraphQLSchema({ // typescript only detects correct types doing this: ...builtConfig, mutation: builtConfig.mutation, query: builtConfig.query, subscription: builtConfig.subscription, }); } exports.inversifySchema = inversifySchema; //# sourceMappingURL=build.js.map