Skip to content

Commit b97fe0a

Browse files
committed
Refactor GraphQL*Type TS types to be more DRY
Motivation: 1. Makes it easier to understand the type hierarchy. 2. Adding a new type, were it ever to happen, would require fewer code changes. Depends on #3597
1 parent c526767 commit b97fe0a

File tree

1 file changed

+5
-31
lines changed

1 file changed

+5
-31
lines changed

src/type/definition.ts

+5-31
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,9 @@ import type { GraphQLSchema } from './schema';
5151
* These are all of the possible kinds of types.
5252
*/
5353
export type GraphQLType =
54-
| GraphQLScalarType
55-
| GraphQLObjectType
56-
| GraphQLInterfaceType
57-
| GraphQLUnionType
58-
| GraphQLEnumType
59-
| GraphQLInputObjectType
54+
| GraphQLNamedType
6055
| GraphQLList<GraphQLType>
61-
| GraphQLNonNull<
62-
| GraphQLScalarType
63-
| GraphQLObjectType
64-
| GraphQLInterfaceType
65-
| GraphQLUnionType
66-
| GraphQLEnumType
67-
| GraphQLInputObjectType
68-
| GraphQLList<GraphQLType>
69-
>;
56+
| GraphQLNonNull<GraphQLNullableType>;
7057

7158
export function isType(type: unknown): type is GraphQLType {
7259
return (
@@ -207,9 +194,7 @@ export function assertNonNullType(type: unknown): GraphQLNonNull<GraphQLType> {
207194
* These types may be used as input types for arguments and directives.
208195
*/
209196
export type GraphQLNullableInputType =
210-
| GraphQLScalarType
211-
| GraphQLEnumType
212-
| GraphQLInputObjectType
197+
| GraphQLNamedInputType
213198
| GraphQLList<GraphQLInputType>;
214199

215200
export type GraphQLInputType =
@@ -236,11 +221,7 @@ export function assertInputType(type: unknown): GraphQLInputType {
236221
* These types may be used as output types as the result of fields.
237222
*/
238223
export type GraphQLNullableOutputType =
239-
| GraphQLScalarType
240-
| GraphQLObjectType
241-
| GraphQLInterfaceType
242-
| GraphQLUnionType
243-
| GraphQLEnumType
224+
| GraphQLNamedOutputType
244225
| GraphQLList<GraphQLOutputType>;
245226

246227
export type GraphQLOutputType =
@@ -430,14 +411,7 @@ export function assertWrappingType(type: unknown): GraphQLWrappingType {
430411
/**
431412
* These types can all accept null as a value.
432413
*/
433-
export type GraphQLNullableType =
434-
| GraphQLScalarType
435-
| GraphQLObjectType
436-
| GraphQLInterfaceType
437-
| GraphQLUnionType
438-
| GraphQLEnumType
439-
| GraphQLInputObjectType
440-
| GraphQLList<GraphQLType>;
414+
export type GraphQLNullableType = GraphQLNamedType | GraphQLList<GraphQLType>;
441415

442416
export function isNullableType(type: unknown): type is GraphQLNullableType {
443417
return isType(type) && !isNonNullType(type);

0 commit comments

Comments
 (0)