@graphql-mesh/mysql 0.95.2 → 0.95.3-alpha-20230901120336-ba096d594
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/cjs/index.js +13 -6
- package/esm/index.js +13 -6
- package/package.json +1 -1
package/cjs/index.js
CHANGED
|
@@ -71,6 +71,7 @@ async function getPromisifiedConnection(pool) {
|
|
|
71
71
|
const deleteRow = cross_helpers_1.util.promisify(connection.delete.bind(connection));
|
|
72
72
|
const count = cross_helpers_1.util.promisify(connection.count.bind(connection));
|
|
73
73
|
const release = connection.release.bind(connection);
|
|
74
|
+
const queryKeyValue = cross_helpers_1.util.promisify(connection.queryKeyValue.bind(connection));
|
|
74
75
|
return {
|
|
75
76
|
connection,
|
|
76
77
|
release,
|
|
@@ -84,6 +85,7 @@ async function getPromisifiedConnection(pool) {
|
|
|
84
85
|
update,
|
|
85
86
|
deleteRow,
|
|
86
87
|
count,
|
|
88
|
+
queryKeyValue,
|
|
87
89
|
};
|
|
88
90
|
}
|
|
89
91
|
function getFieldsFromResolveInfo(info) {
|
|
@@ -184,6 +186,7 @@ class MySQLHandler {
|
|
|
184
186
|
});
|
|
185
187
|
const tables = await introspectionConnection.getDatabaseTables(pool.config.connectionConfig.database);
|
|
186
188
|
const tableNames = this.config.tables || Object.keys(tables);
|
|
189
|
+
const autoIncrementedColumns = await getAutoIncrementFields(introspectionConnection);
|
|
187
190
|
const typeMergingOptions = {};
|
|
188
191
|
await Promise.all(tableNames.map(async (tableName) => {
|
|
189
192
|
if (this.config.tables && !this.config.tables.includes(tableName)) {
|
|
@@ -260,24 +263,25 @@ class MySQLHandler {
|
|
|
260
263
|
console.warn(`${realTypeName} couldn't be mapped to a type. It will be mapped to JSON as a fallback.`);
|
|
261
264
|
type = 'JSON';
|
|
262
265
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
+
const isNullable = tableField.Null.toLowerCase() === 'yes';
|
|
267
|
+
const isRequired = !isNullable &&
|
|
268
|
+
tableField.Default === null &&
|
|
269
|
+
autoIncrementedColumns[tableName] !== fieldName;
|
|
266
270
|
tableTC.addFields({
|
|
267
271
|
[fieldName]: {
|
|
268
|
-
type,
|
|
272
|
+
type: isNullable ? type : type + '!',
|
|
269
273
|
description: tableField.Comment || undefined,
|
|
270
274
|
},
|
|
271
275
|
});
|
|
272
276
|
tableInsertIC.addFields({
|
|
273
277
|
[fieldName]: {
|
|
274
|
-
type,
|
|
278
|
+
type: isRequired ? type + '!' : type,
|
|
275
279
|
description: tableField.Comment || undefined,
|
|
276
280
|
},
|
|
277
281
|
});
|
|
278
282
|
tableUpdateIC.addFields({
|
|
279
283
|
[fieldName]: {
|
|
280
|
-
type
|
|
284
|
+
type,
|
|
281
285
|
description: tableField.Comment || undefined,
|
|
282
286
|
},
|
|
283
287
|
});
|
|
@@ -551,3 +555,6 @@ class MySQLHandler {
|
|
|
551
555
|
}
|
|
552
556
|
}
|
|
553
557
|
exports.default = MySQLHandler;
|
|
558
|
+
async function getAutoIncrementFields(connection) {
|
|
559
|
+
return connection.queryKeyValue('SELECT TABLE_NAME, COLUMN_NAME FROM information_schema.columns WHERE EXTRA LIKE "%auto_increment%"', []);
|
|
560
|
+
}
|
package/esm/index.js
CHANGED
|
@@ -68,6 +68,7 @@ async function getPromisifiedConnection(pool) {
|
|
|
68
68
|
const deleteRow = util.promisify(connection.delete.bind(connection));
|
|
69
69
|
const count = util.promisify(connection.count.bind(connection));
|
|
70
70
|
const release = connection.release.bind(connection);
|
|
71
|
+
const queryKeyValue = util.promisify(connection.queryKeyValue.bind(connection));
|
|
71
72
|
return {
|
|
72
73
|
connection,
|
|
73
74
|
release,
|
|
@@ -81,6 +82,7 @@ async function getPromisifiedConnection(pool) {
|
|
|
81
82
|
update,
|
|
82
83
|
deleteRow,
|
|
83
84
|
count,
|
|
85
|
+
queryKeyValue,
|
|
84
86
|
};
|
|
85
87
|
}
|
|
86
88
|
function getFieldsFromResolveInfo(info) {
|
|
@@ -181,6 +183,7 @@ export default class MySQLHandler {
|
|
|
181
183
|
});
|
|
182
184
|
const tables = await introspectionConnection.getDatabaseTables(pool.config.connectionConfig.database);
|
|
183
185
|
const tableNames = this.config.tables || Object.keys(tables);
|
|
186
|
+
const autoIncrementedColumns = await getAutoIncrementFields(introspectionConnection);
|
|
184
187
|
const typeMergingOptions = {};
|
|
185
188
|
await Promise.all(tableNames.map(async (tableName) => {
|
|
186
189
|
if (this.config.tables && !this.config.tables.includes(tableName)) {
|
|
@@ -257,24 +260,25 @@ export default class MySQLHandler {
|
|
|
257
260
|
console.warn(`${realTypeName} couldn't be mapped to a type. It will be mapped to JSON as a fallback.`);
|
|
258
261
|
type = 'JSON';
|
|
259
262
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
+
const isNullable = tableField.Null.toLowerCase() === 'yes';
|
|
264
|
+
const isRequired = !isNullable &&
|
|
265
|
+
tableField.Default === null &&
|
|
266
|
+
autoIncrementedColumns[tableName] !== fieldName;
|
|
263
267
|
tableTC.addFields({
|
|
264
268
|
[fieldName]: {
|
|
265
|
-
type,
|
|
269
|
+
type: isNullable ? type : type + '!',
|
|
266
270
|
description: tableField.Comment || undefined,
|
|
267
271
|
},
|
|
268
272
|
});
|
|
269
273
|
tableInsertIC.addFields({
|
|
270
274
|
[fieldName]: {
|
|
271
|
-
type,
|
|
275
|
+
type: isRequired ? type + '!' : type,
|
|
272
276
|
description: tableField.Comment || undefined,
|
|
273
277
|
},
|
|
274
278
|
});
|
|
275
279
|
tableUpdateIC.addFields({
|
|
276
280
|
[fieldName]: {
|
|
277
|
-
type
|
|
281
|
+
type,
|
|
278
282
|
description: tableField.Comment || undefined,
|
|
279
283
|
},
|
|
280
284
|
});
|
|
@@ -547,3 +551,6 @@ export default class MySQLHandler {
|
|
|
547
551
|
};
|
|
548
552
|
}
|
|
549
553
|
}
|
|
554
|
+
async function getAutoIncrementFields(connection) {
|
|
555
|
+
return connection.queryKeyValue('SELECT TABLE_NAME, COLUMN_NAME FROM information_schema.columns WHERE EXTRA LIKE "%auto_increment%"', []);
|
|
556
|
+
}
|