Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add registerChanges method #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

notrab
Copy link
Contributor

@notrab notrab commented Jan 26, 2022

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 notrab requested a review from d-winter January 26, 2022 14:24
@github-actions
Copy link

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

@notrab
Copy link
Contributor Author

notrab commented Jan 26, 2022

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

registerChanges({changes: []})

What do you think @d-winter ?

@notrab notrab requested a review from flexzuu January 27, 2022 12:03
@joelpierre
Copy link
Contributor

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!

@notrab notrab marked this pull request as ready for review February 1, 2022 15:54
@flexzuu
Copy link
Member

flexzuu commented Feb 16, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants