After upgrading my nestJS application to use version 3.2 of apollo-server-plugin-base
, I encountered two TypeScript errors related to a simple nestJS plugin:
import { Plugin } from '@nestjs/graphql'
import {
ApolloServerPlugin,
GraphQLRequestListener
} from 'apollo-server-plugin-base'
@Plugin()
export class LoggingPlugin implements ApolloServerPlugin {
requestDidStart(): GraphQLRequestListener {
console.log('Request started')
return {
willSendResponse() {
console.log('Will send response')
}
}
}
}
I am having trouble understanding the nature of these errors and would appreciate some assistance.
requestDidStart():
TS2416: Property 'requestDidStart' in type 'LoggingPlugin' is not assignable to the same property in the base type 'ApolloServerPlugin<BaseContext>'.
Type '() => GraphQLRequestListener<BaseContext>' is not assignable to type '(requestContext: GraphQLRequestContext<BaseContext>) => Promise<void | GraphQLRequestListener<BaseContext>>'.
Type 'GraphQLRequestListener<BaseContext>' is missing certain properties required by 'Promise<void | GraphQLRequestListener<BaseContext>>'.
willSendResponse:
TS2322: Type '() => void' is not compatible with the expected type '(requestContext: GraphQLRequestContextWillSendResponse<BaseContext>) => Promise<void>'.
The error lies in 'Type 'void' being incompatible with type 'Promise<void>'