()
| 131 | } |
| 132 | |
| 133 | private async createServer() { |
| 134 | const app = this.httpAdapterHost.httpAdapter.getInstance(); |
| 135 | const httpServer = this.httpAdapterHost.httpAdapter.getHttpServer(); |
| 136 | |
| 137 | const schemaName = this.config.get<string>('name'); |
| 138 | if (!schemaName) throw new Error('Unable to get schema name from config'); |
| 139 | |
| 140 | const dbSchema = await this.projectService.getProjectSchema(schemaName); |
| 141 | let options: PostGraphileCoreOptions = { |
| 142 | replaceAllPlugins: plugins, |
| 143 | subscriptions: true, |
| 144 | dynamicJson: true, |
| 145 | graphileBuildOptions: { |
| 146 | connectionFilterRelations: false, // We use our own forked version with historical support |
| 147 | |
| 148 | // cockroach db does not support pgPartition |
| 149 | pgUsePartitionedParent: true, |
| 150 | }, |
| 151 | }; |
| 152 | |
| 153 | if (argv.subscription) { |
| 154 | const pluginHook = makePluginHook([PgPubSub]); |
| 155 | // Must be called manually to init PgPubSub since we're using Apollo Server and not postgraphile |
| 156 | options = pluginHook('postgraphile:options', options, {pgPool: this.pgPool}); |
| 157 | options.replaceAllPlugins ??= []; |
| 158 | options.appendPlugins ??= []; |
| 159 | options.replaceAllPlugins.push(PgSubscriptionPlugin as Plugin); |
| 160 | while (options.appendPlugins.length) { |
| 161 | const replaceAllPlugin = options.appendPlugins.pop(); |
| 162 | if (replaceAllPlugin) options.replaceAllPlugins.push(replaceAllPlugin); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | if (!argv['disable-hot-schema']) { |
| 167 | try { |
| 168 | const pgClient = await this.pgPool.connect(); |
| 169 | await pgClient.query(`LISTEN "${hashName(dbSchema, 'schema_channel', '_metadata')}"`); |
| 170 | |
| 171 | // Set up a keep-alive interval to prevent the connection from being killed |
| 172 | this.setupKeepAlive(pgClient); |
| 173 | |
| 174 | pgClient.on('error', (err: Error) => { |
| 175 | getLogger('db').error('PostgreSQL schema listener client error: ', err); |
| 176 | process.exit(1); |
| 177 | }); |
| 178 | |
| 179 | pgClient.on('notification', (msg) => { |
| 180 | if (msg.payload === 'schema_updated') { |
| 181 | void this.schemaListener(dbSchema, options); |
| 182 | } |
| 183 | }); |
| 184 | } catch (e) { |
| 185 | logger.warn('Failed to init hot-schema reload', e); |
| 186 | } |
| 187 | } |
| 188 | const schema = await this.buildSchema(dbSchema, options); |
| 189 | |
| 190 | const apolloServerPlugins = [ |
no test coverage detected