Skip to content

Commit 9ba6b17

Browse files
authored
Refine getNamedType() for Input and Output types (#3063)
This introduces type definitions `GraphQLNamedInputType` and `GraphQLNamedOutputType` as the subsets of `GraphQLNamedType`, and adds function overrides for `getNamedType()` such that if an input or output type is provided, one of these refined subset types is returned.
1 parent 2673bdf commit 9ba6b17

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

src/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ export {
137137
GraphQLWrappingType,
138138
GraphQLNullableType,
139139
GraphQLNamedType,
140+
GraphQLNamedInputType,
141+
GraphQLNamedOutputType,
140142
ThunkArray,
141143
ThunkObjMap,
142144
GraphQLSchemaConfig,

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ export type {
136136
GraphQLWrappingType,
137137
GraphQLNullableType,
138138
GraphQLNamedType,
139+
GraphQLNamedInputType,
140+
GraphQLNamedOutputType,
139141
ThunkArray,
140142
ThunkObjMap,
141143
GraphQLSchemaConfig,

src/type/definition.d.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,27 @@ export function getNullableType<T extends GraphQLNullableType>(
249249
/**
250250
* These named types do not include modifiers like List or NonNull.
251251
*/
252-
export type GraphQLNamedType =
252+
export type GraphQLNamedType = GraphQLNamedInputType | GraphQLNamedOutputType;
253+
254+
export type GraphQLNamedInputType =
255+
| GraphQLScalarType
256+
| GraphQLEnumType
257+
| GraphQLInputObjectType;
258+
259+
export type GraphQLNamedOutputType =
253260
| GraphQLScalarType
254261
| GraphQLObjectType
255262
| GraphQLInterfaceType
256263
| GraphQLUnionType
257-
| GraphQLEnumType
258-
| GraphQLInputObjectType;
264+
| GraphQLEnumType;
259265

260266
export function isNamedType(type: unknown): type is GraphQLNamedType;
261267

262268
export function assertNamedType(type: unknown): GraphQLNamedType;
263269

264270
export function getNamedType(type: undefined): undefined;
271+
export function getNamedType(type: GraphQLInputType): GraphQLNamedInputType;
272+
export function getNamedType(type: GraphQLOutputType): GraphQLNamedOutputType;
265273
export function getNamedType(type: GraphQLType): GraphQLNamedType;
266274

267275
/**

src/type/definition.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,19 @@ export function getNullableType(type) {
467467
/**
468468
* These named types do not include modifiers like List or NonNull.
469469
*/
470-
export type GraphQLNamedType =
470+
export type GraphQLNamedType = GraphQLNamedInputType | GraphQLNamedOutputType;
471+
472+
export type GraphQLNamedInputType =
473+
| GraphQLScalarType
474+
| GraphQLEnumType
475+
| GraphQLInputObjectType;
476+
477+
export type GraphQLNamedOutputType =
471478
| GraphQLScalarType
472479
| GraphQLObjectType
473480
| GraphQLInterfaceType
474481
| GraphQLUnionType
475-
| GraphQLEnumType
476-
| GraphQLInputObjectType;
482+
| GraphQLEnumType;
477483

478484
export function isNamedType(type: mixed): boolean %checks {
479485
return (
@@ -495,6 +501,8 @@ export function assertNamedType(type: mixed): GraphQLNamedType {
495501

496502
/* eslint-disable no-redeclare */
497503
declare function getNamedType(type: void | null): void;
504+
declare function getNamedType(type: GraphQLInputType): GraphQLNamedInputType;
505+
declare function getNamedType(type: GraphQLOutputType): GraphQLNamedOutputType;
498506
declare function getNamedType(type: GraphQLType): GraphQLNamedType;
499507
export function getNamedType(type) {
500508
/* eslint-enable no-redeclare */

src/type/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export {
7373
GraphQLWrappingType,
7474
GraphQLNullableType,
7575
GraphQLNamedType,
76+
GraphQLNamedInputType,
77+
GraphQLNamedOutputType,
7678
ThunkArray,
7779
ThunkObjMap,
7880
GraphQLArgument,

src/type/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ export type {
128128
GraphQLWrappingType,
129129
GraphQLNullableType,
130130
GraphQLNamedType,
131+
GraphQLNamedInputType,
132+
GraphQLNamedOutputType,
131133
ThunkArray,
132134
ThunkObjMap,
133135
GraphQLArgument,

0 commit comments

Comments
 (0)