UNPKG

3.16 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var graphql_1 = require("graphql");
4var object_map_to_array_1 = require("../utils/object-map-to-array");
5var resolve_type_1 = require("./resolve-type");
6var resolve_arguments_1 = require("./resolve-arguments");
7var resolve_type_indicators_1 = require("./resolve-type-indicators");
8var debugging_1 = require("../debugging");
9var get_directives_1 = require("../utils/get-directives");
10function resolveFields(schema, rawFields, _parent) {
11 var fieldsArray = object_map_to_array_1.objectMapToArray(rawFields);
12 return fieldsArray.map(function (item) {
13 var type = resolve_type_1.resolveType(item.value.type);
14 var resolvedArguments = resolve_arguments_1.resolveArguments(schema, item.value.args || []);
15 var namedType = graphql_1.getNamedType(item.value.type);
16 var indicators = resolve_type_indicators_1.resolveTypeIndicators(namedType);
17 var directives = get_directives_1.getDirectives(schema, item.value);
18 debugging_1.debugLog("[resolveFields] transformed field " + item.value.name + " of type " + type + ", resolved type is: ", type);
19 return {
20 name: item.value.name,
21 description: item.value.description || '',
22 arguments: resolvedArguments,
23 type: type.name,
24 fieldType: toFieldType(schema, namedType),
25 raw: type.raw,
26 isNullableArray: type.isNullableArray,
27 isArray: type.isArray,
28 dimensionOfArray: type.dimensionOfArray,
29 isRequired: type.isRequired,
30 hasArguments: resolvedArguments.length > 0,
31 isEnum: indicators.isEnum,
32 isScalar: indicators.isScalar,
33 isInterface: indicators.isInterface,
34 isUnion: indicators.isUnion,
35 isInputType: indicators.isInputType,
36 isType: indicators.isType,
37 directives: directives,
38 usesDirectives: Object.keys(directives).length > 0
39 };
40 });
41}
42exports.resolveFields = resolveFields;
43function toFieldType(schema, type) {
44 var typeMap = {
45 Type: function () { return type instanceof graphql_1.GraphQLObjectType; },
46 Scalar: function () { return type instanceof graphql_1.GraphQLScalarType; },
47 Interface: function () { return type instanceof graphql_1.GraphQLInterfaceType; },
48 Union: function () { return type instanceof graphql_1.GraphQLUnionType; },
49 InputType: function () { return type instanceof graphql_1.GraphQLInputObjectType; },
50 Enum: function () { return type instanceof graphql_1.GraphQLEnumType; },
51 Query: function () { return schema.getQueryType() && schema.getQueryType().name === type.name; },
52 Mutation: function () { return schema.getMutationType() && schema.getMutationType().name === type.name; },
53 Subscription: function () {
54 return schema.getSubscriptionType() && schema.getSubscriptionType().name === type.name;
55 }
56 };
57 return Object.keys(typeMap).find(function (fieldType) { return typeMap[fieldType](); });
58}
59//# sourceMappingURL=transform-fields.js.map
\No newline at end of file