MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / start

Method start

extensions/graphql/src/graphql.server.ts:158–214  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

156 }
157
158 async start() {
159 const schema = await this._setupSchema();
160 this.schema = schema;
161 // Allow a graphql context resolver to be bound to GRAPHQL_CONTEXT_RESOLVER
162 const graphqlContextResolver: ExpressMiddlewareOptions<BaseContext>['context'] =
163 (await this.get(GraphQLBindings.GRAPHQL_CONTEXT_RESOLVER, {
164 optional: true,
165 })) ?? (async context => context);
166 // Allow a graphql context resolver to be bound to GRAPHQL_CONTEXT_RESOLVER
167 const graphqlWsContextResolver =
168 (await this.get(GraphQLBindings.GRAPHQL_WS_CONTEXT_RESOLVER, {
169 optional: true,
170 })) ??
171 (async (context: object) => {
172 return context;
173 });
174
175 // Create ApolloServerExpress GraphQL server
176 const serverConfig = {
177 ...this.options.apollo,
178 schema,
179 // plugins: [ApolloServerPluginDrainHttpServer({ httpServer: this.httpServer })],
180 } as ApolloServerOptionsWithSchema<BaseContext>;
181 const graphQLServer = new ApolloServer(serverConfig);
182 await graphQLServer.start();
183 this.expressApp.use(
184 this.options.graphQLPath ?? '/',
185 cors<cors.CorsRequest>(),
186 json(),
187 expressMiddleware(graphQLServer, {
188 context: graphqlContextResolver,
189 ...this.options.middlewareOptions,
190 }),
191 );
192 // Start the http server if created
193 await this.httpServer?.start();
194
195 let server;
196 if (this.options.asMiddlewareOnly) {
197 const rest: RestServer = await this.get(RestBindings.SERVER);
198 server = rest.httpServer?.server;
199 } else {
200 server = this.httpServer?.server;
201 }
202 const wsServer = new WebSocketServer({
203 server: server,
204 path: this.options.path,
205 });
206 this.wsServer = wsServer;
207 useServer(
208 {
209 schema,
210 context: graphqlWsContextResolver,
211 },
212 wsServer,
213 );
214 }
215

Callers

nothing calls this directly

Calls 4

_setupSchemaMethod · 0.95
getMethod · 0.65
startMethod · 0.65
useMethod · 0.65

Tested by

no test coverage detected