You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to specify schema using exports.createSchemaCustomization = ({ actions }, siteOptions) in my Gatsby Theme, but it's being ignored by the site that uses the theme. This is a known limitation which has seen some discussion (#15544, #16529).
My question: As of now, is there a workaround to do this?
I know we could move this to the site's gatsby-node.js, but that's unideal — as it creates unnecessary code duplication across sites, when it could just live in the theme — and I'm also having issues (#24427) accessing the config in the site.
Relevant information
My Gatsby theme allows my sites to specify Markdown content types with frontmatter fields, like so:
Ideally, I would've liked then liked to use this info to generate schema customisations in the theme's gatsby-node.js, like below. This code currently runs, but it's being ignored, i.e. the schema customisations aren't being applied. In the build output on the site using the theme, I get:
warn Plugin 'MY_THEME_SAMPLE' tried to define the GraphQL type 'MarkdownRemark', which has already been defined by the plugin
// Explicitly specify GraphQL schema for better performance and reliabilityexports.createSchemaCustomization=({ actions },siteOptions)=>{const{ createTypes }=actions;const{ contentTypes }=createConfig(siteOptions);constcontentTypeDefinitions={};for(leti=0;i<contentTypes.length;i+=1){for(letj=0;j<contentTypes[i].frontmatterFields.length;j+=1){if(contentTypeDefinitions[contentTypes[i].frontmatterFields[j].name]===undefined){// Checks for duplicate field declarations; only the first will be declaredcontentTypeDefinitions[contentTypes[i].frontmatterFields[j].name]=contentTypes[i].frontmatterFields[j].type;}}}constfinalDefinitions=` type MarkdownRemark implements Node { fields: Fields frontmatter: Frontmatter } type Fields { slug: String collection: String } type Frontmatter {${Object.keys(contentTypeDefinitions).map((key)=>`${key}: ${contentTypeDefinitions[key]}`).join('\n')} }`;createTypes(finalDefinitions);};
The text was updated successfully, but these errors were encountered:
Summary
I'm trying to specify schema using
exports.createSchemaCustomization = ({ actions }, siteOptions)
in my Gatsby Theme, but it's being ignored by the site that uses the theme. This is a known limitation which has seen some discussion (#15544, #16529).My question: As of now, is there a workaround to do this?
I know we could move this to the site's
gatsby-node.js
, but that's unideal — as it creates unnecessary code duplication across sites, when it could just live in the theme — and I'm also having issues (#24427) accessing the config in the site.Relevant information
My Gatsby theme allows my sites to specify Markdown content types with frontmatter fields, like so:
gatsby-config.js
:Ideally, I would've liked then liked to use this info to generate schema customisations in the theme's
gatsby-node.js
, like below. This code currently runs, but it's being ignored, i.e. the schema customisations aren't being applied. In the build output on the site using the theme, I get:warn Plugin 'MY_THEME_SAMPLE' tried to define the GraphQL type 'MarkdownRemark', which has already been defined by the plugin
The text was updated successfully, but these errors were encountered: