Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a type guard to distinguish between ResolveTree and FieldsByTypeName #849

Open
4 of 6 tasks
Nargonath opened this issue Nov 10, 2023 · 2 comments · May be fixed by #858
Open
4 of 6 tasks

Provide a type guard to distinguish between ResolveTree and FieldsByTypeName #849

Nargonath opened this issue Nov 10, 2023 · 2 comments · May be fixed by #858

Comments

@Nargonath
Copy link

Feature description

parseResolveInfo return type is ResolveTree | FieldsByTypeName | null | undefined. You can get rid of null | undefined with an if condition but you're left with ResolveTree | FieldsByTypeName. The problem is that simplifyParsedResolveInfoFragmentWithType expects a ResolveTree as its first argument. We need a way to tell them apart. Right now I'm using this:

function isResolveTree(
  value: ResolveTree | FieldsByTypeName,
): value is ResolveTree {
  return typeof value.name === "string" && Boolean(value.fieldsByTypeName);
}

Motivating example

It's hard to use simplifyParsedResolveInfoFragmentWithType when using TypeScript without this type guard, unless I'm doing something wrong here.

Supporting development

I [tick all that apply]:

  • am interested in building this feature myself
  • am interested in collaborating on building this feature
  • am willing to help testing this feature before it's released
  • am willing to write a test-driven test suite for this feature (before it exists)
  • am a Graphile sponsor ❤️
  • have an active support or consultancy contract with Graphile
@benjie
Copy link
Member

benjie commented Nov 13, 2023

Sure; go ahead and raise a PR for it. I'd soften the argument to value: ResolveTree | FieldsByTypeName | null | undefined personally.

@Nargonath
Copy link
Author

Alright, thank you. I'll add it to my TODO list and I'll aim to do it ASAP.

Nargonath added a commit to Nargonath/graphile-engine that referenced this issue Mar 25, 2024
Nargonath added a commit to Nargonath/graphile-engine that referenced this issue Mar 25, 2024
Nargonath added a commit to Nargonath/graphile-engine that referenced this issue Mar 25, 2024
@Nargonath Nargonath linked a pull request Mar 25, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants