v1
Source Handlers
MySQL

MySQL

This handler allows you to generate GraphQL schema from an existing MySQL database.

How to use?

To get started, install the handler library:

npm i @omnigraph/mysql

Now, you can use it directly in your Mesh config file:

mesh.config.ts
import { defineConfig } from '@graphql-mesh/compose-cli'
import { loadMySQLSubgraph } from '@omnigraph/mysql'
 
export const composeConfig = defineConfig({
  subgraphs: [
    {
      sourceHandler: loadMySQLSubgraph('Employees', {
        // You can use environment variables like
        // host: "{env.MYSQL_HOST}"
        // port: "{env.MYSQL_PORT}"
        // user: "{env.MYSQL_USER}"
        // password: "{env.MYSQL_PASSWORD}"
        // database: "{env.MYSQL_DATABASE}"
        host: 'localhost',
        port: 3306,
        user: 'root',
        password: 'passwd',
        database: 'employees'
      })
    }
  ]
})

How does where work?

Every CRUD operation has where field in its input, so you can see all the columns of a table. where works like below;

{
  getProduct(
    where: {
      id: 5
      year: ">2010"
      price: "100..200"
      level: "<=3"
      sn: "*str?"
      label: "str"
      code: "(1,2,4,10,11)"
    }
  ) {
    id
    name
  }
}

This GraphQL operation will send the following query to your MySQL database;

SELECT id, name FROM product WHERE id = 5 AND year > '2010' AND (price BETWEEN '100' AND '200') AND level <= '3' AND sn LIKE '%str\_' AND label = 'str' AND code IN (1,2,4,10,11)