@graphql-mesh/mysql 1.0.0-alpha-20220804093904-8e2e41f7f → 1.0.0-alpha-20230420220344-25b6b92bf

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.
@@ -1,19 +1,17 @@
1
- 'use strict';
2
-
3
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
-
5
- const graphqlCompose = require('graphql-compose');
6
- const mysql = require('mysql');
7
- const mysqlUtilities = require('mysql-utilities');
8
- const graphqlFields = _interopDefault(require('graphql-fields'));
9
- const graphqlScalars = require('graphql-scalars');
10
- const graphql = require('graphql');
11
- const utils = require('@graphql-mesh/utils');
12
- const stringInterpolation = require('@graphql-mesh/string-interpolation');
13
- const store = require('@graphql-mesh/store');
14
- const delegate = require('@graphql-tools/delegate');
15
- const crossHelpers = require('@graphql-mesh/cross-helpers');
16
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const graphql_1 = require("graphql");
5
+ const graphql_compose_1 = require("graphql-compose");
6
+ const graphql_fields_1 = tslib_1.__importDefault(require("graphql-fields"));
7
+ const graphql_scalars_1 = require("graphql-scalars");
8
+ const mysql_1 = require("mysql");
9
+ const mysql_utilities_1 = require("mysql-utilities");
10
+ const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
11
+ const store_1 = require("@graphql-mesh/store");
12
+ const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
13
+ const utils_1 = require("@graphql-mesh/utils");
14
+ const delegate_1 = require("@graphql-tools/delegate");
17
15
  const SCALARS = {
18
16
  bigint: 'BigInt',
19
17
  'bigint unsigned': 'BigInt',
@@ -60,18 +58,18 @@ const SCALARS = {
60
58
  year: 'Int',
61
59
  };
62
60
  async function getPromisifiedConnection(pool) {
63
- const getConnection = crossHelpers.util.promisify(pool.getConnection.bind(pool));
61
+ const getConnection = cross_helpers_1.util.promisify(pool.getConnection.bind(pool));
64
62
  const connection = await getConnection();
65
- const getDatabaseTables = crossHelpers.util.promisify(connection.databaseTables.bind(connection));
66
- const getTableFields = crossHelpers.util.promisify(connection.fields.bind(connection));
67
- const getTableForeigns = crossHelpers.util.promisify(connection.foreign.bind(connection));
68
- const getTablePrimaryKeyMetadata = crossHelpers.util.promisify(connection.primary.bind(connection));
69
- const selectLimit = crossHelpers.util.promisify(connection.selectLimit.bind(connection));
70
- const select = crossHelpers.util.promisify(connection.select.bind(connection));
71
- const insert = crossHelpers.util.promisify(connection.insert.bind(connection));
72
- const update = crossHelpers.util.promisify(connection.update.bind(connection));
73
- const deleteRow = crossHelpers.util.promisify(connection.delete.bind(connection));
74
- const count = crossHelpers.util.promisify(connection.count.bind(connection));
63
+ const getDatabaseTables = cross_helpers_1.util.promisify(connection.databaseTables.bind(connection));
64
+ const getTableFields = cross_helpers_1.util.promisify(connection.fields.bind(connection));
65
+ const getTableForeigns = cross_helpers_1.util.promisify(connection.foreign.bind(connection));
66
+ const getTablePrimaryKeyMetadata = cross_helpers_1.util.promisify(connection.primary.bind(connection));
67
+ const selectLimit = cross_helpers_1.util.promisify(connection.selectLimit.bind(connection));
68
+ const select = cross_helpers_1.util.promisify(connection.select.bind(connection));
69
+ const insert = cross_helpers_1.util.promisify(connection.insert.bind(connection));
70
+ const update = cross_helpers_1.util.promisify(connection.update.bind(connection));
71
+ const deleteRow = cross_helpers_1.util.promisify(connection.delete.bind(connection));
72
+ const count = cross_helpers_1.util.promisify(connection.count.bind(connection));
75
73
  const release = connection.release.bind(connection);
76
74
  return {
77
75
  connection,
@@ -89,7 +87,7 @@ async function getPromisifiedConnection(pool) {
89
87
  };
90
88
  }
91
89
  function getFieldsFromResolveInfo(info) {
92
- const fieldMap = graphqlFields(info);
90
+ const fieldMap = (0, graphql_fields_1.default)(info);
93
91
  return Object.keys(fieldMap).filter(fieldName => Object.keys(fieldMap[fieldName]).length === 0 && fieldName !== '__typename');
94
92
  }
95
93
  class MySQLHandler {
@@ -107,12 +105,16 @@ class MySQLHandler {
107
105
  if (methodName === 'release') {
108
106
  return () => promisifiedConnection$ === null || promisifiedConnection$ === void 0 ? void 0 : promisifiedConnection$.then(promisifiedConnection => promisifiedConnection === null || promisifiedConnection === void 0 ? void 0 : promisifiedConnection.connection.release());
109
107
  }
108
+ if (methodName === 'connection') {
109
+ return promisifiedConnection$ === null || promisifiedConnection$ === void 0 ? void 0 : promisifiedConnection$.then(promisifiedConnection => promisifiedConnection === null || promisifiedConnection === void 0 ? void 0 : promisifiedConnection.connection);
110
+ }
110
111
  return async (...args) => {
111
112
  const cacheKey = [methodName, ...args].join('_');
112
- const cacheProxy = this.store.proxy(cacheKey, store.PredefinedProxyOptions.JsonWithoutValidation);
113
+ const cacheProxy = this.store.proxy(cacheKey, store_1.PredefinedProxyOptions.JsonWithoutValidation);
113
114
  return cacheProxy.getWithSet(async () => {
114
115
  promisifiedConnection$ = promisifiedConnection$ || getPromisifiedConnection(pool);
115
116
  const promisifiedConnection = await promisifiedConnection$;
117
+ // @ts-expect-error - Weird error
116
118
  return promisifiedConnection[methodName](...args);
117
119
  });
118
120
  };
@@ -121,41 +123,43 @@ class MySQLHandler {
121
123
  }
122
124
  async getMeshSource() {
123
125
  const { pool: configPool } = this.config;
124
- const schemaComposer = new graphqlCompose.SchemaComposer();
126
+ const schemaComposer = new graphql_compose_1.SchemaComposer();
125
127
  const pool = configPool
126
128
  ? typeof configPool === 'string'
127
- ? await utils.loadFromModuleExportExpression(configPool, {
129
+ ? await (0, utils_1.loadFromModuleExportExpression)(configPool, {
128
130
  cwd: this.baseDir,
129
131
  defaultExportName: 'default',
130
132
  importFn: this.importFn,
131
133
  })
132
134
  : configPool
133
- : mysql.createPool({
135
+ : (0, mysql_1.createPool)({
134
136
  supportBigNumbers: true,
135
137
  bigNumberStrings: true,
136
- dateStrings: true,
137
- trace: !!crossHelpers.process.env.DEBUG,
138
- debug: !!crossHelpers.process.env.DEBUG,
139
- host: this.config.host && stringInterpolation.stringInterpolator.parse(this.config.host, { env: crossHelpers.process.env }),
140
- port: this.config.port && parseInt(stringInterpolation.stringInterpolator.parse(this.config.port.toString(), { env: crossHelpers.process.env })),
141
- user: this.config.user && stringInterpolation.stringInterpolator.parse(this.config.user, { env: crossHelpers.process.env }),
142
- password: this.config.password && stringInterpolation.stringInterpolator.parse(this.config.password, { env: crossHelpers.process.env }),
143
- database: this.config.database && stringInterpolation.stringInterpolator.parse(this.config.database, { env: crossHelpers.process.env }),
138
+ trace: !!cross_helpers_1.process.env.DEBUG,
139
+ debug: !!cross_helpers_1.process.env.DEBUG,
140
+ host: this.config.host && string_interpolation_1.stringInterpolator.parse(this.config.host, { env: cross_helpers_1.process.env }),
141
+ port: this.config.port &&
142
+ parseInt(string_interpolation_1.stringInterpolator.parse(this.config.port.toString(), { env: cross_helpers_1.process.env })),
143
+ user: this.config.user && string_interpolation_1.stringInterpolator.parse(this.config.user, { env: cross_helpers_1.process.env }),
144
+ password: this.config.password &&
145
+ string_interpolation_1.stringInterpolator.parse(this.config.password, { env: cross_helpers_1.process.env }),
146
+ database: this.config.database &&
147
+ string_interpolation_1.stringInterpolator.parse(this.config.database, { env: cross_helpers_1.process.env }),
144
148
  ...this.config,
145
149
  });
146
150
  pool.on('connection', connection => {
147
- mysqlUtilities.upgrade(connection);
148
- mysqlUtilities.introspection(connection);
151
+ (0, mysql_utilities_1.upgrade)(connection);
152
+ (0, mysql_utilities_1.introspection)(connection);
149
153
  });
150
154
  const introspectionConnection = this.getCachedIntrospectionConnection(pool);
151
- schemaComposer.add(graphqlScalars.GraphQLBigInt);
152
- schemaComposer.add(graphqlScalars.GraphQLJSON);
153
- schemaComposer.add(graphqlScalars.GraphQLDate);
154
- schemaComposer.add(graphqlScalars.GraphQLTime);
155
- schemaComposer.add(graphqlScalars.GraphQLDateTime);
156
- schemaComposer.add(graphqlScalars.GraphQLTimestamp);
157
- schemaComposer.add(graphqlScalars.GraphQLUnsignedInt);
158
- schemaComposer.add(graphqlScalars.GraphQLUnsignedFloat);
155
+ schemaComposer.add(graphql_scalars_1.GraphQLBigInt);
156
+ schemaComposer.add(graphql_scalars_1.GraphQLJSON);
157
+ schemaComposer.add(graphql_scalars_1.GraphQLDate);
158
+ schemaComposer.add(graphql_scalars_1.GraphQLTime);
159
+ schemaComposer.add(graphql_scalars_1.GraphQLDateTime);
160
+ schemaComposer.add(graphql_scalars_1.GraphQLTimestamp);
161
+ schemaComposer.add(graphql_scalars_1.GraphQLUnsignedInt);
162
+ schemaComposer.add(graphql_scalars_1.GraphQLUnsignedFloat);
159
163
  schemaComposer.createEnumTC({
160
164
  name: 'OrderBy',
161
165
  values: {
@@ -169,17 +173,18 @@ class MySQLHandler {
169
173
  });
170
174
  const tables = await introspectionConnection.getDatabaseTables(pool.config.connectionConfig.database);
171
175
  const tableNames = this.config.tables || Object.keys(tables);
176
+ const typeMergingOptions = {};
172
177
  await Promise.all(tableNames.map(async (tableName) => {
173
178
  var _a, _b;
174
179
  if (this.config.tables && !this.config.tables.includes(tableName)) {
175
180
  return;
176
181
  }
177
182
  const table = tables[tableName];
178
- const objectTypeName = utils.sanitizeNameForGraphQL(table.TABLE_NAME);
179
- const insertInputName = utils.sanitizeNameForGraphQL(table.TABLE_NAME + '_InsertInput');
180
- const updateInputName = utils.sanitizeNameForGraphQL(table.TABLE_NAME + '_UpdateInput');
181
- const whereInputName = utils.sanitizeNameForGraphQL(table.TABLE_NAME + '_WhereInput');
182
- const orderByInputName = utils.sanitizeNameForGraphQL(table.TABLE_NAME + '_OrderByInput');
183
+ const objectTypeName = (0, utils_1.sanitizeNameForGraphQL)(table.TABLE_NAME);
184
+ const insertInputName = (0, utils_1.sanitizeNameForGraphQL)(table.TABLE_NAME + '_InsertInput');
185
+ const updateInputName = (0, utils_1.sanitizeNameForGraphQL)(table.TABLE_NAME + '_UpdateInput');
186
+ const whereInputName = (0, utils_1.sanitizeNameForGraphQL)(table.TABLE_NAME + '_WhereInput');
187
+ const orderByInputName = (0, utils_1.sanitizeNameForGraphQL)(table.TABLE_NAME + '_OrderByInput');
183
188
  const tableTC = schemaComposer.createObjectTC({
184
189
  name: objectTypeName,
185
190
  description: table.TABLE_COMMENT || undefined,
@@ -212,7 +217,8 @@ class MySQLHandler {
212
217
  });
213
218
  const primaryKeys = new Set();
214
219
  const fields = await introspectionConnection.getTableFields(tableName);
215
- const fieldNames = ((_b = (_a = this.config.tableFields) === null || _a === void 0 ? void 0 : _a.find(({ table }) => table === tableName)) === null || _b === void 0 ? void 0 : _b.fields) || Object.keys(fields);
220
+ const fieldNames = ((_b = (_a = this.config.tableFields) === null || _a === void 0 ? void 0 : _a.find(({ table }) => table === tableName)) === null || _b === void 0 ? void 0 : _b.fields) ||
221
+ Object.keys(fields);
216
222
  await Promise.all(fieldNames.map(async (fieldName) => {
217
223
  const tableField = fields[fieldName];
218
224
  if (tableField.Key === 'PRI') {
@@ -225,11 +231,11 @@ class MySQLHandler {
225
231
  let type = SCALARS[realTypeName];
226
232
  if (realTypeName === 'enum' || realTypeName === 'set') {
227
233
  const enumValues = typeDetails.split(`'`).join('').split(',');
228
- const enumTypeName = utils.sanitizeNameForGraphQL(tableName + '_' + fieldName);
234
+ const enumTypeName = (0, utils_1.sanitizeNameForGraphQL)(tableName + '_' + fieldName);
229
235
  schemaComposer.createEnumTC({
230
236
  name: enumTypeName,
231
237
  values: enumValues.reduce((prev, curr) => {
232
- const enumKey = utils.sanitizeNameForGraphQL(curr);
238
+ const enumKey = (0, utils_1.sanitizeNameForGraphQL)(curr);
233
239
  return {
234
240
  ...prev,
235
241
  [enumKey]: {
@@ -288,9 +294,9 @@ class MySQLHandler {
288
294
  }
289
295
  const foreignTableName = tableForeign.REFERENCED_TABLE_NAME;
290
296
  const foreignColumnName = tableForeign.REFERENCED_COLUMN_NAME;
291
- const foreignObjectTypeName = utils.sanitizeNameForGraphQL(foreignTableName);
292
- const foreignWhereInputName = utils.sanitizeNameForGraphQL(foreignTableName + '_WhereInput');
293
- const foreignOrderByInputName = utils.sanitizeNameForGraphQL(foreignTableName + '_OrderByInput');
297
+ const foreignObjectTypeName = (0, utils_1.sanitizeNameForGraphQL)(foreignTableName);
298
+ const foreignWhereInputName = (0, utils_1.sanitizeNameForGraphQL)(foreignTableName + '_WhereInput');
299
+ const foreignOrderByInputName = (0, utils_1.sanitizeNameForGraphQL)(foreignTableName + '_OrderByInput');
294
300
  tableTC.addFields({
295
301
  [foreignTableName]: {
296
302
  type: '[' + foreignObjectTypeName + ']',
@@ -352,7 +358,7 @@ class MySQLHandler {
352
358
  [columnName]: root[foreignColumnName],
353
359
  ...args === null || args === void 0 ? void 0 : args.where,
354
360
  };
355
- const fieldMap = graphqlFields(info);
361
+ const fieldMap = (0, graphql_fields_1.default)(info);
356
362
  const fields = [];
357
363
  for (const fieldName in fieldMap) {
358
364
  if (fieldName !== '__typename') {
@@ -361,8 +367,9 @@ class MySQLHandler {
361
367
  fields.push(fieldName);
362
368
  }
363
369
  else {
364
- const tableForeign = schemaComposer.getOTC(objectTypeName).getField(fieldName)
365
- .extensions;
370
+ const tableForeign = schemaComposer
371
+ .getOTC(objectTypeName)
372
+ .getField(fieldName).extensions;
366
373
  fields.push(tableForeign.COLUMN_NAME);
367
374
  }
368
375
  }
@@ -379,6 +386,19 @@ class MySQLHandler {
379
386
  },
380
387
  });
381
388
  }));
389
+ typeMergingOptions[objectTypeName] = {
390
+ selectionSet: `{ ${[...primaryKeys].join(' ')} }`,
391
+ args: obj => {
392
+ const where = {};
393
+ for (const primaryKey of primaryKeys) {
394
+ where[primaryKey] = obj[primaryKey];
395
+ }
396
+ return {
397
+ where,
398
+ };
399
+ },
400
+ valuesFromResults: results => results[0],
401
+ };
382
402
  schemaComposer.Query.addFields({
383
403
  [tableName]: {
384
404
  type: '[' + objectTypeName + ']',
@@ -397,7 +417,7 @@ class MySQLHandler {
397
417
  },
398
418
  },
399
419
  resolve: (root, args, { mysqlConnection }, info) => {
400
- const fieldMap = graphqlFields(info);
420
+ const fieldMap = (0, graphql_fields_1.default)(info);
401
421
  const fields = [];
402
422
  for (const fieldName in fieldMap) {
403
423
  if (fieldName !== '__typename') {
@@ -478,19 +498,25 @@ class MySQLHandler {
478
498
  type: whereInputName,
479
499
  },
480
500
  },
481
- resolve: (root, args, { mysqlConnection }) => mysqlConnection.deleteRow(tableName, args.where).then(result => !!(result === null || result === void 0 ? void 0 : result.affectedRows)),
501
+ resolve: (root, args, { mysqlConnection }) => mysqlConnection
502
+ .deleteRow(tableName, args.where)
503
+ .then(result => !!(result === null || result === void 0 ? void 0 : result.affectedRows)),
482
504
  },
483
505
  });
484
506
  }));
485
507
  introspectionConnection.release();
486
508
  const id = this.pubsub.subscribe('destroy', () => {
487
- pool.end();
488
- this.pubsub.unsubscribe(id);
509
+ pool.end(err => {
510
+ if (err) {
511
+ console.error(err);
512
+ }
513
+ this.pubsub.unsubscribe(id);
514
+ });
489
515
  });
490
516
  // graphql-compose doesn't add @defer and @stream to the schema
491
- graphql.specifiedDirectives.forEach(directive => schemaComposer.addDirective(directive));
517
+ graphql_1.specifiedDirectives.forEach(directive => schemaComposer.addDirective(directive));
492
518
  const schema = schemaComposer.buildSchema();
493
- const executor = delegate.createDefaultExecutor(schema);
519
+ const executor = (0, delegate_1.createDefaultExecutor)(schema);
494
520
  return {
495
521
  schema,
496
522
  async executor(executionRequest) {
@@ -514,5 +540,4 @@ class MySQLHandler {
514
540
  };
515
541
  }
516
542
  }
517
-
518
- module.exports = MySQLHandler;
543
+ exports.default = MySQLHandler;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1,15 +1,14 @@
1
+ import { specifiedDirectives } from 'graphql';
1
2
  import { SchemaComposer } from 'graphql-compose';
2
- import { createPool } from 'mysql';
3
- import { upgrade, introspection } from 'mysql-utilities';
4
3
  import graphqlFields from 'graphql-fields';
5
- import { GraphQLBigInt, GraphQLJSON, GraphQLDate, GraphQLTime, GraphQLDateTime, GraphQLTimestamp, GraphQLUnsignedInt, GraphQLUnsignedFloat } from 'graphql-scalars';
6
- import { specifiedDirectives } from 'graphql';
7
- import { loadFromModuleExportExpression, sanitizeNameForGraphQL } from '@graphql-mesh/utils';
8
- import { stringInterpolator } from '@graphql-mesh/string-interpolation';
4
+ import { GraphQLBigInt, GraphQLDate, GraphQLDateTime, GraphQLJSON, GraphQLTime, GraphQLTimestamp, GraphQLUnsignedFloat, GraphQLUnsignedInt, } from 'graphql-scalars';
5
+ import { createPool } from 'mysql';
6
+ import { introspection, upgrade } from 'mysql-utilities';
7
+ import { process, util } from '@graphql-mesh/cross-helpers';
9
8
  import { PredefinedProxyOptions } from '@graphql-mesh/store';
9
+ import { stringInterpolator } from '@graphql-mesh/string-interpolation';
10
+ import { loadFromModuleExportExpression, sanitizeNameForGraphQL } from '@graphql-mesh/utils';
10
11
  import { createDefaultExecutor } from '@graphql-tools/delegate';
11
- import { process, util } from '@graphql-mesh/cross-helpers';
12
-
13
12
  const SCALARS = {
14
13
  bigint: 'BigInt',
15
14
  'bigint unsigned': 'BigInt',
@@ -88,7 +87,7 @@ function getFieldsFromResolveInfo(info) {
88
87
  const fieldMap = graphqlFields(info);
89
88
  return Object.keys(fieldMap).filter(fieldName => Object.keys(fieldMap[fieldName]).length === 0 && fieldName !== '__typename');
90
89
  }
91
- class MySQLHandler {
90
+ export default class MySQLHandler {
92
91
  constructor({ name, config, baseDir, pubsub, store, importFn, logger, }) {
93
92
  this.config = config;
94
93
  this.baseDir = baseDir;
@@ -103,12 +102,16 @@ class MySQLHandler {
103
102
  if (methodName === 'release') {
104
103
  return () => promisifiedConnection$ === null || promisifiedConnection$ === void 0 ? void 0 : promisifiedConnection$.then(promisifiedConnection => promisifiedConnection === null || promisifiedConnection === void 0 ? void 0 : promisifiedConnection.connection.release());
105
104
  }
105
+ if (methodName === 'connection') {
106
+ return promisifiedConnection$ === null || promisifiedConnection$ === void 0 ? void 0 : promisifiedConnection$.then(promisifiedConnection => promisifiedConnection === null || promisifiedConnection === void 0 ? void 0 : promisifiedConnection.connection);
107
+ }
106
108
  return async (...args) => {
107
109
  const cacheKey = [methodName, ...args].join('_');
108
110
  const cacheProxy = this.store.proxy(cacheKey, PredefinedProxyOptions.JsonWithoutValidation);
109
111
  return cacheProxy.getWithSet(async () => {
110
112
  promisifiedConnection$ = promisifiedConnection$ || getPromisifiedConnection(pool);
111
113
  const promisifiedConnection = await promisifiedConnection$;
114
+ // @ts-expect-error - Weird error
112
115
  return promisifiedConnection[methodName](...args);
113
116
  });
114
117
  };
@@ -129,14 +132,16 @@ class MySQLHandler {
129
132
  : createPool({
130
133
  supportBigNumbers: true,
131
134
  bigNumberStrings: true,
132
- dateStrings: true,
133
135
  trace: !!process.env.DEBUG,
134
136
  debug: !!process.env.DEBUG,
135
137
  host: this.config.host && stringInterpolator.parse(this.config.host, { env: process.env }),
136
- port: this.config.port && parseInt(stringInterpolator.parse(this.config.port.toString(), { env: process.env })),
138
+ port: this.config.port &&
139
+ parseInt(stringInterpolator.parse(this.config.port.toString(), { env: process.env })),
137
140
  user: this.config.user && stringInterpolator.parse(this.config.user, { env: process.env }),
138
- password: this.config.password && stringInterpolator.parse(this.config.password, { env: process.env }),
139
- database: this.config.database && stringInterpolator.parse(this.config.database, { env: process.env }),
141
+ password: this.config.password &&
142
+ stringInterpolator.parse(this.config.password, { env: process.env }),
143
+ database: this.config.database &&
144
+ stringInterpolator.parse(this.config.database, { env: process.env }),
140
145
  ...this.config,
141
146
  });
142
147
  pool.on('connection', connection => {
@@ -165,6 +170,7 @@ class MySQLHandler {
165
170
  });
166
171
  const tables = await introspectionConnection.getDatabaseTables(pool.config.connectionConfig.database);
167
172
  const tableNames = this.config.tables || Object.keys(tables);
173
+ const typeMergingOptions = {};
168
174
  await Promise.all(tableNames.map(async (tableName) => {
169
175
  var _a, _b;
170
176
  if (this.config.tables && !this.config.tables.includes(tableName)) {
@@ -208,7 +214,8 @@ class MySQLHandler {
208
214
  });
209
215
  const primaryKeys = new Set();
210
216
  const fields = await introspectionConnection.getTableFields(tableName);
211
- const fieldNames = ((_b = (_a = this.config.tableFields) === null || _a === void 0 ? void 0 : _a.find(({ table }) => table === tableName)) === null || _b === void 0 ? void 0 : _b.fields) || Object.keys(fields);
217
+ const fieldNames = ((_b = (_a = this.config.tableFields) === null || _a === void 0 ? void 0 : _a.find(({ table }) => table === tableName)) === null || _b === void 0 ? void 0 : _b.fields) ||
218
+ Object.keys(fields);
212
219
  await Promise.all(fieldNames.map(async (fieldName) => {
213
220
  const tableField = fields[fieldName];
214
221
  if (tableField.Key === 'PRI') {
@@ -357,8 +364,9 @@ class MySQLHandler {
357
364
  fields.push(fieldName);
358
365
  }
359
366
  else {
360
- const tableForeign = schemaComposer.getOTC(objectTypeName).getField(fieldName)
361
- .extensions;
367
+ const tableForeign = schemaComposer
368
+ .getOTC(objectTypeName)
369
+ .getField(fieldName).extensions;
362
370
  fields.push(tableForeign.COLUMN_NAME);
363
371
  }
364
372
  }
@@ -375,6 +383,19 @@ class MySQLHandler {
375
383
  },
376
384
  });
377
385
  }));
386
+ typeMergingOptions[objectTypeName] = {
387
+ selectionSet: `{ ${[...primaryKeys].join(' ')} }`,
388
+ args: obj => {
389
+ const where = {};
390
+ for (const primaryKey of primaryKeys) {
391
+ where[primaryKey] = obj[primaryKey];
392
+ }
393
+ return {
394
+ where,
395
+ };
396
+ },
397
+ valuesFromResults: results => results[0],
398
+ };
378
399
  schemaComposer.Query.addFields({
379
400
  [tableName]: {
380
401
  type: '[' + objectTypeName + ']',
@@ -474,14 +495,20 @@ class MySQLHandler {
474
495
  type: whereInputName,
475
496
  },
476
497
  },
477
- resolve: (root, args, { mysqlConnection }) => mysqlConnection.deleteRow(tableName, args.where).then(result => !!(result === null || result === void 0 ? void 0 : result.affectedRows)),
498
+ resolve: (root, args, { mysqlConnection }) => mysqlConnection
499
+ .deleteRow(tableName, args.where)
500
+ .then(result => !!(result === null || result === void 0 ? void 0 : result.affectedRows)),
478
501
  },
479
502
  });
480
503
  }));
481
504
  introspectionConnection.release();
482
505
  const id = this.pubsub.subscribe('destroy', () => {
483
- pool.end();
484
- this.pubsub.unsubscribe(id);
506
+ pool.end(err => {
507
+ if (err) {
508
+ console.error(err);
509
+ }
510
+ this.pubsub.unsubscribe(id);
511
+ });
485
512
  });
486
513
  // graphql-compose doesn't add @defer and @stream to the schema
487
514
  specifiedDirectives.forEach(directive => schemaComposer.addDirective(directive));
@@ -510,5 +537,3 @@ class MySQLHandler {
510
537
  };
511
538
  }
512
539
  }
513
-
514
- export default MySQLHandler;
@@ -0,0 +1 @@
1
+ "use strict";
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "@graphql-mesh/mysql",
3
- "version": "1.0.0-alpha-20220804093904-8e2e41f7f",
3
+ "version": "1.0.0-alpha-20230420220344-25b6b92bf",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@graphql-mesh/types": "0.79.0-alpha-20220804093904-8e2e41f7f",
7
- "@graphql-mesh/utils": "1.0.0-alpha-20220804093904-8e2e41f7f",
8
- "graphql": "*"
6
+ "@graphql-mesh/cross-helpers": "^0.3.4",
7
+ "@graphql-mesh/store": "1.0.0-alpha-20230420220344-25b6b92bf",
8
+ "@graphql-mesh/types": "1.0.0-alpha-20230420220344-25b6b92bf",
9
+ "@graphql-mesh/utils": "1.0.0-alpha-20230420220344-25b6b92bf",
10
+ "@graphql-tools/utils": "^9.2.1",
11
+ "graphql": "*",
12
+ "tslib": "^2.4.0"
9
13
  },
10
14
  "dependencies": {
11
- "@graphql-mesh/cross-helpers": "0.2.0",
12
- "@graphql-mesh/store": "1.0.0-alpha-20220804093904-8e2e41f7f",
13
- "@graphql-mesh/string-interpolation": "0.3.0",
14
- "@graphql-tools/delegate": "8.8.1",
15
- "@graphql-tools/utils": "8.9.0",
16
- "graphql-compose": "9.0.8",
15
+ "@graphql-mesh/string-interpolation": "0.4.4",
16
+ "@graphql-tools/delegate": "9.0.32",
17
+ "graphql-compose": "9.0.10",
17
18
  "graphql-fields": "2.0.3",
18
- "graphql-scalars": "1.17.0",
19
+ "graphql-scalars": "^1.20.4",
19
20
  "mysql": "2.18.1",
20
- "mysql-utilities": "1.1.4",
21
- "tslib": "^2.4.0"
21
+ "mysql-utilities": "1.1.4"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
@@ -26,21 +26,28 @@
26
26
  "directory": "packages/handlers/mysql"
27
27
  },
28
28
  "license": "MIT",
29
- "main": "index.js",
30
- "module": "index.mjs",
31
- "typings": "index.d.ts",
29
+ "main": "cjs/index.js",
30
+ "module": "esm/index.js",
31
+ "typings": "typings/index.d.ts",
32
32
  "typescript": {
33
- "definition": "index.d.ts"
33
+ "definition": "typings/index.d.ts"
34
34
  },
35
+ "type": "module",
35
36
  "exports": {
36
37
  ".": {
37
- "require": "./index.js",
38
- "import": "./index.mjs"
39
- },
40
- "./*": {
41
- "require": "./*.js",
42
- "import": "./*.mjs"
38
+ "require": {
39
+ "types": "./typings/index.d.cts",
40
+ "default": "./cjs/index.js"
41
+ },
42
+ "import": {
43
+ "types": "./typings/index.d.ts",
44
+ "default": "./esm/index.js"
45
+ },
46
+ "default": {
47
+ "types": "./typings/index.d.ts",
48
+ "default": "./esm/index.js"
49
+ }
43
50
  },
44
51
  "./package.json": "./package.json"
45
52
  }
46
- }
53
+ }
@@ -0,0 +1,11 @@
1
+ import { MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
2
+ export default class MySQLHandler implements MeshHandler {
3
+ private config;
4
+ private baseDir;
5
+ private pubsub;
6
+ private store;
7
+ private importFn;
8
+ constructor({ name, config, baseDir, pubsub, store, importFn, logger, }: MeshHandlerOptions<YamlConfig.MySQLHandler>);
9
+ private getCachedIntrospectionConnection;
10
+ getMeshSource(): Promise<MeshSource>;
11
+ }
@@ -1,11 +1,11 @@
1
- import { GetMeshSourceOptions, MeshHandler, MeshSource, YamlConfig } from '@graphql-mesh/types';
1
+ import { MeshHandler, MeshHandlerOptions, MeshSource, YamlConfig } from '@graphql-mesh/types';
2
2
  export default class MySQLHandler implements MeshHandler {
3
3
  private config;
4
4
  private baseDir;
5
5
  private pubsub;
6
6
  private store;
7
7
  private importFn;
8
- constructor({ name, config, baseDir, pubsub, store, importFn, logger, }: GetMeshSourceOptions<YamlConfig.MySQLHandler>);
8
+ constructor({ name, config, baseDir, pubsub, store, importFn, logger, }: MeshHandlerOptions<YamlConfig.MySQLHandler>);
9
9
  private getCachedIntrospectionConnection;
10
10
  getMeshSource(): Promise<MeshSource>;
11
11
  }
@@ -0,0 +1,8 @@
1
+ declare module 'util' {
2
+ function promisify<T>(f: (cb: (err: any, res: T) => void) => void, thisContext?: any): () => Promise<T>;
3
+ function promisify<A, T>(f: (arg: A, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A) => Promise<T>;
4
+ function promisify<A, A2, T>(f: (arg: A, arg2: A2, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A, arg2: A2) => Promise<T>;
5
+ function promisify<A, A2, A3, T>(f: (arg: A, arg2: A2, arg3: A3, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A, arg2: A2, arg3: A3) => Promise<T>;
6
+ function promisify<A, A2, A3, A4, T>(f: (arg: A, arg2: A2, arg3: A3, arg4: A4, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A, arg2: A2, arg3: A3, arg4: A4) => Promise<T>;
7
+ function promisify<A, A2, A3, A4, A5, T>(f: (arg: A, arg2: A2, arg3: A3, arg4: A4, arg5: A5, cb: (err: any, res: T) => void) => void, thisContext?: any): (arg: A, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Promise<T>;
8
+ }
File without changes