MCPcopy Index your code
hub / github.com/subquery/subql / createServer

Method createServer

packages/query/src/graphql/graphql.module.ts:133–236  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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 = [

Callers 1

onModuleInitMethod · 0.95

Calls 15

setupKeepAliveMethod · 0.95
schemaListenerMethod · 0.95
buildSchemaMethod · 0.95
hashNameFunction · 0.90
getLoggerFunction · 0.90
playgroundPluginFunction · 0.90
queryComplexityPluginFunction · 0.90
queryDepthLimitPluginFunction · 0.90
queryAliasLimitFunction · 0.90
queryExplainPluginFunction · 0.90
getInstanceMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected