-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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: Allow themes to modify GraphQL types #16928
feat: Allow themes to modify GraphQL types #16928
Conversation
apparently node 11 (or v8 really) has changed the sort implementation, which is why this doesn't work anymore: gatsby/packages/gatsby/src/schema/index.js Lines 42 to 44 in c2fc3ee
|
packages/gatsby/src/schema/schema.js
Outdated
plugin.name === `default-site-plugin` || | ||
plugin.name === typeOwner | ||
(plugin.name.startsWith(`gatsby-theme-`) && | ||
!typeOwner.startsWith(`gatsby-theme-`)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wonder that does the name of a theme have to start with "gatsby-theme" ? If so, I think that's a little unreasonable. My theme plugin's name is antdsite
, not starts with "gatsby-theme". I think we should judge theme in another way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the gatsby-theme-
naming is a requirement since #16620, so we can rely on that. it's not totally optimal since i don't think it is actually enforced anywhere, otoh the only thing you'll lose (currently) when naming your theme differently is the ability to modify types owned by plugins. i'm open to other proposals, please post them in #16529.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol All right, since you haved discussed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, looks like my assumption was wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks 👍 I added a suggestion to fix sorting.
I do have a question about the themes spec. Don't we want themes to override/use other themes and maybe also augment the graphql types of those child themes?
cc @gatsbyjs/themes-core
We have this use case, currently we work around it via |
Sweet! Good workaround 👍. My comment about parent/child augmentation isn't blocking to get this PR merged so most people will already be happy |
#16529 did not really get lots of responses so i think this needs more discussion wrt to themes modifying types owned by other themes. this PR is a conservative start (following @KyleAMathews comment on slack) |
packages/gatsby/src/schema/schema.js
Outdated
plugin.name === `default-site-plugin` || | ||
plugin.name === typeOwner | ||
(plugin.name.startsWith(`gatsby-theme-`) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a heavy handed suggestion but not a requirement, as detailed in #16529 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this code would need to be modified to work for scoped packages like @namespace/gatsby-theme-thing
as well
Could you add some tests for non vs scoped packages? |
Sure, but let's first decide if we can actually rely on the naming convention? |
@stefanprobst I feel that we should probably remove restriction on modifying types by other plugins. I'm not sure there is any other solution, we don't want a "theme-class" and "non-theme-class" plugins. |
Perhaps we could do what we do for nodes? E.g. reserve a "fields" key on every type that other plugins can add additional fields to. |
@KyleAMathews What I'd like to be possible is to override some types, instead of extending them. |
I'm not really clear why that is? To me it seems that the issue of "who is allowed to modify which types" is exactly a case where having some way to differentiate between themes and other-plugins would make sense (even if only by naming convention). Not sure I like dropping type ownership just to preserve the theme/plugin symmetry. |
What we have to prevent is scenarios where s site is working and someone installs a plugin (or theme) and the site stops working. This is incredibly confusing for everyone. Allowing plugins or themes to override types leads to exactly that sort of problem. |
ok, I'm going to close this as there doesn't seem to be consensus wrt to type modifications. if I understand correctly, @freiksenet's position is to remove restrictions for type modifications and allow them for all plugins, while @KyleAMathews's position is to not let plugins modify types at all. let's clarify this in #16529 |
They don’t appear to be working even though themes are allowed to customise schemas. Reference: - gatsbyjs/gatsby#26864 - https://github.com/gatsbyjs/gatsby/issues/15544\ - gatsbyjs/gatsby#16928
* chore: bump gatsby, TS & React dependencies * Remove custom schema types They don’t appear to be working even though themes are allowed to customise schemas. Reference: - gatsbyjs/gatsby#26864 - https://github.com/gatsbyjs/gatsby/issues/15544\ - gatsbyjs/gatsby#16928 * Update peer deps for Gatsby
Currently, a GraphQL type can only be modified by the plugin which created that type, or by a user's
gatsby-node
. This excludes a theme'sgatsby-node
.This PR allows a theme's
gatsby-node
to modify types. A top-levelgatsby-node
always takes precedence. If a type has already been modified by another theme, modification is not allowed.Fixes #16529
Fixes #15544