graphile / graphile/graphile-engine

Provide a type guard to distinguish between ResolveTree and FieldsByTypeName

Open
#849 2 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
764
Forks
128
PR merge metrics
No merged PRs in 30d

Description

### 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:

```ts
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]:

- [x] am interested in building this feature myself
- [x] am interested in collaborating on building this feature
- [x] am willing to help testing this feature before it's released
- [x] am willing to write a test-driven test suite for this feature (before it exists)
- [ ] am a [Graphile sponsor](https://www.graphile.org/sponsor/) ❤️
- [ ] have an active [support or consultancy contract](https://www.graphile.org/support/) with Graphile

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.