management-sdk icon indicating copy to clipboard operation
management-sdk copied to clipboard

feat: add registerChanges method

Open notrab opened this issue 3 years ago • 4 comments

Exposes registerChanges to apply bulk changes onto the current migration.

Example usage:

const migration = newMigration({
  endpoint: "...",
  authToken: "...",
});

migration.registerChanges([
  {
    createModel: {
      apiId: "Post",
      apiIdPlural: "Posts",
      description: "",
      displayName: "Post",
      previewURLs: [],
    },
  },
  {
    createSimpleField: {
      apiId: "title",
      modelApiId: "Post",
      type: "STRING",
      displayName: "Title",
      description: null,
      tableRenderer: "GCMS_SINGLE_LINE",
      formRenderer: "GCMS_SINGLE_LINE",
      tableExtension: null,
      formExtension: null,
      formConfig: {},
      tableConfig: {},
      isList: false,
      isLocalized: false,
      isRequired: false,
      isUnique: false,
      isHidden: false,
      embeddableModels: [],
      visibility: "READ_WRITE",
      isTitle: false,
      position: 9,
      validations: null,
      embedsEnabled: null,
    },
  },
  {
    createSimpleField: {
      apiId: "content",
      modelApiId: "Post",
      type: "RICHTEXT",
      displayName: "Content",
      description: null,
      tableRenderer: "GCMS",
      formRenderer: "GCMS",
      tableExtension: null,
      formExtension: null,
      formConfig: {},
      tableConfig: {},
      isList: false,
      isLocalized: false,
      isRequired: false,
      isUnique: false,
      isHidden: false,
      embeddableModels: [],
      visibility: "READ_WRITE",
      isTitle: false,
      position: 10,
      validations: null,
      embedsEnabled: false,
    },
  },
  {
    updateSimpleField: {
      apiId: "fileName",
      modelApiId: "Migration",
      tableRenderer: "GCMS",
    },
  },
]);

migration.run();

I used GraphQLBatchMigrationChangeInput for better typing, but we may want to change it to MigrationChange if we don't want so strict typing.

notrab avatar Jan 26 '22 14:01 notrab

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
dist/index.js 17.7 KB (+0.1% 🔺) 354 ms (+0.1% 🔺) 134 ms (+49.41% 🔺) 487 ms

github-actions[bot] avatar Jan 26 '22 20:01 github-actions[bot]

I'd prefer to add some named arguments here, e.g.

registerChanges({changes: []})

What do you think @d-winter ?

notrab avatar Jan 26 '22 20:01 notrab

This feature would be amazing. Having this level of control will help in solving a lot of the migration issues we have in our team!

joelpierre avatar Jan 27 '22 23:01 joelpierre

Just a small note this basically gives direct access to the underlying api with all it's power. It will give us less control to hide certain fields and will potentially make it harder to make backwards compatible changes.

flexzuu avatar Feb 16 '22 15:02 flexzuu