Skip to content

Commit

Permalink
feat(gatsby-plugin-mdx): swap sourceNodes to createSchemaCustomization (
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Jun 22, 2021
1 parent 47cf675 commit d75b965
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
6 changes: 4 additions & 2 deletions packages/gatsby-plugin-mdx/gatsby-node.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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.`
),
})
}
Expand Up @@ -50,7 +50,7 @@ async function getCounts({ mdast }) {
}
}

module.exports = (
module.exports = function createSchemaCustomization(
{
store,
pathPrefix,
Expand All @@ -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
Expand Down Expand Up @@ -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,
])
}

0 comments on commit d75b965

Please sign in to comment.