Skip to content

Commit 1af8e9b

Browse files
committed
Minor error message clarity
Follow up to #570
1 parent b7ea845 commit 1af8e9b

File tree

3 files changed

+65
-65
lines changed

3 files changed

+65
-65
lines changed

src/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,6 @@ export {
9090
__EnumValue,
9191
__TypeKind,
9292

93-
// Assertions
94-
assertType,
95-
assertInputType,
96-
assertOutputType,
97-
assertLeafType,
98-
assertCompositeType,
99-
assertAbstractType,
100-
10193
// Predicates
10294
isType,
10395
isInputType,
@@ -106,6 +98,14 @@ export {
10698
isCompositeType,
10799
isAbstractType,
108100

101+
// Assertions
102+
assertType,
103+
assertInputType,
104+
assertOutputType,
105+
assertLeafType,
106+
assertCompositeType,
107+
assertAbstractType,
108+
109109
// Un-modifiers
110110
getNullableType,
111111
getNamedType,

src/type/definition.js

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type {
2121
import type { GraphQLSchema } from './schema';
2222

2323

24-
// Predicates
24+
// Predicates & Assertions
2525

2626
/**
2727
* These are all of the possible kinds of types.
@@ -36,14 +36,6 @@ export type GraphQLType =
3636
GraphQLList<any> |
3737
GraphQLNonNull<any>;
3838

39-
export function assertType(type: mixed): GraphQLType {
40-
invariant(
41-
isType(type),
42-
`GraphQL: Expected ${String(type)} to be a GraphQLType.`
43-
);
44-
return (type: any);
45-
}
46-
4739
export function isType(type: mixed): boolean {
4840
return (
4941
type instanceof GraphQLScalarType ||
@@ -57,6 +49,14 @@ export function isType(type: mixed): boolean {
5749
);
5850
}
5951

52+
export function assertType(type: mixed): GraphQLType {
53+
invariant(
54+
isType(type),
55+
`Expected ${String(type)} to be a GraphQL type.`
56+
);
57+
return (type: any);
58+
}
59+
6060
/**
6161
* These types may be used as input types for arguments and directives.
6262
*/
@@ -72,14 +72,6 @@ export type GraphQLInputType =
7272
GraphQLList<GraphQLInputType>
7373
>;
7474

75-
export function assertInputType(type: ?GraphQLType): GraphQLInputType {
76-
invariant(
77-
isInputType(type),
78-
`GraphQL: Expected type ${String(type)} to be a GraphQLInputType.`
79-
);
80-
return (type: any);
81-
}
82-
8375
export function isInputType(type: ?GraphQLType): boolean {
8476
const namedType = getNamedType(type);
8577
return (
@@ -89,6 +81,14 @@ export function isInputType(type: ?GraphQLType): boolean {
8981
);
9082
}
9183

84+
export function assertInputType(type: ?GraphQLType): GraphQLInputType {
85+
invariant(
86+
isInputType(type),
87+
`Expected ${String(type)} to be a GraphQL input type.`
88+
);
89+
return (type: any);
90+
}
91+
9292
/**
9393
* These types may be used as output types as the result of fields.
9494
*/
@@ -108,14 +108,6 @@ export type GraphQLOutputType =
108108
GraphQLList<GraphQLOutputType>
109109
>;
110110

111-
export function assertOutputType(type: ?GraphQLType): GraphQLOutputType {
112-
invariant(
113-
isOutputType(type),
114-
`GraphQL: Expected type ${String(type)} to be a GraphQLOutputType.`,
115-
);
116-
return (type: any);
117-
}
118-
119111
export function isOutputType(type: ?GraphQLType): boolean {
120112
const namedType = getNamedType(type);
121113
return (
@@ -127,21 +119,21 @@ export function isOutputType(type: ?GraphQLType): boolean {
127119
);
128120
}
129121

122+
export function assertOutputType(type: ?GraphQLType): GraphQLOutputType {
123+
invariant(
124+
isOutputType(type),
125+
`Expected ${String(type)} to be a GraphQL output type.`,
126+
);
127+
return (type: any);
128+
}
129+
130130
/**
131131
* These types may describe types which may be leaf values.
132132
*/
133133
export type GraphQLLeafType =
134134
GraphQLScalarType |
135135
GraphQLEnumType;
136136

137-
export function assertLeafType(type: ?GraphQLType): GraphQLLeafType {
138-
invariant(
139-
isLeafType(type),
140-
`GraphQL: Expected type ${String(type)} to be a GraphQLLeafType.`,
141-
);
142-
return (type: any);
143-
}
144-
145137
export function isLeafType(type: ?GraphQLType): boolean {
146138
const namedType = getNamedType(type);
147139
return (
@@ -150,6 +142,14 @@ export function isLeafType(type: ?GraphQLType): boolean {
150142
);
151143
}
152144

145+
export function assertLeafType(type: ?GraphQLType): GraphQLLeafType {
146+
invariant(
147+
isLeafType(type),
148+
`Expected ${String(type)} to be a GraphQL leaf type.`,
149+
);
150+
return (type: any);
151+
}
152+
153153
/**
154154
* These types may describe the parent context of a selection set.
155155
*/
@@ -158,14 +158,6 @@ export type GraphQLCompositeType =
158158
GraphQLInterfaceType |
159159
GraphQLUnionType;
160160

161-
export function assertCompositeType(type: ?GraphQLType): GraphQLCompositeType {
162-
invariant(
163-
isCompositeType(type),
164-
`GraphQL: Expected type ${String(type)} to be a GraphQLCompositeType.`,
165-
);
166-
return (type: any);
167-
}
168-
169161
export function isCompositeType(type: ?GraphQLType): boolean {
170162
return (
171163
type instanceof GraphQLObjectType ||
@@ -174,28 +166,36 @@ export function isCompositeType(type: ?GraphQLType): boolean {
174166
);
175167
}
176168

169+
export function assertCompositeType(type: ?GraphQLType): GraphQLCompositeType {
170+
invariant(
171+
isCompositeType(type),
172+
`Expected ${String(type)} to be a GraphQL composite type.`,
173+
);
174+
return (type: any);
175+
}
176+
177177
/**
178178
* These types may describe the parent context of a selection set.
179179
*/
180180
export type GraphQLAbstractType =
181181
GraphQLInterfaceType |
182182
GraphQLUnionType;
183183

184-
export function assertAbstractType(type: ?GraphQLType): GraphQLAbstractType {
185-
invariant(
186-
isAbstractType(type),
187-
`GraphQL: Expected type ${String(type)} to be a GraphQLAbstractType.`,
188-
);
189-
return (type: any);
190-
}
191-
192184
export function isAbstractType(type: ?GraphQLType): boolean {
193185
return (
194186
type instanceof GraphQLInterfaceType ||
195187
type instanceof GraphQLUnionType
196188
);
197189
}
198190

191+
export function assertAbstractType(type: ?GraphQLType): GraphQLAbstractType {
192+
invariant(
193+
isAbstractType(type),
194+
`Expected ${String(type)} to be a GraphQL abstract type.`,
195+
);
196+
return (type: any);
197+
}
198+
199199
/**
200200
* These types can all accept null as a value.
201201
*/

src/type/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
export { GraphQLSchema } from './schema';
1313

1414
export {
15-
// Assertions
16-
assertType,
17-
assertInputType,
18-
assertOutputType,
19-
assertLeafType,
20-
assertCompositeType,
21-
assertAbstractType,
22-
2315
// Predicates
2416
isType,
2517
isInputType,
@@ -28,6 +20,14 @@ export {
2820
isCompositeType,
2921
isAbstractType,
3022

23+
// Assertions
24+
assertType,
25+
assertInputType,
26+
assertOutputType,
27+
assertLeafType,
28+
assertCompositeType,
29+
assertAbstractType,
30+
3131
// Un-modifiers
3232
getNullableType,
3333
getNamedType,

0 commit comments

Comments
 (0)