Skip to content

Commit

Permalink
feat(apollo,yoga,core): use graphql child injector context as graphql…
Browse files Browse the repository at this point in the history
… context
  • Loading branch information
marcus-sa committed Jan 23, 2024
1 parent 9be100e commit d459dc2
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 216 deletions.
23 changes: 8 additions & 15 deletions packages/apollo/src/lib/apollo-graphql-driver.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import * as http from 'node:http';
import * as https from 'node:https';
import * as url from 'node:url';
import { ApolloServer, HeaderMap, HTTPGraphQLRequest } from '@apollo/server';
import { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer';
import { InjectorContext } from '@deepkit/injector';
import { GraphQLSchema } from 'graphql';
import {
WebWorkerFactory,
ApplicationServer,
WebWorker,
} from '@deepkit/framework';
import { WebWorkerFactory, ApplicationServer } from '@deepkit/framework';
import { HttpBadRequestError, httpWorkflow } from '@deepkit/http';
import { Driver, GraphQLHttpContext } from '@deepkit-graphql/core';
import { Driver } from '@deepkit-graphql/core';

import { ApolloGraphQLConfig } from './apollo-graphql-config';
import { ApolloServerPlugins } from './plugins';
Expand All @@ -27,7 +22,10 @@ export class ApolloDriver extends Driver {
super(appServer, webWorkerFactory);
}

async onRequest(event: typeof httpWorkflow.onRequest.event): Promise<void> {
async onRequest(
event: typeof httpWorkflow.onRequest.event,
injectorContext: InjectorContext,
): Promise<void> {
if (!event.request.method) return;

const requestHeaders = new HeaderMap();
Expand All @@ -53,14 +51,9 @@ export class ApolloDriver extends Driver {
body: JSON.parse(await event.request.readBodyText()),
};

const context: GraphQLHttpContext = {
request: event.request,
response: event.response,
};

const response = await this.server!.executeHTTPGraphQLRequest({
httpGraphQLRequest,
context: async () => context,
context: async () => injectorContext,
});
if (!response) {
throw new HttpBadRequestError(JSON.stringify(httpGraphQLRequest));
Expand Down
Loading

0 comments on commit d459dc2

Please sign in to comment.