Defines comprehensive GraphQL type definitions for MarkdownRemark and related types, enabling rich querying capabilities for markdown data.
Main function that creates GraphQL type definitions and enables sub-plugin schema customization.
/**
* Creates GraphQL schema customizations for MarkdownRemark
* @param nodeApiArgs - Gatsby node API arguments
* @param nodeApiArgs.actions - Gatsby actions including createTypes
* @param pluginOptions - Plugin configuration options
* @param pluginOptions.plugins - Array of sub-plugins that may customize schema
*/
function createSchemaCustomization(nodeApiArgs, pluginOptions = {}): void;Usage Example:
This function is automatically called by Gatsby during schema building. It creates all the necessary GraphQL types and allows sub-plugins to customize the schema.
Complete GraphQL schema definitions exported by the plugin:
/**
* GraphQL Schema Definition Language (SDL) string containing all type definitions
*/
const typeDefs: string;The typeDefs constant contains the following GraphQL types:
Represents extracted heading information from markdown content.
type MarkdownHeading {
"""Heading ID extracted from data attributes or null if none"""
id: String
"""Text content of the heading"""
value: String
"""Heading depth level (1-6)"""
depth: Int
}Usage in Queries:
{
markdownRemark {
headings {
id
value
depth
}
}
}Enumeration of valid heading levels for filtering headings by depth.
enum MarkdownHeadingLevels {
h1
h2
h3
h4
h5
h6
}Usage in Queries:
{
markdownRemark {
headings(depth: h2) {
value
}
}
}Enumeration of supported excerpt output formats.
enum MarkdownExcerptFormats {
"""Plain text format (default)"""
PLAIN
"""HTML format with markup preserved"""
HTML
"""Markdown format with original markdown syntax"""
MARKDOWN
}Usage in Queries:
{
markdownRemark {
excerpt(format: HTML, pruneLength: 200)
}
}Represents word, sentence, and paragraph counts for markdown content.
type MarkdownWordCount {
"""Number of paragraphs in the content"""
paragraphs: Int
"""Number of sentences in the content"""
sentences: Int
"""Number of words in the content"""
words: Int
}Usage in Queries:
{
markdownRemark {
wordCount {
words
paragraphs
sentences
}
}
}Main type representing a transformed markdown file with rich computed fields.
type MarkdownRemark implements Node @infer @childOf(mimeTypes: ["text/markdown", "text/x-markdown"]) {
"""Unique node identifier"""
id: ID!
# Additional fields are added by setFieldsOnGraphQLNodeType
# See field-extensions.md for complete field definitions
}Key Directives:
@infer: Enables automatic type inference for frontmatter fields@childOf: Specifies parent-child relationship with File nodes of markdown media typesThe plugin enables gatsby-remark-* sub-plugins to customize the GraphQL schema:
/**
* Sub-plugin schema customization integration
* Each sub-plugin can export a createSchemaCustomization function
*/
plugins.forEach(plugin => {
const resolvedPlugin = plugin.module;
if (typeof resolvedPlugin.createSchemaCustomization === `function`) {
resolvedPlugin.createSchemaCustomization(
nodeApiArgs,
plugin.pluginOptions
);
}
});Sub-Plugin Implementation Example:
// gatsby-remark-custom-plugin/index.js
exports.createSchemaCustomization = ({ actions }, pluginOptions) => {
const { createTypes } = actions;
const typeDefs = `
type MarkdownRemark implements Node {
customField: String
}
`;
createTypes(typeDefs);
};This system allows the extensive gatsby-remark-* ecosystem to extend the MarkdownRemark type with additional fields and functionality while maintaining type safety and GraphQL schema consistency.