Gridsome source plugin to load data directly from a MySQL database. Current stable version is 1.5.4. It allows specifying SQL queries to fetch data as content types, with support for image downloading/optimization (including comma-separated URLs), relations via foreign key naming conventions (`xxx_id`, `xxx_ids`), dynamic routes, and JSON parsing. Compared to using a CMS or other source plugins, it provides direct database access for custom queries, regex-based image filename cleanup, and sub-query support. Release cadence is irregular; updates occur based on community contributions.
npm install gridsome-source-mysqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Configures Gridsome to use the MySQL source plugin with a connection and a simple Post query.
Access the MySQL primary key as 'mysqlId' in your GraphQL queries, or alias the column in SQL (e.g., SELECT id AS original_id).
Rename your foreign key columns to match the pattern, e.g., 'author_id' for a relation to the 'Author' content type.
Provide an 'args' array with the same number of elements as '?' placeholders in your SQL string.
Upgrade to version 1.5.0 or later to use the 'regex' option.
Ensure image column values are absolute URLs or paths reachable from the build environment.
Install it explicitly: npm install mysql2
Ensure the 'args' option contains exactly the same number of values as '?' placeholders in your SQL string.
In GraphQL queries, access the MySQL primary key field as 'mysqlId' instead of 'id'.