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

refactor(theme): work around to ensure frontmatter fields are created in the GraphQL schema #99

Closed
wants to merge 1 commit into from

Conversation

emmenko
Copy link
Member

@emmenko emmenko commented Nov 26, 2019

Fixes #70

@vercel
Copy link

vercel bot commented Nov 26, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/commercetools/commercetools-docs-kit/mt4xiq0jr
🌍 Preview: https://commercetools-docs-kit-git-nm-frontmatter-graphql-types.commercetools.now.sh

@nkuehn
Copy link
Collaborator

nkuehn commented Nov 26, 2019

Hm, I'm a bit scared of this because it creates an actual page that we'll then have to explicitly handle in every other code that walks through pages or loops over mdx page nodes (RSS feed generators, sitemaps, release notes list etc. )

Here's the comment of one of the gatsby core maintainers concerning the topic: gatsbyjs/gatsby#5495 (comment)

He says that if you want to customize graphQL fields of other plugins, you should write a plugin that sets "fields" on the other plugin's node. Fields are intended to be added by other plugins and live in an own namespace on the graphQL node.

Another option would be to write a minimal mdx AST plugin that sets a default value on all "offical" frontmatter keys in the AST, that way the schema will always have it, too. Likely very few code but we'd have to dump or instpect the frontmatter AST to understand the data structure.

@emmenko
Copy link
Member Author

emmenko commented Nov 26, 2019

Yes this is not the ideal solution and it should be taken as a (temporary?) workaround. I wouldn't consider the index.mdx to be a problem to be honest, a website usually overrides this file.

We can also name it something like __FOR_INTERNAL_USE_ONLY_DO_NOT_USE_THIS_.mdx, as long as it's picked up by GraphQL.

@nkuehn
Copy link
Collaborator

nkuehn commented Nov 26, 2019

Not sure whether the problem is big enough to merge a workaround that's not much better than simply putting the necessary default values into each site's index.mdx now and and the site template too.

But src/content/index.mdx is definitely the best place since it will very likely be overridden.

@emmenko
Copy link
Member Author

emmenko commented Nov 27, 2019

Closing in favor of #92

@emmenko emmenko closed this Nov 27, 2019
@emmenko emmenko deleted the nm-frontmatter-graphql-types branch November 27, 2019 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible to declare all allowed mdx frontmatter as explicit schema ?
2 participants