Skip to content

Commit 9d359b8

Browse files
authored
Merge pull request #589 from jamesgorman2/master
Add isNamedType and assertNamedType helpers
2 parents 30811fa + f89b237 commit 9d359b8

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export {
9797
isLeafType,
9898
isCompositeType,
9999
isAbstractType,
100+
isNamedType,
100101

101102
// Assertions
102103
assertType,
@@ -105,6 +106,7 @@ export {
105106
assertLeafType,
106107
assertCompositeType,
107108
assertAbstractType,
109+
assertNamedType,
108110

109111
// Un-modifiers
110112
getNullableType,

src/type/definition.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,25 @@ export type GraphQLNamedType =
225225
GraphQLEnumType |
226226
GraphQLInputObjectType;
227227

228+
export function isNamedType(type: ?GraphQLType): boolean {
229+
return (
230+
type instanceof GraphQLScalarType ||
231+
type instanceof GraphQLObjectType ||
232+
type instanceof GraphQLInterfaceType ||
233+
type instanceof GraphQLUnionType ||
234+
type instanceof GraphQLEnumType ||
235+
type instanceof GraphQLInputObjectType
236+
);
237+
}
238+
239+
export function assertNamedType(type: ?GraphQLType): GraphQLNamedType {
240+
invariant(
241+
isNamedType(type),
242+
`Expected ${String(type)} to be a GraphQL named type.`,
243+
);
244+
return (type: any);
245+
}
246+
228247
export function getNamedType(type: ?GraphQLType): ?GraphQLNamedType {
229248
let unmodifiedType = type;
230249
while (

src/type/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export {
1919
isLeafType,
2020
isCompositeType,
2121
isAbstractType,
22+
isNamedType,
2223

2324
// Assertions
2425
assertType,
@@ -27,6 +28,7 @@ export {
2728
assertLeafType,
2829
assertCompositeType,
2930
assertAbstractType,
31+
assertNamedType,
3032

3133
// Un-modifiers
3234
getNullableType,

0 commit comments

Comments
 (0)