graphile-engine
graphile-engine copied to clipboard
[graphql-parse-resolve-info] Fix types or example
Summary
Documentation says to do this:
But when I do it, I get a TypeScript error:
Put as ResolveTree after the error and it should go away.
Seeing the same.
text dump of error:
Argument of type 'ResolveTree | FieldsByTypeName | null | undefined' is not assignable to parameter of type 'ResolveTree'.
Type 'undefined' is not assignable to type 'ResolveTree'.
To be clear, the example code written in JavaScript is correct. If you want to use it with TypeScript then you need to either add the above type cast (parsedResolvedInfoFragment as ResolveTree) or do some other type narrowing behaviour. We could potentially change the signature of the function to something like:
export function parseResolveInfo(
resolveInfo: GraphQLResolveInfo,
): ResolveTree | null | undefined;
export function parseResolveInfo(
resolveInfo: GraphQLResolveInfo,
options: ParseOptions
): ResolveTree | FieldsByTypeName | null | undefined;
export function parseResolveInfo(
resolveInfo: GraphQLResolveInfo,
options: ParseOptions = {}
): ResolveTree | FieldsByTypeName | null | undefined {
but overloaded functions in TypeScript have all sorts of issues that they can cause down the road so I'm not keen to do that, especially given all you need to do is add as ResolveTree if you know that's what it's going to be based on the options that you've passed.