Closed trevor-scheer closed 1 year ago
Ok so having a look at the code it seems that the third param will be our savior - options.
export const graphqlHandler = startServerAndCreateLambdaHandler(
server,
// We will be using the Proxy V2 handler
handlers.createAPIGatewayProxyEventV2RequestHandler(),
{
context: async () => ({ prisma }),
}
);
If you cmd + click on the startSeverAndCreateLambdaHandler in vscode it will take you to the method definition.
export function startServerAndCreateLambdaHandler<
RH extends RequestHandler<any, any>,
>(
server: ApolloServer<BaseContext>,
handler: RH,
options?: LambdaHandlerOptions<RH, BaseContext>,
): LambdaHandler<RH>;
as you can see here options are defined as so...
export interface LambdaHandlerOptions<
RH extends RequestHandler<any, any>,
TContext extends BaseContext,
> {
middleware?: Array<MiddlewareFn<RH>>;
context?: ContextFunction<[LambdaContextFunctionArgument<RH>], TContext>;
}
@s10mcow Thank you for setting me on the right path. It still took me longer than I'd like to admit to find the correct types for my use-case. I've raised a PR to update the README to include an example of using the context with types.
No API documentation or examples of usage in the README for the
context
option.