1 | "use strict";
|
2 | var definition_1 = require("graphql/type/definition");
|
3 | var definition_2 = require("graphql/type/definition");
|
4 | var pascalCase = require("pascal-case");
|
5 | exports.isPrimitive = function (primitivesMap, type) {
|
6 | return Object.keys(primitivesMap).map(function (key) { return primitivesMap[key]; }).find(function (item) { return item === type; });
|
7 | };
|
8 | exports.shouldSkip = function (typeName) {
|
9 | return !typeName || typeName.indexOf('__') > -1;
|
10 | };
|
11 | exports.isRequired = function (type) {
|
12 | return (String(type)).indexOf('!') > -1;
|
13 | };
|
14 | exports.isArray = function (type) {
|
15 | return (String(type)).indexOf('[') > -1;
|
16 | };
|
17 | exports.getTypeName = function (primitivesMap, type) {
|
18 | var name = (String(type)).replace(/[\[\]!]/g, '');
|
19 | if (primitivesMap[name]) {
|
20 | return primitivesMap[name];
|
21 | }
|
22 | else {
|
23 | return name;
|
24 | }
|
25 | };
|
26 | function getFieldDef(parentType, fieldAST) {
|
27 | var name = fieldAST.name.value;
|
28 | if (parentType instanceof definition_2.GraphQLObjectType ||
|
29 | parentType instanceof definition_1.GraphQLInterfaceType) {
|
30 | return parentType.getFields()[name];
|
31 | }
|
32 | }
|
33 | exports.getFieldDef = getFieldDef;
|
34 | exports.handleNameDuplications = function (name, existing) {
|
35 | if (existing.find(function (model) { return model.name === name; })) {
|
36 | return exports.handleNameDuplications('_' + name, existing);
|
37 | }
|
38 | return name;
|
39 | };
|
40 | exports.getRoot = function (schema, operation) {
|
41 | switch (operation.operation) {
|
42 | case 'query':
|
43 | return schema.getQueryType();
|
44 | case 'mutation':
|
45 | return schema.getMutationType();
|
46 | case 'subscription':
|
47 | return schema.getSubscriptionType();
|
48 | default:
|
49 | return;
|
50 | }
|
51 | };
|
52 | exports.buildName = function (typesMap, name, type) {
|
53 | return pascalCase(name) + typesMap[type];
|
54 | };
|
55 |
|
\ | No newline at end of file |