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 ||
|
10 | typeName.indexOf('__') > -1 ||
|
11 | typeName === 'Query' ||
|
12 | typeName === 'Mutation' ||
|
13 | typeName === 'Subscription';
|
14 | };
|
15 | exports.isRequired = function (type) {
|
16 | return (type.toString()).indexOf('!') > -1;
|
17 | };
|
18 | exports.isArray = function (type) {
|
19 | return (type.toString()).indexOf('[') > -1;
|
20 | };
|
21 | exports.getTypeName = function (primitivesMap, type) {
|
22 | var name = (type.toString()).replace(/[\[\]!]/g, '');
|
23 | if (primitivesMap[name]) {
|
24 | return primitivesMap[name];
|
25 | }
|
26 | else {
|
27 | return name;
|
28 | }
|
29 | };
|
30 | function getFieldDef(parentType, fieldAST) {
|
31 | var name = fieldAST.name.value;
|
32 | if (parentType instanceof definition_2.GraphQLObjectType ||
|
33 | parentType instanceof definition_1.GraphQLInterfaceType) {
|
34 | return parentType.getFields()[name];
|
35 | }
|
36 | }
|
37 | exports.getFieldDef = getFieldDef;
|
38 | exports.handleNameDuplications = function (name, existing) {
|
39 | if (existing.find(function (model) { return model.name === name; })) {
|
40 | return exports.handleNameDuplications('_' + name, existing);
|
41 | }
|
42 | return name;
|
43 | };
|
44 | exports.getRoot = function (schema, operation) {
|
45 | switch (operation.operation) {
|
46 | case 'query':
|
47 | return schema.getQueryType();
|
48 | case 'mutation':
|
49 | return schema.getMutationType();
|
50 | case 'subscription':
|
51 | return schema.getSubscriptionType();
|
52 | default:
|
53 | return;
|
54 | }
|
55 | };
|
56 | exports.buildName = function (typesMap, name, type) {
|
57 | return pascalCase(name) + typesMap[type];
|
58 | };
|
59 |
|
\ | No newline at end of file |