Skip to content

Commit a506bfe

Browse files
committed
Use type guards rather than instanceof
1 parent 9669fe9 commit a506bfe

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ function makeConvertType(toStrict: boolean) {
109109
} else {
110110
return unwrapped;
111111
}
112-
} else if (type instanceof GraphQLNonNull) {
112+
} else if (isNonNullType(type)) {
113113
return new GraphQLNonNull(
114114
convertType(type.ofType as GraphQLNullableType),
115115
);
116-
} else if (type instanceof GraphQLList) {
116+
} else if (isListType(type)) {
117117
return new GraphQLList(convertType(type.ofType as GraphQLType));
118118
}
119119
if (type.name.startsWith("__")) {
@@ -123,21 +123,21 @@ function makeConvertType(toStrict: boolean) {
123123
return cache.get(type.name);
124124
}
125125
const newType = (() => {
126-
if (type instanceof GraphQLObjectType) {
126+
if (isObjectType(type)) {
127127
const config = type.toConfig();
128128
return new GraphQLObjectType({
129129
...config,
130130
fields: convertFields(config.fields),
131131
interfaces: convertTypes(config.interfaces),
132132
});
133-
} else if (type instanceof GraphQLInterfaceType) {
133+
} else if (isInterfaceType(type)) {
134134
const config = type.toConfig();
135135
return new GraphQLInterfaceType({
136136
...config,
137137
fields: convertFields(config.fields),
138138
interfaces: convertTypes(config.interfaces),
139139
});
140-
} else if (type instanceof GraphQLUnionType) {
140+
} else if (isUnionType(type)) {
141141
const config = type.toConfig();
142142
return new GraphQLUnionType({
143143
...config,
@@ -203,7 +203,7 @@ export function convertFieldConfig(
203203
// uses both semantic-non-null and the `@semanticNonNull` directive, we
204204
// want the directive to win (I guess?)
205205
return recurse(type.ofType, level);
206-
} else if (type instanceof GraphQLNonNull) {
206+
} else if (isNonNullType(type)) {
207207
const inner = recurse(type.ofType, level);
208208
if (levels.includes(level)) {
209209
// Semantic non-null from `inner` replaces our GraphQLNonNull wrapper
@@ -212,7 +212,7 @@ export function convertFieldConfig(
212212
// Keep non-null wrapper; no semantic-non-null was added to `inner`
213213
return new GraphQLNonNull(inner);
214214
}
215-
} else if (type instanceof GraphQLList) {
215+
} else if (isListType(type)) {
216216
const inner = new GraphQLList(recurse(type.ofType, level + 1));
217217
if (levels.includes(level)) {
218218
return new GraphQLNonNull(inner);

0 commit comments

Comments
 (0)