1 | "use strict";
|
2 | var definition_1 = require("graphql/type/definition");
|
3 | var utils_1 = require("./utils");
|
4 | var ignoredScalars = ['Boolean', 'Float', 'String', 'ID', 'Int'];
|
5 | exports.handleType = function (primitivesMap, type) {
|
6 | var typeName = type['name'];
|
7 | var currentType = {
|
8 | imports: [],
|
9 | name: typeName,
|
10 | fields: [],
|
11 | isEnum: false,
|
12 | isObject: false,
|
13 | isCustomScalar: false
|
14 | };
|
15 | if (!utils_1.shouldSkip(typeName)) {
|
16 | if (type instanceof definition_1.GraphQLEnumType) {
|
17 | currentType.isEnum = true;
|
18 | currentType.enumValues = type.getValues().map(function (enumItem) {
|
19 | return {
|
20 | name: enumItem.name,
|
21 | description: enumItem.description,
|
22 | value: enumItem.value
|
23 | };
|
24 | });
|
25 | }
|
26 | else if (type instanceof definition_1.GraphQLObjectType || type instanceof definition_1.GraphQLInputObjectType || type instanceof definition_1.GraphQLInterfaceType) {
|
27 | currentType.isObject = true;
|
28 | var fields_1 = type.getFields();
|
29 | if (type instanceof definition_1.GraphQLObjectType) {
|
30 | currentType.implementedInterfaces = type.getInterfaces().map(function (interf) {
|
31 | return interf.name;
|
32 | });
|
33 | currentType.hasImplementedInterfaces = currentType.implementedInterfaces.length > 0;
|
34 | }
|
35 | currentType.fields = Object
|
36 | .keys(fields_1)
|
37 | .map(function (fieldName) { return fields_1[fieldName]; })
|
38 | .map(function (field) {
|
39 | var type = utils_1.getTypeName(primitivesMap, field.type);
|
40 | if (!utils_1.isPrimitive(primitivesMap, type)) {
|
41 | currentType.imports.push(type);
|
42 | }
|
43 | return {
|
44 | name: field.name,
|
45 | type: type,
|
46 | isArray: utils_1.isArray(field.type),
|
47 | isRequired: utils_1.isRequired(field.type)
|
48 | };
|
49 | });
|
50 | }
|
51 | else if (type instanceof definition_1.GraphQLUnionType) {
|
52 | currentType.name = type.name || typeName;
|
53 | currentType.isUnion = true;
|
54 | currentType.isObject = false;
|
55 | currentType.unionTypes = type.getTypes().map(function (type) { return type.name; });
|
56 | currentType.hasUnionTypes = currentType.unionTypes.length > 0;
|
57 | }
|
58 | else if (type instanceof definition_1.GraphQLList || type instanceof definition_1.GraphQLNonNull) {
|
59 | return exports.handleType(primitivesMap, definition_1.getNamedType(type));
|
60 | }
|
61 | else if (type instanceof definition_1.GraphQLScalarType && ignoredScalars.indexOf(currentType.name) === -1) {
|
62 | currentType.isCustomScalar = true;
|
63 | }
|
64 | return currentType;
|
65 | }
|
66 | else {
|
67 | return null;
|
68 | }
|
69 | };
|
70 |
|
\ | No newline at end of file |