1 | var __assign = (this && this.__assign) || function () {
|
2 | __assign = Object.assign || function(t) {
|
3 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4 | s = arguments[i];
|
5 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6 | t[p] = s[p];
|
7 | }
|
8 | return t;
|
9 | };
|
10 | return __assign.apply(this, arguments);
|
11 | };
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | var graphql_1 = require("graphql");
|
14 | function extendResolversFromInterfaces(schema, resolvers) {
|
15 | var typeNames = Object.keys(__assign({}, schema.getTypeMap(), resolvers));
|
16 | var extendedResolvers = {};
|
17 | typeNames.forEach(function (typeName) {
|
18 | var typeResolvers = resolvers[typeName];
|
19 | var type = schema.getType(typeName);
|
20 | if (type instanceof graphql_1.GraphQLObjectType) {
|
21 | var interfaceResolvers = type
|
22 | .getInterfaces()
|
23 | .map(function (iFace) { return resolvers[iFace.name]; });
|
24 | extendedResolvers[typeName] = Object.assign.apply(Object, [{}].concat(interfaceResolvers, [typeResolvers]));
|
25 | }
|
26 | else {
|
27 | if (typeResolvers) {
|
28 | extendedResolvers[typeName] = typeResolvers;
|
29 | }
|
30 | }
|
31 | });
|
32 | return extendedResolvers;
|
33 | }
|
34 | exports.default = extendResolversFromInterfaces;
|
35 |
|
\ | No newline at end of file |