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(mysql): add an ability to use existing Pool instance #1158

Merged
merged 2 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/silent-wasps-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-mesh/mysql': minor
'@graphql-mesh/types': minor
---

feat(mysql): add an ability to use existing Pool instance
1 change: 1 addition & 0 deletions packages/handlers/mysql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@graphql-mesh/types": "0.17.1",
"@graphql-mesh/utils": "0.6.0",
"graphql-compose": "7.22.1",
"graphql-fields": "2.0.3",
"mysql": "2.18.1",
Expand Down
7 changes: 6 additions & 1 deletion packages/handlers/mysql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
GraphQLTime,
} from 'graphql-scalars';
import { execute } from 'graphql';
import { loadFromModuleExportExpression } from '@graphql-mesh/utils';

const SCALARS = {
bigint: 'BigInt',
Expand Down Expand Up @@ -110,7 +111,11 @@ export default class MySQLHandler implements MeshHandler {

async getMeshSource(): Promise<MeshSource> {
const schemaComposer = new SchemaComposer<MysqlContext>();
const pool = createPool(this.config);
const pool: Pool = this.config.pool
? typeof this.config.pool === 'string'
? await loadFromModuleExportExpression(this.config.pool)
: this.config.pool
: createPool(this.config);
pool.on('connection', connection => {
upgrade(connection);
introspection(connection);
Expand Down
13 changes: 9 additions & 4 deletions packages/handlers/mysql/yaml-config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ extend type Handler {
}

type MySQLHandler @md {
host: String!
port: Int!
user: String!
host: String
port: Int
user: String
password: String
database: String!
database: String
"""
Use existing `Pool` instance
Format: modulePath#exportName
"""
pool: Any
}
15 changes: 13 additions & 2 deletions packages/types/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1174,9 +1174,20 @@
},
"database": {
"type": "string"
},
"pool": {
"anyOf": [
{
"type": "object",
"additionalProperties": true
},
{
"type": "string"
}
],
"description": "Use existing `Pool` instance\nFormat: modulePath#exportName"
}
},
"required": ["host", "port", "user", "database"]
}
},
"Neo4jHandler": {
"additionalProperties": false,
Expand Down
13 changes: 9 additions & 4 deletions packages/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,16 @@ export interface TypeConverterResolversOpts1 {
pagination?: boolean | PaginationResolverOpts;
}
export interface MySQLHandler {
host: string;
port: number;
user: string;
host?: string;
port?: number;
user?: string;
password?: string;
database: string;
database?: string;
/**
* Use existing `Pool` instance
* Format: modulePath#exportName
*/
pool?: any;
}
/**
* Handler for Neo4j
Expand Down