1 | export function extendResolversFromInterfaces(schema, resolvers) {
|
2 | const extendedResolvers = {};
|
3 | const typeMap = schema.getTypeMap();
|
4 | for (const typeName in typeMap) {
|
5 | const type = typeMap[typeName];
|
6 | if ('getInterfaces' in type) {
|
7 | extendedResolvers[typeName] = {};
|
8 | for (const iFace of type.getInterfaces()) {
|
9 | if (resolvers[iFace.name]) {
|
10 | for (const fieldName in resolvers[iFace.name]) {
|
11 | if (fieldName === '__isTypeOf' || !fieldName.startsWith('__')) {
|
12 | extendedResolvers[typeName][fieldName] = resolvers[iFace.name][fieldName];
|
13 | }
|
14 | }
|
15 | }
|
16 | }
|
17 | const typeResolvers = resolvers[typeName];
|
18 | extendedResolvers[typeName] = {
|
19 | ...extendedResolvers[typeName],
|
20 | ...typeResolvers,
|
21 | };
|
22 | }
|
23 | else {
|
24 | const typeResolvers = resolvers[typeName];
|
25 | if (typeResolvers != null) {
|
26 | extendedResolvers[typeName] = typeResolvers;
|
27 | }
|
28 | }
|
29 | }
|
30 | return extendedResolvers;
|
31 | }
|