Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby-plugin-mdx): swap sourceNodes to createSchemaCustomization #32021

Merged
merged 1 commit into from Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
])
}