UNPKG

graphile-settings

Version:
113 lines (112 loc) 4.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getGraphileSettings = void 0; const pg_many_to_many_1 = __importDefault(require("@graphile-contrib/pg-many-to-many")); const env_1 = require("@launchql/env"); const postgis_1 = __importDefault(require("@pyramation/postgis")); // @ts-ignore const postgraphile_plugin_fulltext_filter_1 = __importDefault(require("@pyramation/postgraphile-plugin-fulltext-filter")); const graphile_build_1 = require("graphile-build"); const graphile_i18n_1 = require("graphile-i18n"); // @ts-ignore const graphile_meta_schema_1 = __importDefault(require("graphile-meta-schema")); // @ts-ignore const graphile_search_plugin_1 = __importDefault(require("graphile-search-plugin")); // @ts-ignore const graphile_simple_inflector_1 = __importDefault(require("graphile-simple-inflector")); const postgraphile_plugin_connection_filter_1 = __importDefault(require("postgraphile-plugin-connection-filter")); // @ts-ignore const postgraphile_plugin_connection_filter_postgis_1 = __importDefault(require("postgraphile-plugin-connection-filter-postgis")); const types_1 = __importDefault(require("./plugins/types")); const upload_postgraphile_plugin_1 = __importDefault(require("./plugins/upload-postgraphile-plugin")); const upload_1 = require("./resolvers/upload"); const getGraphileSettings = (rawOpts) => { const opts = (0, env_1.getEnvOptions)(rawOpts); const { server, graphile, features, cdn } = opts; // Instantiate uploader with merged cdn opts const uploader = new upload_1.Uploader({ bucketName: cdn.bucketName, awsRegion: cdn.awsRegion, awsAccessKey: cdn.awsAccessKey, awsSecretKey: cdn.awsSecretKey, minioEndpoint: cdn.minioEndpoint, }); const resolveUpload = uploader.resolveUpload.bind(uploader); const plugins = [ postgraphile_plugin_connection_filter_1.default, postgraphile_plugin_fulltext_filter_1.default, types_1.default, upload_postgraphile_plugin_1.default, graphile_meta_schema_1.default, pg_many_to_many_1.default, graphile_search_plugin_1.default, ]; if (features?.postgis) { plugins.push(postgis_1.default, postgraphile_plugin_connection_filter_postgis_1.default); } if (features?.simpleInflection) { plugins.push(graphile_simple_inflector_1.default); } plugins.push(graphile_i18n_1.LangPlugin); return { graphileBuildOptions: { uploadFieldDefinitions: [ { name: 'upload', namespaceName: 'public', type: 'JSON', resolve: resolveUpload, }, { name: 'attachment', namespaceName: 'public', type: 'String', resolve: resolveUpload, }, { name: 'image', namespaceName: 'public', type: 'JSON', resolve: resolveUpload, }, { tag: 'upload', resolve: resolveUpload, }, ], pgSimplifyOppositeBaseNames: features?.oppositeBaseNames, connectionFilterComputedColumns: false, }, appendPlugins: plugins, skipPlugins: [graphile_build_1.NodePlugin], dynamicJson: true, disableGraphiql: false, enhanceGraphiql: true, enableQueryBatching: true, graphiql: true, watch: false, port: server?.port, host: server?.host, schema: graphile?.schema, ignoreRBAC: false, legacyRelations: 'omit', showErrorStack: false, // @ts-ignore extendedErrors: false, disableQueryLog: false, includeExtensionResources: true, setofFunctionsContainNulls: false, retryOnInitFail: async (_error) => { return false; }, additionalGraphQLContextFromRequest: (req, res) => ({ ...(0, graphile_i18n_1.additionalGraphQLContextFromRequest)(req, res), req, res, }), }; }; exports.getGraphileSettings = getGraphileSettings;