@graphcommerce/hygraph-cli 9.0.0-canary.72 → 9.0.0-canary.73
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/CHANGELOG.md +2 -0
- package/Config.graphqls +6 -10
- package/dist/UpsertClient.js +69 -0
- package/dist/index.js +2 -2
- package/dist/migrateHygraphCli.js +111 -0
- package/dist/migrationActionFactory.js +133 -0
- package/dist/migrations/graphcommerce5to6.js +12 -14
- package/dist/migrations/graphcommerce6to7.js +25 -27
- package/dist/migrations/graphcommerce7to8.js +7 -9
- package/dist/migrations/graphcommerce8to9.js +54 -8
- package/dist/readSchema.js +10 -21
- package/dist/utils/getConfig.js +19 -0
- package/dist/utils/getEndpointUrl.js +43 -0
- package/dist/utils/getManagementClient.js +15 -0
- package/dist/{log-functions.js → utils/graphCommerceLog.js} +1 -1
- package/package.json +5 -5
- package/src/UpsertClient.ts +99 -0
- package/src/index.ts +1 -1
- package/src/migrateHygraphCli.ts +113 -0
- package/src/migrationActionFactory.ts +230 -0
- package/src/migrations/graphcommerce5to6.ts +4 -6
- package/src/migrations/graphcommerce6to7.ts +4 -6
- package/src/migrations/graphcommerce7to8.ts +4 -6
- package/src/migrations/graphcommerce8to9.ts +79 -8
- package/src/readSchema.ts +24 -29
- package/src/types.ts +6 -1
- package/src/utils/getConfig.ts +33 -0
- package/src/utils/getEndpointUrl.ts +65 -0
- package/src/utils/getManagementClient.ts +15 -0
- package/src/{log-functions.ts → utils/graphCommerceLog.ts} +1 -1
- package/dist/client.js +0 -21
- package/dist/migrateHygraph.js +0 -95
- package/dist/migrationAction.js +0 -133
- package/src/client.ts +0 -25
- package/src/migrateHygraph.ts +0 -86
- package/src/migrationAction.ts +0 -223
package/CHANGELOG.md
CHANGED
package/Config.graphqls
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
extend input GraphCommerceConfig {
|
|
2
|
-
"""
|
|
3
|
-
Content API. **Only used for migrations.**
|
|
4
|
-
|
|
5
|
-
> Regular read & write endpoint that allows querying and mutating data in your project.
|
|
6
|
-
|
|
7
|
-
Project settings -> API Access -> Content API
|
|
8
|
-
"""
|
|
9
|
-
hygraphWriteAccessEndpoint: String
|
|
10
|
-
|
|
11
2
|
"""
|
|
12
3
|
Hygraph Management SDK Authorization Token. **Only used for migrations.**
|
|
13
4
|
|
|
@@ -34,7 +25,6 @@ extend input GraphCommerceConfig {
|
|
|
34
25
|
- Can see schema view
|
|
35
26
|
|
|
36
27
|
```
|
|
37
|
-
GC_HYGRAPH_WRITE_ACCESS_ENDPOINT="https://...hygraph.com/v2/..."
|
|
38
28
|
GC_HYGRAPH_WRITE_ACCESS_TOKEN="AccessTokenFromHygraph"
|
|
39
29
|
yarn graphcommerce hygraph-migrate
|
|
40
30
|
```
|
|
@@ -43,11 +33,17 @@ extend input GraphCommerceConfig {
|
|
|
43
33
|
|
|
44
34
|
"""
|
|
45
35
|
Hygraph Project ID. **Only used for migrations.**
|
|
36
|
+
|
|
37
|
+
Optional: If the hygraphEndpoint is configured with the 'High Performance Content
|
|
38
|
+
API', this field is not required.
|
|
46
39
|
"""
|
|
47
40
|
hygraphProjectId: String
|
|
48
41
|
|
|
49
42
|
"""
|
|
50
43
|
Hygraph Management API. **Only used for migrations.**
|
|
44
|
+
|
|
45
|
+
Optional: If the hygraphEndpoint is configured with the 'High Performance Content
|
|
46
|
+
API', this field is not required.
|
|
51
47
|
"""
|
|
52
48
|
hygraphManagementApi: String
|
|
53
49
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpsertClient = void 0;
|
|
4
|
+
const management_sdk_1 = require("@hygraph/management-sdk");
|
|
5
|
+
class UpsertClient extends management_sdk_1.Client {
|
|
6
|
+
schema;
|
|
7
|
+
constructor(params, schema) {
|
|
8
|
+
super(params);
|
|
9
|
+
this.schema = schema;
|
|
10
|
+
}
|
|
11
|
+
upsertModel(data) {
|
|
12
|
+
const exists = this.schema.models.some((m) => m.apiId === data.apiId);
|
|
13
|
+
return exists ? this.createModel(data) : this.updateModel(data);
|
|
14
|
+
}
|
|
15
|
+
upsertComponent(data) {
|
|
16
|
+
const exists = this.schema.models.some((m) => m.apiId === data.apiId);
|
|
17
|
+
return exists ? this.createComponent(data) : this.updateComponent(data);
|
|
18
|
+
}
|
|
19
|
+
upsertSimpleField(data) {
|
|
20
|
+
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
21
|
+
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
22
|
+
return exists
|
|
23
|
+
? this.createSimpleField(data)
|
|
24
|
+
: this.updateSimpleField({ ...data, embeddableModels: undefined });
|
|
25
|
+
}
|
|
26
|
+
// upsertRemoteField(data: BatchMigrationCreateRemoteFieldInput) {
|
|
27
|
+
// const model = this.schema.models.find((m) => m.apiId === data.parentApiId)
|
|
28
|
+
// const exists = model?.fields.some((f) => f.apiId === data.apiId)
|
|
29
|
+
// return exists ? this.createRemoteField(data) : this.updateRemoteField(data)
|
|
30
|
+
// }
|
|
31
|
+
upsertRelationalField(data) {
|
|
32
|
+
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
33
|
+
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
34
|
+
return exists ? this.createRelationalField(data) : this.updateRelationalField(data);
|
|
35
|
+
}
|
|
36
|
+
upsertUnionField(data) {
|
|
37
|
+
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
38
|
+
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
39
|
+
return exists ? this.createUnionField(data) : this.updateUnionField(data);
|
|
40
|
+
}
|
|
41
|
+
upsertComponentField(data) {
|
|
42
|
+
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
43
|
+
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
44
|
+
return exists ? this.createComponentField(data) : this.updateComponentField(data);
|
|
45
|
+
}
|
|
46
|
+
upsertComponentUnionField(data) {
|
|
47
|
+
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
48
|
+
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
49
|
+
return exists ? this.createComponentUnionField(data) : this.updateComponentUnionField(data);
|
|
50
|
+
}
|
|
51
|
+
upsertEnumeration(data) {
|
|
52
|
+
const exists = this.schema.enumerations.some((e) => e.apiId === data.apiId);
|
|
53
|
+
return exists ? this.createEnumeration(data) : this.updateEnumeration(data);
|
|
54
|
+
}
|
|
55
|
+
upsertEnumerableField(data) {
|
|
56
|
+
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
57
|
+
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
58
|
+
return exists ? this.createEnumerableField(data) : this.updateEnumerableField(data);
|
|
59
|
+
}
|
|
60
|
+
upsertStage(data) {
|
|
61
|
+
const exists = this.schema.stages.some((m) => m.apiId === data.apiId);
|
|
62
|
+
return exists ? this.createStage(data) : this.updateStage(data);
|
|
63
|
+
}
|
|
64
|
+
upsertLocale(data) {
|
|
65
|
+
const exists = this.schema.locales.some((m) => m.apiId === data.apiId);
|
|
66
|
+
return exists ? this.createLocale(data) : this.updateLocale(data);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.UpsertClient = UpsertClient;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.migrateHygraph = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "migrateHygraph", { enumerable: true, get: function () { return
|
|
4
|
+
var migrateHygraphCli_1 = require("./migrateHygraphCli");
|
|
5
|
+
Object.defineProperty(exports, "migrateHygraph", { enumerable: true, get: function () { return migrateHygraphCli_1.migrateHygraphCli; } });
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.migrateHygraphCli = migrateHygraphCli;
|
|
30
|
+
const fs_1 = __importDefault(require("fs"));
|
|
31
|
+
const next_config_1 = require("@graphcommerce/next-config");
|
|
32
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
33
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
34
|
+
const UpsertClient_1 = require("./UpsertClient");
|
|
35
|
+
const availableMigrations = __importStar(require("./migrations"));
|
|
36
|
+
const readSchema_1 = require("./readSchema");
|
|
37
|
+
const getConfig_1 = require("./utils/getConfig");
|
|
38
|
+
const getEndpointUrl_1 = require("./utils/getEndpointUrl");
|
|
39
|
+
const getManagementClient_1 = require("./utils/getManagementClient");
|
|
40
|
+
const graphCommerceLog_1 = require("./utils/graphCommerceLog");
|
|
41
|
+
dotenv_1.default.config();
|
|
42
|
+
async function migrateHygraphCli() {
|
|
43
|
+
const hygraphConfig = (0, getConfig_1.getConfig)((0, next_config_1.loadConfig)(process.cwd()));
|
|
44
|
+
/**
|
|
45
|
+
* Extracting the current GC version. Are we gonna use the current version to determine which
|
|
46
|
+
* scripts should be runned? Or do we let the user pick the migration from a list? 🤔
|
|
47
|
+
*/
|
|
48
|
+
const packageJson = fs_1.default.readFileSync('package.json', 'utf8');
|
|
49
|
+
const packageData = JSON.parse(packageJson);
|
|
50
|
+
const graphcommerceVersion = packageData.dependencies['@graphcommerce/next-ui'];
|
|
51
|
+
(0, graphCommerceLog_1.graphcommerceLog)(`Graphcommerce version: ${graphcommerceVersion}`, 'info');
|
|
52
|
+
const mangementClient = (0, getManagementClient_1.getManagementClient)(hygraphConfig);
|
|
53
|
+
// Extract the currently existing models, components and enumerations from the Hygraph schema.
|
|
54
|
+
const schemaViewer = await (0, readSchema_1.readSchema)(mangementClient, hygraphConfig.projectId);
|
|
55
|
+
const schema = schemaViewer.viewer.project.environment.contentModel;
|
|
56
|
+
// A list of possible migrations
|
|
57
|
+
const possibleMigrations = Object.entries(availableMigrations);
|
|
58
|
+
// Here we setup the list we ask the user to choose from
|
|
59
|
+
const selectMigrationInput = {
|
|
60
|
+
type: 'select',
|
|
61
|
+
name: 'selectedMigration',
|
|
62
|
+
message: '\x1b[36m\x1b[1m[]: Select migration',
|
|
63
|
+
choices: possibleMigrations.map(([name, migration]) => ({
|
|
64
|
+
title: name,
|
|
65
|
+
value: { name, migration },
|
|
66
|
+
})),
|
|
67
|
+
};
|
|
68
|
+
// Here we ask the user to choose a migration from a list of possible migrations
|
|
69
|
+
try {
|
|
70
|
+
(0, graphCommerceLog_1.graphcommerceLog)('Available migrations: ', 'info');
|
|
71
|
+
const selectMigrationOutput = await (0, prompts_1.default)(selectMigrationInput);
|
|
72
|
+
let { migration, name } = selectMigrationOutput.selectedMigration;
|
|
73
|
+
(0, graphCommerceLog_1.graphcommerceLog)(`You have selected the ${selectMigrationOutput.selectedMigration.name} migration`, 'info');
|
|
74
|
+
try {
|
|
75
|
+
const { endpoint, migrations } = await (0, getEndpointUrl_1.getEnvironment)(mangementClient, hygraphConfig);
|
|
76
|
+
const migrationExists = migrations.find((m) => m.name?.startsWith(name) && m.status === 'SUCCESS');
|
|
77
|
+
if (migrationExists) {
|
|
78
|
+
if (!process.argv.includes('--force')) {
|
|
79
|
+
(0, graphCommerceLog_1.graphcommerceLog)(`Migration ${name} as ${migrationExists.name} already exists in Hygraph with the status SUCCESS. To rerun this migration use the --force option. Exiting now..`, 'info');
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
(0, graphCommerceLog_1.graphcommerceLog)(`Migration ${name} as ${migrationExists.name} already exists in Hygraph with the status SUCCESS. Using --force, rerunning migration..`, 'warning');
|
|
84
|
+
}
|
|
85
|
+
name = `${name}-${Date.now()}`;
|
|
86
|
+
}
|
|
87
|
+
// Here we try to run the migration
|
|
88
|
+
const result = await migration(schema, new UpsertClient_1.UpsertClient({ authToken: hygraphConfig.authToken, endpoint, name }, schema));
|
|
89
|
+
(0, graphCommerceLog_1.graphcommerceLog)(`Migration result: ${JSON.stringify(result)}`, 'info');
|
|
90
|
+
if (!result) {
|
|
91
|
+
(0, graphCommerceLog_1.graphcommerceLog)('No migration client found. Please make sure your GC_HYGRAPH_WRITE_ACCESS_TOKEN in your env file is correct.');
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
if (result.status !== 'SUCCESS') {
|
|
95
|
+
(0, graphCommerceLog_1.graphcommerceLog)(`Migration not successful: ${result.status} ${name}:\n${result.errors}`);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
(0, graphCommerceLog_1.graphcommerceLog)(`Migration successful: ${name}`, 'info');
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
if (err instanceof Error) {
|
|
102
|
+
const garbledErrorIndex = err.message.indexOf(': {"');
|
|
103
|
+
const msg = garbledErrorIndex > 0 ? err.message.slice(0, garbledErrorIndex) : err.message;
|
|
104
|
+
(0, graphCommerceLog_1.graphcommerceLog)(`${msg}`, 'error');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
(0, graphCommerceLog_1.graphcommerceLog)(`An error occurred: ${error}`, 'error');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.migrationActionFactory = migrationActionFactory;
|
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
+
const graphCommerceLog_1 = require("./utils/graphCommerceLog");
|
|
9
|
+
dotenv_1.default.config();
|
|
10
|
+
function migrationActionFactory(schema, client) {
|
|
11
|
+
/**
|
|
12
|
+
* This constant is used to assign the right action of the management SDK to the migratioAction
|
|
13
|
+
* function
|
|
14
|
+
*/
|
|
15
|
+
const actionMap = client
|
|
16
|
+
? {
|
|
17
|
+
create: {
|
|
18
|
+
model: (innerprops) => client.createModel(innerprops),
|
|
19
|
+
component: (innerprops) => client.createComponent(innerprops),
|
|
20
|
+
enumeration: (innerprops) => client.createEnumeration(innerprops),
|
|
21
|
+
simpleField: (innerprops) => client.createSimpleField(innerprops),
|
|
22
|
+
enumerableField: (innerprops) => client.createEnumerableField(innerprops),
|
|
23
|
+
componentField: (innerprops) => client.createComponentField(innerprops),
|
|
24
|
+
relationalField: (innerprops) => client.createRelationalField(innerprops),
|
|
25
|
+
unionField: (innerprops) => client.createUnionField(innerprops),
|
|
26
|
+
componentUnionField: (innerprops) => client.createComponentUnionField(innerprops),
|
|
27
|
+
},
|
|
28
|
+
update: {
|
|
29
|
+
model: (innerprops) => client.updateModel(innerprops),
|
|
30
|
+
component: (innerprops) => client.updateComponent(innerprops),
|
|
31
|
+
enumeration: (innerprops) => client.updateEnumeration(innerprops),
|
|
32
|
+
simpleField: (innerprops) => client.updateSimpleField(innerprops),
|
|
33
|
+
enumerableField: (innerprops) => client.updateEnumerableField(innerprops),
|
|
34
|
+
componentField: (innerprops) => client.updateComponentField(innerprops),
|
|
35
|
+
relationalField: (innerprops) => client.updateRelationalField(innerprops),
|
|
36
|
+
unionField: (innerprops) => client.updateUnionField(innerprops),
|
|
37
|
+
componentUnionField: (innerprops) => client.updateComponentUnionField(innerprops),
|
|
38
|
+
},
|
|
39
|
+
delete: {
|
|
40
|
+
model: (innerprops) => client.deleteModel(innerprops),
|
|
41
|
+
component: (innerprops) => client.deleteComponent(innerprops),
|
|
42
|
+
enumeration: (innerprops) => client.deleteEnumeration(innerprops),
|
|
43
|
+
simpleField: (innerprops) => client.deleteField(innerprops),
|
|
44
|
+
enumerableField: (innerprops) => client.deleteField(innerprops),
|
|
45
|
+
componentField: (innerprops) => client.deleteField(innerprops),
|
|
46
|
+
relationalField: (innerprops) => client.deleteField(innerprops),
|
|
47
|
+
unionField: (innerprops) => client.deleteField(innerprops),
|
|
48
|
+
componentUnionField: (innerprops) => client.deleteField(innerprops),
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
: undefined;
|
|
52
|
+
/**
|
|
53
|
+
* This function is our variation on the client.migrationAction functions from the hygraph
|
|
54
|
+
* management sdk.
|
|
55
|
+
*
|
|
56
|
+
* MigrationAction() is better suited because it is a single function for all actions. More
|
|
57
|
+
* importantly, if the action fails, because a field with the apiID already exists for instance. it
|
|
58
|
+
* will skip this action but still continue the whole migration, while the management sdk function
|
|
59
|
+
* will bail.
|
|
60
|
+
*
|
|
61
|
+
* It takes the schema as argument, which is always the same.
|
|
62
|
+
*
|
|
63
|
+
* Then it takes the type of schema entity you want to do an action upon, and the action you want to
|
|
64
|
+
* do.
|
|
65
|
+
*
|
|
66
|
+
* The fourth arguments are the props that belong to the action you want to do. For instance, if you
|
|
67
|
+
* want to create a model, you need to pass the props that belong to a model.
|
|
68
|
+
*
|
|
69
|
+
* The last two arguments are optional. If you want to create a field, you need to pass the apiId of
|
|
70
|
+
* the model or component you want to create the field on. If you want to create a field on a
|
|
71
|
+
* component, you also need to pass the parentType, which is either 'model' or 'component'.
|
|
72
|
+
*/
|
|
73
|
+
const migrationAction = (_schema, type, action, props, parentApiId, parentType) => {
|
|
74
|
+
/**
|
|
75
|
+
* Check if the entity already exists.
|
|
76
|
+
* If an update or deletion is made, it does not matter if the entity already exists
|
|
77
|
+
*/
|
|
78
|
+
const alreadyExists = () => {
|
|
79
|
+
if (action !== 'create') {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
switch (type) {
|
|
83
|
+
case 'model':
|
|
84
|
+
return schema.models.some((model) => model.apiId === props.apiId);
|
|
85
|
+
case 'component':
|
|
86
|
+
return schema.components.some((component) => component.apiId === props.apiId);
|
|
87
|
+
case 'enumeration':
|
|
88
|
+
return schema.enumerations.some((enumeration) => enumeration.apiId === props.apiId);
|
|
89
|
+
case 'simpleField':
|
|
90
|
+
case 'enumerableField':
|
|
91
|
+
case 'relationalField':
|
|
92
|
+
case 'unionField':
|
|
93
|
+
case 'componentUnionField': {
|
|
94
|
+
let parent;
|
|
95
|
+
switch (parentType) {
|
|
96
|
+
case 'model': {
|
|
97
|
+
parent = schema.models.find((model) => model.apiId === parentApiId);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case 'component': {
|
|
101
|
+
parent = schema.components.find((component) => component.apiId === parentApiId);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
default:
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return parent?.fields.some((field) => field.apiId === props.apiId);
|
|
108
|
+
}
|
|
109
|
+
default: {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const actionFunc = actionMap && actionMap[action] && actionMap[action][type];
|
|
115
|
+
if (!alreadyExists()) {
|
|
116
|
+
if (actionFunc) {
|
|
117
|
+
(0, graphCommerceLog_1.graphcommerceLog)(`${(0, graphCommerceLog_1.capitalize)(action)} ${type} with apiId ${props.apiId}...`);
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
119
|
+
// @ts-ignore | This error is a loss on typescript autocomplete, but the function is called correctly
|
|
120
|
+
actionFunc(props);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
(0, graphCommerceLog_1.graphcommerceLog)(`Action ${action} is not supported for ${type}`, 'error');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
(0, graphCommerceLog_1.graphcommerceLog)(`${(0, graphCommerceLog_1.capitalize)(type)} with apiId ${props.apiId} on ${parentApiId} already exists`, 'warning');
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
migrationAction,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.graphcommerce5to6 = void 0;
|
|
4
4
|
const management_sdk_1 = require("@hygraph/management-sdk");
|
|
5
|
-
const
|
|
6
|
-
const graphcommerce5to6 = async (schema) => {
|
|
7
|
-
|
|
8
|
-
return 0;
|
|
9
|
-
}
|
|
5
|
+
const migrationActionFactory_1 = require("../migrationActionFactory");
|
|
6
|
+
const graphcommerce5to6 = async (schema, client) => {
|
|
7
|
+
const { migrationAction } = (0, migrationActionFactory_1.migrationActionFactory)(schema, client);
|
|
10
8
|
// ? ENUMERATIONS
|
|
11
|
-
|
|
9
|
+
migrationAction(schema, 'enumeration', 'create', {
|
|
12
10
|
displayName: 'Row Links Variants',
|
|
13
11
|
apiId: 'RowLinksVariants',
|
|
14
12
|
values: [
|
|
@@ -19,13 +17,13 @@ const graphcommerce5to6 = async (schema) => {
|
|
|
19
17
|
],
|
|
20
18
|
});
|
|
21
19
|
// ? MODEL
|
|
22
|
-
|
|
20
|
+
migrationAction(schema, 'model', 'create', {
|
|
23
21
|
apiId: 'RowLinks',
|
|
24
22
|
apiIdPlural: 'RowLinksMultiple',
|
|
25
23
|
displayName: 'Row Links',
|
|
26
24
|
description: 'Row Links is a Row of PageLinks with different variants',
|
|
27
25
|
});
|
|
28
|
-
|
|
26
|
+
migrationAction(schema, 'simpleField', 'create', {
|
|
29
27
|
displayName: 'Identity',
|
|
30
28
|
apiId: 'identity',
|
|
31
29
|
description: 'Only used for internal reference',
|
|
@@ -35,14 +33,14 @@ const graphcommerce5to6 = async (schema) => {
|
|
|
35
33
|
isUnique: true,
|
|
36
34
|
modelApiId: 'RowLinks',
|
|
37
35
|
}, 'RowLinks', 'model');
|
|
38
|
-
|
|
36
|
+
migrationAction(schema, 'enumerableField', 'create', {
|
|
39
37
|
displayName: 'Variant',
|
|
40
38
|
apiId: 'linksVariant',
|
|
41
39
|
parentApiId: 'RowLinks',
|
|
42
40
|
enumerationApiId: 'RowLinksVariants',
|
|
43
41
|
description: 'Different variants for Row Links',
|
|
44
42
|
}, 'RowLinks', 'model');
|
|
45
|
-
|
|
43
|
+
migrationAction(schema, 'simpleField', 'create', {
|
|
46
44
|
displayName: 'Title',
|
|
47
45
|
apiId: 'title',
|
|
48
46
|
type: management_sdk_1.SimpleFieldType.String,
|
|
@@ -50,14 +48,14 @@ const graphcommerce5to6 = async (schema) => {
|
|
|
50
48
|
modelApiId: 'RowLinks',
|
|
51
49
|
isLocalized: true,
|
|
52
50
|
}, 'RowLinks', 'model');
|
|
53
|
-
|
|
51
|
+
migrationAction(schema, 'simpleField', 'create', {
|
|
54
52
|
displayName: 'Copy',
|
|
55
53
|
apiId: 'rowLinksCopy',
|
|
56
54
|
type: management_sdk_1.SimpleFieldType.Richtext,
|
|
57
55
|
isLocalized: true,
|
|
58
56
|
modelApiId: 'RowLinks',
|
|
59
57
|
}, 'RowLinks', 'model');
|
|
60
|
-
|
|
58
|
+
migrationAction(schema, 'relationalField', 'create', {
|
|
61
59
|
displayName: 'Links',
|
|
62
60
|
apiId: 'pageLinks',
|
|
63
61
|
modelApiId: 'RowLinks',
|
|
@@ -72,7 +70,7 @@ const graphcommerce5to6 = async (schema) => {
|
|
|
72
70
|
visibility: management_sdk_1.VisibilityTypes.ReadWrite,
|
|
73
71
|
isList: true,
|
|
74
72
|
}, 'RowLinks', 'model');
|
|
75
|
-
|
|
73
|
+
migrationAction(schema, 'unionField', 'update', {
|
|
76
74
|
apiId: 'content',
|
|
77
75
|
displayName: 'Content',
|
|
78
76
|
modelApiId: 'Page',
|
|
@@ -95,6 +93,6 @@ const graphcommerce5to6 = async (schema) => {
|
|
|
95
93
|
// visibility: VisibilityTypes.Hidden, => Currently not supported for updateUnionField | https://github.com/hygraph/management-sdk/issues/34
|
|
96
94
|
},
|
|
97
95
|
}, 'Page', 'model');
|
|
98
|
-
return
|
|
96
|
+
return client.run(true);
|
|
99
97
|
};
|
|
100
98
|
exports.graphcommerce5to6 = graphcommerce5to6;
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.graphcommerce6to7 = void 0;
|
|
4
4
|
const management_sdk_1 = require("@hygraph/management-sdk");
|
|
5
|
-
const
|
|
6
|
-
const graphcommerce6to7 = async (schema) => {
|
|
7
|
-
|
|
8
|
-
return 0;
|
|
9
|
-
}
|
|
5
|
+
const migrationActionFactory_1 = require("../migrationActionFactory");
|
|
6
|
+
const graphcommerce6to7 = async (schema, client) => {
|
|
7
|
+
const { migrationAction } = (0, migrationActionFactory_1.migrationActionFactory)(schema, client);
|
|
10
8
|
// ? ENUMERATIONS
|
|
11
|
-
|
|
9
|
+
migrationAction(schema, 'enumeration', 'create', {
|
|
12
10
|
displayName: 'Row Column One Variants',
|
|
13
11
|
apiId: 'RowColumnOneVariants',
|
|
14
12
|
values: [
|
|
@@ -16,7 +14,7 @@ const graphcommerce6to7 = async (schema) => {
|
|
|
16
14
|
{ displayName: 'Message', apiId: 'Message' },
|
|
17
15
|
],
|
|
18
16
|
});
|
|
19
|
-
|
|
17
|
+
migrationAction(schema, 'enumeration', 'create', {
|
|
20
18
|
displayName: 'Dynamic Row Condition Number Operator',
|
|
21
19
|
apiId: 'DynamicRowConditionNumberOperator',
|
|
22
20
|
values: [
|
|
@@ -25,7 +23,7 @@ const graphcommerce6to7 = async (schema) => {
|
|
|
25
23
|
{ displayName: 'Equal to', apiId: 'EQUAL' },
|
|
26
24
|
],
|
|
27
25
|
});
|
|
28
|
-
|
|
26
|
+
migrationAction(schema, 'enumeration', 'create', {
|
|
29
27
|
displayName: 'Dynamic Row Placement',
|
|
30
28
|
apiId: 'DynamicRowPlacement',
|
|
31
29
|
values: [
|
|
@@ -35,36 +33,36 @@ const graphcommerce6to7 = async (schema) => {
|
|
|
35
33
|
],
|
|
36
34
|
});
|
|
37
35
|
// ? COMPONENTS
|
|
38
|
-
|
|
36
|
+
migrationAction(schema, 'component', 'create', {
|
|
39
37
|
displayName: 'Text',
|
|
40
38
|
apiId: 'ConditionText',
|
|
41
39
|
apiIdPlural: 'ConditionTexts',
|
|
42
40
|
});
|
|
43
|
-
|
|
41
|
+
migrationAction(schema, 'component', 'create', {
|
|
44
42
|
displayName: 'Number',
|
|
45
43
|
apiId: 'ConditionNumber',
|
|
46
44
|
apiIdPlural: 'ConditionNumbers',
|
|
47
45
|
});
|
|
48
|
-
|
|
46
|
+
migrationAction(schema, 'component', 'create', {
|
|
49
47
|
displayName: 'AND',
|
|
50
48
|
apiId: 'ConditionAnd',
|
|
51
49
|
apiIdPlural: 'ConditionAnds',
|
|
52
50
|
description: 'All of these conditions must match',
|
|
53
51
|
});
|
|
54
|
-
|
|
52
|
+
migrationAction(schema, 'component', 'create', {
|
|
55
53
|
displayName: 'OR',
|
|
56
54
|
apiId: 'ConditionOr',
|
|
57
55
|
apiIdPlural: 'ConditionOrs',
|
|
58
56
|
description: 'One of these conditions must match',
|
|
59
57
|
});
|
|
60
|
-
|
|
58
|
+
migrationAction(schema, 'componentUnionField', 'create', {
|
|
61
59
|
displayName: 'Conditions',
|
|
62
60
|
apiId: 'conditions',
|
|
63
61
|
parentApiId: 'ConditionAnd',
|
|
64
62
|
componentApiIds: ['ConditionOr', 'ConditionText', 'ConditionNumber'],
|
|
65
63
|
isList: true,
|
|
66
64
|
}, 'ConditionAnd', 'component');
|
|
67
|
-
|
|
65
|
+
migrationAction(schema, 'simpleField', 'create', {
|
|
68
66
|
displayName: 'Property',
|
|
69
67
|
apiId: 'property',
|
|
70
68
|
type: management_sdk_1.SimpleFieldType.String,
|
|
@@ -81,14 +79,14 @@ const graphcommerce6to7 = async (schema) => {
|
|
|
81
79
|
},
|
|
82
80
|
},
|
|
83
81
|
}, 'ConditionText', 'component');
|
|
84
|
-
|
|
82
|
+
migrationAction(schema, 'simpleField', 'create', {
|
|
85
83
|
displayName: 'Value',
|
|
86
84
|
apiId: 'value',
|
|
87
85
|
type: management_sdk_1.SimpleFieldType.String,
|
|
88
86
|
parentApiId: 'ConditionText',
|
|
89
87
|
isRequired: true,
|
|
90
88
|
}, 'ConditionText', 'component');
|
|
91
|
-
|
|
89
|
+
migrationAction(schema, 'simpleField', 'create', {
|
|
92
90
|
displayName: 'Property',
|
|
93
91
|
apiId: 'property',
|
|
94
92
|
type: management_sdk_1.SimpleFieldType.String,
|
|
@@ -104,14 +102,14 @@ const graphcommerce6to7 = async (schema) => {
|
|
|
104
102
|
},
|
|
105
103
|
},
|
|
106
104
|
}, 'ConditionNumber', 'component');
|
|
107
|
-
|
|
105
|
+
migrationAction(schema, 'enumerableField', 'create', {
|
|
108
106
|
displayName: 'Operator',
|
|
109
107
|
apiId: 'operator',
|
|
110
108
|
parentApiId: 'ConditionNumber',
|
|
111
109
|
enumerationApiId: 'DynamicRowConditionNumberOperator',
|
|
112
110
|
isRequired: true,
|
|
113
111
|
}, 'ConditionNumber', 'component');
|
|
114
|
-
|
|
112
|
+
migrationAction(schema, 'simpleField', 'create', {
|
|
115
113
|
displayName: 'Value',
|
|
116
114
|
apiId: 'value',
|
|
117
115
|
type: management_sdk_1.SimpleFieldType.Float,
|
|
@@ -119,13 +117,13 @@ const graphcommerce6to7 = async (schema) => {
|
|
|
119
117
|
isRequired: true,
|
|
120
118
|
}, 'ConditionNumber', 'component');
|
|
121
119
|
// ? MODEL
|
|
122
|
-
|
|
120
|
+
migrationAction(schema, 'model', 'create', {
|
|
123
121
|
displayName: 'Dynamic Row',
|
|
124
122
|
apiId: 'DynamicRow',
|
|
125
123
|
apiIdPlural: 'DynamicRows',
|
|
126
124
|
description: 'Dynamic rows allow you to add specific Row models to pages based on the properties of the page',
|
|
127
125
|
});
|
|
128
|
-
|
|
126
|
+
migrationAction(schema, 'simpleField', 'create', {
|
|
129
127
|
displayName: 'Internal name',
|
|
130
128
|
apiId: 'internalName',
|
|
131
129
|
description: 'Only used for internal reference',
|
|
@@ -135,7 +133,7 @@ const graphcommerce6to7 = async (schema) => {
|
|
|
135
133
|
isUnique: true,
|
|
136
134
|
modelApiId: 'DynamicRow',
|
|
137
135
|
}, 'DynamicRow', 'model');
|
|
138
|
-
|
|
136
|
+
migrationAction(schema, 'unionField', 'create', {
|
|
139
137
|
displayName: 'Row',
|
|
140
138
|
apiId: 'row',
|
|
141
139
|
reverseField: {
|
|
@@ -147,7 +145,7 @@ const graphcommerce6to7 = async (schema) => {
|
|
|
147
145
|
},
|
|
148
146
|
parentApiId: 'DynamicRow',
|
|
149
147
|
}, 'DynamicRow', 'model');
|
|
150
|
-
|
|
148
|
+
migrationAction(schema, 'enumerableField', 'create', {
|
|
151
149
|
displayName: 'Placement',
|
|
152
150
|
apiId: 'placement',
|
|
153
151
|
parentApiId: 'DynamicRow',
|
|
@@ -155,7 +153,7 @@ const graphcommerce6to7 = async (schema) => {
|
|
|
155
153
|
description: 'Where will the row be placed relative to the target',
|
|
156
154
|
isRequired: true,
|
|
157
155
|
}, 'DynamicRow', 'model');
|
|
158
|
-
|
|
156
|
+
migrationAction(schema, 'unionField', 'create', {
|
|
159
157
|
displayName: 'Placement target',
|
|
160
158
|
apiId: 'target',
|
|
161
159
|
description: 'Optional: When the target is left blank it will place the Dynamic Row on the start or end.',
|
|
@@ -181,7 +179,7 @@ const graphcommerce6to7 = async (schema) => {
|
|
|
181
179
|
},
|
|
182
180
|
parentApiId: 'DynamicRow',
|
|
183
181
|
}, 'DynamicRow', 'model');
|
|
184
|
-
|
|
182
|
+
migrationAction(schema, 'componentUnionField', 'create', {
|
|
185
183
|
displayName: 'Conditions (OR)',
|
|
186
184
|
apiId: 'conditions',
|
|
187
185
|
parentApiId: 'DynamicRow',
|
|
@@ -190,19 +188,19 @@ const graphcommerce6to7 = async (schema) => {
|
|
|
190
188
|
isList: true,
|
|
191
189
|
}, 'DynamicRow', 'model');
|
|
192
190
|
// ? Row Column One
|
|
193
|
-
|
|
191
|
+
migrationAction(schema, 'enumerableField', 'create', {
|
|
194
192
|
displayName: 'Variant',
|
|
195
193
|
apiId: 'rowColumnOneVariant',
|
|
196
194
|
enumerationApiId: 'RowColumnOneVariants',
|
|
197
195
|
parentApiId: 'RowColumnOne',
|
|
198
196
|
}, 'RowColumnOne', 'model');
|
|
199
|
-
|
|
197
|
+
migrationAction(schema, 'componentUnionField', 'create', {
|
|
200
198
|
displayName: 'Conditions',
|
|
201
199
|
apiId: 'conditions',
|
|
202
200
|
parentApiId: 'ConditionOr',
|
|
203
201
|
componentApiIds: ['ConditionText', 'ConditionNumber'],
|
|
204
202
|
isList: true,
|
|
205
203
|
}, 'ConditionOr', 'component');
|
|
206
|
-
return
|
|
204
|
+
return client.run(true);
|
|
207
205
|
};
|
|
208
206
|
exports.graphcommerce6to7 = graphcommerce6to7;
|