Skip to content

Commit ed2585d

Browse files
committed
refactor(checkForResolveTypeResolver): use mapSchema for
1 parent 9ec00c5 commit ed2585d

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
import { GraphQLInterfaceType, GraphQLUnionType, GraphQLSchema, isAbstractType } from 'graphql';
1+
import { GraphQLSchema } from 'graphql';
22

3-
// If we have any union or interface types throw if no there is no resolveType or isTypeOf resolvers
3+
import { MapperKind, mapSchema } from '@graphql-tools/utils';
4+
5+
// If we have any union or interface types throw if no there is no resolveType resolver
46
export function checkForResolveTypeResolver(schema: GraphQLSchema, requireResolversForResolveType?: boolean) {
5-
Object.keys(schema.getTypeMap())
6-
.map(typeName => schema.getType(typeName))
7-
.forEach((type: GraphQLUnionType | GraphQLInterfaceType) => {
8-
if (!isAbstractType(type)) {
9-
return;
10-
}
11-
if (!type.resolveType) {
12-
if (!requireResolversForResolveType) {
13-
return;
14-
}
7+
mapSchema(schema, {
8+
[MapperKind.ABSTRACT_TYPE]: type => {
9+
if (!type.resolveType && requireResolversForResolveType) {
1510
throw new Error(
1611
`Type "${type.name}" is missing a "__resolveType" resolver. Pass false into ` +
1712
'"resolverValidationOptions.requireResolversForResolveType" to disable this error.'
1813
);
1914
}
20-
});
15+
return undefined;
16+
},
17+
});
2118
}

0 commit comments

Comments
 (0)