From d75b965266fc3fa8e58086421dfea7c7e7ee2f86 Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Tue, 22 Jun 2021 18:08:02 +0200 Subject: [PATCH] feat(gatsby-plugin-mdx): swap sourceNodes to createSchemaCustomization (#32021) --- packages/gatsby-plugin-mdx/gatsby-node.js | 6 ++- ...odes.js => create-schema-customization.js} | 49 ++++++++++--------- 2 files changed, 30 insertions(+), 25 deletions(-) rename packages/gatsby-plugin-mdx/gatsby/{source-nodes.js => create-schema-customization.js} (96%) diff --git a/packages/gatsby-plugin-mdx/gatsby-node.js b/packages/gatsby-plugin-mdx/gatsby-node.js index 3cd212028f614..a5e0f5bb92389 100644 --- a/packages/gatsby-plugin-mdx/gatsby-node.js +++ b/packages/gatsby-plugin-mdx/gatsby-node.js @@ -12,7 +12,7 @@ const { /** * Create Mdx types and resolvers */ -exports.sourceNodes = require(`./gatsby/source-nodes`) +exports.createSchemaCustomization = require(`./gatsby/create-schema-customization`) /** * Check whether to create Mdx nodes from MDX files. @@ -124,6 +124,8 @@ exports.pluginOptionsSchema = function ({ Joi }) { ), root: Joi.string() .default(process.cwd()) - .description(`[deprecated] This is a legacy option that used to define root directory of the project. It was needed to generate a cache directory location. It currently has no effect.`) + .description( + `[deprecated] This is a legacy option that used to define root directory of the project. It was needed to generate a cache directory location. It currently has no effect.` + ), }) } diff --git a/packages/gatsby-plugin-mdx/gatsby/source-nodes.js b/packages/gatsby-plugin-mdx/gatsby/create-schema-customization.js similarity index 96% rename from packages/gatsby-plugin-mdx/gatsby/source-nodes.js rename to packages/gatsby-plugin-mdx/gatsby/create-schema-customization.js index f07aab4f9e640..fe28703437384 100644 --- a/packages/gatsby-plugin-mdx/gatsby/source-nodes.js +++ b/packages/gatsby-plugin-mdx/gatsby/create-schema-customization.js @@ -50,7 +50,7 @@ async function getCounts({ mdast }) { } } -module.exports = ( +module.exports = function createSchemaCustomization( { store, pathPrefix, @@ -63,32 +63,12 @@ module.exports = ( ...helpers }, pluginOptions -) => { +) { let mdxHTMLLoader const { createTypes } = actions const options = defaultOptions(pluginOptions) const headingsMdx = [`h1`, `h2`, `h3`, `h4`, `h5`, `h6`] - createTypes(` - type MdxFrontmatter { - title: String! - } - - type MdxHeadingMdx { - value: String - depth: Int - } - - enum HeadingsMdx { - ${headingsMdx} - } - - type MdxWordCount { - paragraphs: Int - sentences: Int - words: Int - } - `) /** * Support gatsby-remark parser plugins @@ -303,5 +283,28 @@ ${e}` }, }, }) - createTypes(MdxType) + + createTypes([ + ` + type MdxFrontmatter { + title: String! + } + + type MdxHeadingMdx { + value: String + depth: Int + } + + enum HeadingsMdx { + ${headingsMdx} + } + + type MdxWordCount { + paragraphs: Int + sentences: Int + words: Int + } +`, + MdxType, + ]) }