@fraym/crud 0.13.1 → 0.14.1

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.
Files changed (2) hide show
  1. package/dist/cmd/crud.js +37 -13
  2. package/package.json +1 -1
package/dist/cmd/crud.js CHANGED
@@ -188,6 +188,8 @@ const getValueString = (v) => {
188
188
  return `${v.value}`;
189
189
  case graphql_1.Kind.NULL:
190
190
  return `null`;
191
+ case graphql_1.Kind.ENUM:
192
+ return `${v.value}`;
191
193
  case graphql_1.Kind.OBJECT:
192
194
  let objectString = "";
193
195
  v.fields.forEach(f => {
@@ -197,10 +199,32 @@ const getValueString = (v) => {
197
199
  objectString += `${f.name.value}: ${getValueString(f.value)}`;
198
200
  });
199
201
  return `{${objectString}}`;
200
- default:
201
- throw new Error(`values of kind ${v.kind} are currently not supported`);
202
202
  }
203
203
  };
204
+ const addNestedTypesToSchema = (definitions, nestedTypeName, nestedTypes) => {
205
+ const nestedTypeDefinition = definitions[nestedTypeName];
206
+ if (nestedTypes.indexOf(nestedTypeName) !== -1 ||
207
+ (nestedTypeDefinition && nestedTypeDefinition.isCrudType)) {
208
+ return {
209
+ schema: "",
210
+ nestedTypes: [],
211
+ };
212
+ }
213
+ let newSchema = definitions[nestedTypeName].schema;
214
+ nestedTypes.push(nestedTypeName);
215
+ nestedTypeDefinition.nestedTypes.forEach(nestedNestedTypeName => {
216
+ const nestedSchemaData = addNestedTypesToSchema(definitions, nestedNestedTypeName, nestedTypes);
217
+ if (nestedSchemaData.schema === "") {
218
+ return;
219
+ }
220
+ newSchema += `\n${nestedSchemaData.schema}`;
221
+ nestedTypes.push(...nestedSchemaData.nestedTypes);
222
+ });
223
+ return {
224
+ schema: newSchema,
225
+ nestedTypes: nestedTypes,
226
+ };
227
+ };
204
228
  const migrateSchemas = async (definitions, serverAddress, namespace) => {
205
229
  console.log(`Considering ${Object.keys(definitions).length} type definitions for migration.`);
206
230
  console.log(`Using server address ${serverAddress}`);
@@ -222,12 +246,12 @@ const migrateSchemas = async (definitions, serverAddress, namespace) => {
222
246
  typesToUpdate.push(existingName);
223
247
  updateSchema += `\n${definitions[existingName].schema}`;
224
248
  definitions[existingName].nestedTypes.forEach(nestedTypeName => {
225
- if (nestedTypesToUpdate.indexOf(nestedTypeName) !== -1 ||
226
- (definitions[nestedTypeName] && definitions[nestedTypeName].isCrudType)) {
249
+ const nestedSchemaData = addNestedTypesToSchema(definitions, nestedTypeName, nestedTypesToUpdate);
250
+ if (nestedSchemaData.schema === "") {
227
251
  return;
228
252
  }
229
- updateSchema += `\n${definitions[nestedTypeName].schema}`;
230
- nestedTypesToUpdate.push(nestedTypeName);
253
+ updateSchema += `\n${nestedSchemaData.schema}`;
254
+ nestedTypesToUpdate.push(...nestedSchemaData.nestedTypes);
231
255
  });
232
256
  }
233
257
  });
@@ -238,27 +262,27 @@ const migrateSchemas = async (definitions, serverAddress, namespace) => {
238
262
  typesToCreate.push(newName);
239
263
  createSchema += `\n${definitions[newName].schema}`;
240
264
  definitions[newName].nestedTypes.forEach(nestedTypeName => {
241
- if (nestedTypesToCreate.indexOf(nestedTypeName) !== -1 ||
242
- (definitions[nestedTypeName] && definitions[nestedTypeName].isCrudType)) {
265
+ const nestedSchemaData = addNestedTypesToSchema(definitions, nestedTypeName, nestedTypesToCreate);
266
+ if (nestedSchemaData.schema === "") {
243
267
  return;
244
268
  }
245
- createSchema += `\n${definitions[nestedTypeName].schema}`;
246
- nestedTypesToCreate.push(nestedTypeName);
269
+ createSchema += `\n${nestedSchemaData.schema}`;
270
+ nestedTypesToCreate.push(...nestedSchemaData.nestedTypes);
247
271
  });
248
272
  });
249
273
  if (typesToCreate.length > 0) {
250
274
  console.log(`Creating ${typesToCreate.length} types: ${typesToCreate}...`);
251
- await managementClient.createTypes(createSchema).catch(console.log);
275
+ await managementClient.createTypes(createSchema);
252
276
  console.log(`Created ${typesToCreate.length} types`);
253
277
  }
254
278
  if (typesToUpdate.length > 0) {
255
279
  console.log(`Updating ${typesToUpdate.length} types: ${typesToUpdate}...`);
256
- await managementClient.updateTypes(updateSchema).catch(console.log);
280
+ await managementClient.updateTypes(updateSchema);
257
281
  console.log(`Updated ${typesToUpdate.length} types`);
258
282
  }
259
283
  if (typesToRemove.length > 0) {
260
284
  console.log(`Removing ${typesToRemove.length} types: ${typesToRemove}...`);
261
- await managementClient.removeTypes(typesToRemove).catch(console.log);
285
+ await managementClient.removeTypes(typesToRemove);
262
286
  console.log(`Removed ${typesToRemove.length} types`);
263
287
  }
264
288
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraym/crud",
3
- "version": "0.13.1",
3
+ "version": "0.14.1",
4
4
  "license": "UNLICENSED",
5
5
  "homepage": "https://github.com/fraym/crud-nodejs",
6
6
  "repository": {