Registry / database / gatsby-source-mysql

gatsby-source-mysql

JSON →
library2.2.3jsnpmunverified

MySQL source plugin for Gatsby that allows pulling data from a MySQL database into Gatsby's GraphQL layer. Current stable version is 2.2.3. The plugin supports multiple queries, joins between tables (one-to-one and one-to-many), and remote image downloading for Gatsby image processing. It is specifically for Gatsby v2+ and requires gatsby-source-filesystem as a peer dependency. Compared to other database source plugins, it offers a straightforward configuration with SQL queries and automatic type generation.

npm install gatsby-source-mysql
INSTALL
IMPORT
SIG · GATSBY-SOURCE-MYSQ
G
gatsby-source-mysql
databasejavascriptv2.2.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GatsbyConfig
// In gatsby-config.js, use require or import
Plugin is configured in gatsby-config.js, not directly imported in source files.
gatsby-source-mysql
// gatsby-config.js { resolve: 'gatsby-source-mysql', options: { ... } }
// Incorrect: Trying to import plugin in components import gatsbySourceMysql from 'gatsby-source-mysql'
Plugin is used as a Gatsby plugin, not a runtime library.

Configure the plugin in gatsby-config.js with MySQL connection details and SQL queries to create Gatsby nodes.

// gatsby-config.js module.exports = { plugins: [ { resolve: 'gatsby-source-mysql', options: { connectionDetails: { host: process.env.MYSQL_HOST || 'localhost', user: process.env.MYSQL_USER || 'root', password: process.env.MYSQL_PASSWORD || '', database: process.env.MYSQL_DATABASE || 'test' }, queries: [ { statement: 'SELECT * FROM users', idFieldName: 'id', name: 'User' } ] } } ] };
Debug
Known issues
gotchaPeer dependency on gatsby-source-filesystem is required but not automatically installed.
fix
Ensure gatsby-source-filesystem is installed: npm install gatsby-source-filesystem
affects: >=1.0.0
gotchaSQL injection risk: The 'statement' field is passed directly to MySQL. Do not use user input to build queries.
fix
Use parameterized queries or stored procedures, but the plugin does not support them directly. Only use hardcoded or server-side validated queries.
affects: >=1.0.0
deprecatedVersion 2.x only supports Gatsby v2+. For Gatsby v3+, you may need to check compatibility or use an alternative.
fix
Upgrade gatsby to v2.x or consider using a different plugin for newer Gatsby versions.
affects: 2.0.0 - 2.2.3
Errors
Common errors & fixes
Cannot query field 'allMysqlName' on type 'Query'
The query name defined in options (e.g., 'User') does not match the GraphQL type.
fix
Ensure the options.queries[].name is set correctly and the plugin is properly configured in gatsby-config.js.
The plugin "gatsby-source-mysql" is missing a peer dependency "gatsby-source-filesystem".
gatsby-source-filesystem must be installed as a dependency.
fix
Run: npm install gatsby-source-filesystem
ConnectionError: connect ECONNREFUSED
MySQL server is not running or connection details are incorrect.
fix
Verify MySQL host, port, and credentials. Ensure the MySQL server is accessible.
Upgrade
Version history
2.2.3latest on npm
Audit
Dependencies
gatsbyrequiredCore dependency; plugin is designed to work with Gatsby framework.
gatsby-source-filesystemrequiredRequired for image processing and node creation.
Agent activity
4 hits · last 30 days
node
4
Resources
gatsby-source-mysql — npm install gatsby-source-mysql · libregistry