Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
Add stronger inference to unwrapType
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Dec 3, 2019
1 parent cc633a0 commit 809e7a3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/ast/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
InlineFragmentNode,
FieldNode,
FragmentDefinitionNode,
GraphQLOutputType,
GraphQLWrappingType,
Kind,
isListType,
isNonNullType,
Expand Down Expand Up @@ -44,9 +44,12 @@ export const isInlineFragment = (
node: SelectionNode
): node is InlineFragmentNode => node.kind === Kind.INLINE_FRAGMENT;

export const unwrapType = (
type: null | undefined | GraphQLOutputType
): GraphQLFlatType | null => {
export const unwrapType = <
T,
V = T extends GraphQLWrappingType ? GraphQLFlatType : T
>(
type: null | undefined | T
): V | null => {
return type && (isListType(type) || isNonNullType(type))
? type.ofType
: type || null;
Expand Down

0 comments on commit 809e7a3

Please sign in to comment.