graphile-engine icon indicating copy to clipboard operation
graphile-engine copied to clipboard

[graphql-parse-resolve-info] Fix types or example

Open lorensr opened this issue 3 years ago • 1 comments

Summary

Documentation says to do this:

image

But when I do it, I get a TypeScript error:

image

lorensr avatar Apr 05 '22 06:04 lorensr

Put as ResolveTree after the error and it should go away.

benjie avatar Apr 05 '22 08:04 benjie

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'.

BlairCurrey avatar Jan 12 '23 01:01 BlairCurrey

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.

benjie avatar Jan 12 '23 10:01 benjie