@fraym/crud 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cmd/crud.js CHANGED
@@ -34,18 +34,38 @@ run();
34
34
  const getTypeDefinition = (schema) => {
35
35
  const definitions = {};
36
36
  schema.toConfig().types.forEach(t => {
37
- var _a;
38
- if (((_a = t.astNode) === null || _a === void 0 ? void 0 : _a.kind) !== graphql_1.Kind.OBJECT_TYPE_DEFINITION || !(t instanceof graphql_1.GraphQLObjectType)) {
37
+ if (!(t instanceof graphql_1.GraphQLObjectType) && !(t instanceof graphql_1.GraphQLEnumType)) {
39
38
  return;
40
39
  }
41
40
  const name = t.toString();
42
41
  if (definitions[name]) {
43
42
  throw new Error(`duplicate definition for type "${name}" detected, try renaming one of them as they have to be uniquely named`);
44
43
  }
45
- definitions[name] = getTypeDefinitionFromGraphQLObjectType(t);
44
+ if (t instanceof graphql_1.GraphQLObjectType) {
45
+ definitions[name] = getTypeDefinitionFromGraphQLObjectType(t);
46
+ return;
47
+ }
48
+ if (t instanceof graphql_1.GraphQLEnumType) {
49
+ definitions[name] = getTypeDefinitionFromGraphQLEnumType(t);
50
+ return;
51
+ }
46
52
  });
47
53
  return definitions;
48
54
  };
55
+ const getTypeDefinitionFromGraphQLEnumType = (t) => {
56
+ var _a, _b;
57
+ const name = t.toString();
58
+ let enumValuesString = "";
59
+ (_b = (_a = t.astNode) === null || _a === void 0 ? void 0 : _a.values) === null || _b === void 0 ? void 0 : _b.forEach(value => {
60
+ enumValuesString += `\n\t${value.name.value}`;
61
+ });
62
+ const schema = `enum ${name} {${enumValuesString}\n}`;
63
+ return {
64
+ isCrudType: false,
65
+ nestedTypes: [],
66
+ schema,
67
+ };
68
+ };
49
69
  const getTypeDefinitionFromGraphQLObjectType = (t) => {
50
70
  var _a, _b, _c, _d, _e, _f, _g;
51
71
  const isCrudType = (_c = (((_a = t.astNode) === null || _a === void 0 ? void 0 : _a.directives) &&
@@ -86,7 +106,7 @@ const getFieldStringAndNestedTypes = (f) => {
86
106
  nestedTypes.push(nestedType);
87
107
  }
88
108
  return {
89
- str: `\n${f.name.value}: ${typeString}${directivesString}`,
109
+ str: `\n\t${f.name.value}: ${typeString}${directivesString}`,
90
110
  nestedTypes,
91
111
  };
92
112
  };
@@ -183,23 +203,24 @@ const migrateSchemas = async (definitions, serverAddress) => {
183
203
  typesToUpdate.push(existingName);
184
204
  updateSchema += `\n${definitions[existingName].schema}`;
185
205
  definitions[existingName].nestedTypes.forEach(nestedTypeName => {
186
- if (nestedTypesToUpdate.indexOf(nestedTypeName) !== -1) {
206
+ if (nestedTypesToUpdate.indexOf(nestedTypeName) !== -1 ||
207
+ (definitions[nestedTypeName] && definitions[nestedTypeName].isCrudType)) {
187
208
  return;
188
209
  }
189
210
  updateSchema += `\n${definitions[nestedTypeName].schema}`;
190
211
  nestedTypesToUpdate.push(nestedTypeName);
191
212
  });
192
- delete definitions[existingName];
193
213
  }
194
214
  });
195
215
  Object.keys(definitions).forEach(newName => {
196
- if (!definitions[newName].isCrudType) {
216
+ if (!definitions[newName].isCrudType || existingTypeNames.includes(newName)) {
197
217
  return;
198
218
  }
199
219
  typesToCreate.push(newName);
200
220
  createSchema += `\n${definitions[newName].schema}`;
201
221
  definitions[newName].nestedTypes.forEach(nestedTypeName => {
202
- if (nestedTypesToCreate.indexOf(nestedTypeName) !== -1) {
222
+ if (nestedTypesToCreate.indexOf(nestedTypeName) !== -1 ||
223
+ (definitions[nestedTypeName] && definitions[nestedTypeName].isCrudType)) {
203
224
  return;
204
225
  }
205
226
  createSchema += `\n${definitions[nestedTypeName].schema}`;
@@ -28,7 +28,6 @@ const useConfigDefaults = (config) => {
28
28
  if (!config) {
29
29
  config = (0, exports.getEnvConfig)();
30
30
  }
31
- console.log(config);
32
31
  return {
33
32
  serverAddress: config.serverAddress,
34
33
  keepaliveTimeout: (_a = config.keepaliveTimeout) !== null && _a !== void 0 ? _a : 3 * 1000,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraym/crud",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "license": "UNLICENSED",
5
5
  "homepage": "https://github.com/fraym/crud-nodejs",
6
6
  "repository": {
@@ -16,8 +16,7 @@
16
16
  "clean": "rm -rf dist",
17
17
  "prepublishOnly": "npm test && npm run lint && npm run build",
18
18
  "preversion": "npm run lint",
19
- "cmd": "dist/cmd/crud.js",
20
- "cmd2": "dist/cmd/crud.js --config .tst/crud.config.json"
19
+ "cmd": "dist/cmd/crud.js"
21
20
  },
22
21
  "files": [
23
22
  "dist/**/*"