1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const graphql_1 = require("graphql");
|
4 | const intTypes = [`INTEGER`, `INT`, `SMALLINT`, `TINYINT`, `MEDIUMINT`, `BIGINT`, `BIT`];
|
5 | const floatTypes = [`FLOAT`, `DOUBLE`, `REAL`, `REAL_AS_FLOAT`, `DOUBLE PRECISION`, `DEC`, `DECIMAL`, `FIXED`, `NUMERIC`];
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function getNonNullType(typeNode) {
|
13 | return {
|
14 | kind: graphql_1.Kind.NON_NULL_TYPE,
|
15 | type: typeNode
|
16 | };
|
17 | }
|
18 | exports.getNonNullType = getNonNullType;
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function getNamedType(name) {
|
26 | return {
|
27 | kind: graphql_1.Kind.NAMED_TYPE,
|
28 | name: {
|
29 | kind: graphql_1.Kind.NAME,
|
30 | value: name
|
31 | }
|
32 | };
|
33 | }
|
34 | exports.getNamedType = getNamedType;
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | function getInputValueDefinition(typeNode, name) {
|
43 | return {
|
44 | kind: graphql_1.Kind.INPUT_VALUE_DEFINITION,
|
45 | name: {
|
46 | kind: graphql_1.Kind.NAME,
|
47 | value: name
|
48 | },
|
49 | type: typeNode
|
50 | };
|
51 | }
|
52 | exports.getInputValueDefinition = getInputValueDefinition;
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | function getOperationFieldDefinition(name, args, type, directives) {
|
63 | return {
|
64 | kind: graphql_1.Kind.FIELD_DEFINITION,
|
65 | name: {
|
66 | kind: graphql_1.Kind.NAME,
|
67 | value: name
|
68 | },
|
69 | arguments: args,
|
70 | type: type,
|
71 | directives: directives
|
72 | };
|
73 | }
|
74 | exports.getOperationFieldDefinition = getOperationFieldDefinition;
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | function getFieldDefinition(fieldName, type) {
|
83 | return {
|
84 | kind: graphql_1.Kind.FIELD_DEFINITION,
|
85 | name: {
|
86 | kind: graphql_1.Kind.NAME,
|
87 | value: fieldName
|
88 | },
|
89 | type
|
90 | };
|
91 | }
|
92 | exports.getFieldDefinition = getFieldDefinition;
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | function getTypeDefinition(fields, typeName) {
|
101 | return {
|
102 | kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION,
|
103 | name: {
|
104 | kind: graphql_1.Kind.NAME,
|
105 | value: typeName
|
106 | },
|
107 | fields: fields
|
108 | };
|
109 | }
|
110 | exports.getTypeDefinition = getTypeDefinition;
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | function getInputTypeDefinition(fields, typeName) {
|
119 | return {
|
120 | kind: graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
121 | name: {
|
122 | kind: graphql_1.Kind.NAME,
|
123 | value: typeName
|
124 | },
|
125 | fields: fields
|
126 | };
|
127 | }
|
128 | exports.getInputTypeDefinition = getInputTypeDefinition;
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | function getNameNode(name) {
|
136 | return {
|
137 | kind: graphql_1.Kind.NAME,
|
138 | value: name
|
139 | };
|
140 | }
|
141 | exports.getNameNode = getNameNode;
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | function getListValueNode(values) {
|
149 | return {
|
150 | kind: graphql_1.Kind.LIST,
|
151 | values: values
|
152 | };
|
153 | }
|
154 | exports.getListValueNode = getListValueNode;
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | function getStringValueNode(value) {
|
162 | return {
|
163 | kind: graphql_1.Kind.STRING,
|
164 | value: value
|
165 | };
|
166 | }
|
167 | exports.getStringValueNode = getStringValueNode;
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | function getDirectiveNode(mutationName) {
|
175 | return {
|
176 | kind: graphql_1.Kind.DIRECTIVE,
|
177 | name: this.getNameNode('aws_subscribe'),
|
178 | arguments: [this.getArgumentNode(mutationName)]
|
179 | };
|
180 | }
|
181 | exports.getDirectiveNode = getDirectiveNode;
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 | function getOperationTypeDefinition(operationType, operation) {
|
189 | return {
|
190 | kind: graphql_1.Kind.OPERATION_TYPE_DEFINITION,
|
191 | operation: operationType,
|
192 | type: operation
|
193 | };
|
194 | }
|
195 | exports.getOperationTypeDefinition = getOperationTypeDefinition;
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 | function getArgumentNode(argument) {
|
203 | return {
|
204 | kind: graphql_1.Kind.ARGUMENT,
|
205 | name: this.getNameNode('mutations'),
|
206 | value: this.getListValueNode([this.getStringValueNode(argument)])
|
207 | };
|
208 | }
|
209 | exports.getArgumentNode = getArgumentNode;
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 | function getGraphQLTypeFromMySQLType(dbType) {
|
218 | const normalizedType = dbType.toUpperCase().split("(")[0];
|
219 | if (`BOOL` == normalizedType) {
|
220 | return `Boolean`;
|
221 | }
|
222 | else if (`JSON` == normalizedType) {
|
223 | return `AWSJSON`;
|
224 | }
|
225 | else if (`TIME` == normalizedType) {
|
226 | return `AWSTime`;
|
227 | }
|
228 | else if (`DATE` == normalizedType) {
|
229 | return `AWSDate`;
|
230 | }
|
231 | else if (`DATETIME` == normalizedType) {
|
232 | return `AWSDateTime`;
|
233 | }
|
234 | else if (`TIMESTAMP` == normalizedType) {
|
235 | return `AWSTimestamp`;
|
236 | }
|
237 | else if (intTypes.indexOf(normalizedType) > -1) {
|
238 | return `Int`;
|
239 | }
|
240 | else if (floatTypes.indexOf(normalizedType) > -1) {
|
241 | return `Float`;
|
242 | }
|
243 | return `String`;
|
244 | }
|
245 | exports.getGraphQLTypeFromMySQLType = getGraphQLTypeFromMySQLType;
|
246 |
|
\ | No newline at end of file |