Improve `makeWrapResolversPlugin` typing for TS
Summary
Specifying any args in makeWrapResolversPlugin that is more narrow than any fails typechecking with
Property 'input' is missing in type '{ [argName: string]: any; }' but required in type '{ input: $Typename; }'.
Steps to reproduce
Here's a simple example:
const getPointFromGMaps => {
const getLatitudeAndLongitude = async (
resolve: any,
_source: any,
args: {
input: CreateDestinationInput; // This is a type generated by `graphql-codegen`
},
_context: any,
_resolveInfo: GraphQLResolveInfo
) => {
// Code omitted for brevity
};
return makeWrapResolversPlugin({
Mutation: {
updateDestination: getLatitudeAndLongitude,
createDestination: getLatitudeAndLongitude
}
});
};
Expected results
This should typecheck without issue.
Actual results
The example above fails with
Property 'input' is missing in type '{ [argName: string]: any; }' but required in type '{ input: CreateDestinationInput; }'.
Possible Solution
It seems like the issue is due to the fact that the type parameters of ResolverWrapperFn gets instantiated as any, any, { [argName: string]: any }. It seems like this can be fixed by forwarding the type parameters from makeWrapResolversPlugin (and by setting the type parameter defaults in the same way as in ResolverWrapperFn so we don't break existing code) to ResolverWrapperFn.
I have a PoC that I can submit a PR for if you want. Thanks in advance!
I have a PoC that I can submit a PR for if you want. Thanks in advance!
Sounds good; please do :+1:
See https://github.com/graphile/graphile-engine/pull/709