-
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(gatsby-plugin-image): support multiple sources using gatsby-plugin-image #32544
feat(gatsby-plugin-image): support multiple sources using gatsby-plugin-image #32544
Conversation
Thanks for picking this one up! Hopefully there will be a fix soon because using Gatsby Image icm Prismic would be awesome. |
This would be a great fix for the issue of having two plugins that reference Gatsby Image (i.e. shopify source and prismic source). Those two specifically would be great together, seeing as Prismic's slices and repeater fields make it very powerful. |
@wardpeet Is there any ETA on this? :) |
a1e4581
to
316dcdf
Compare
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.
Tested and works like a charm. Thanks a bunch @angeloashmore
…in-image (#32544) Co-authored-by: Ward Peeters <[email protected]> (cherry picked from commit 3bf4f10)
…in-image (#32544) (#33436) Co-authored-by: Ward Peeters <[email protected]> (cherry picked from commit 3bf4f10) Co-authored-by: Angelo Ashmore <[email protected]> Co-authored-by: Vladimir Razuvaev <[email protected]>
Hello all! I have an error whilst trying to upgrade to Gatsby V4, and the latest Shopify and Wordpress plugins, I think both of them use Gatsby Image.
Is this related to this PR? Perhaps I have to "register the shared types?" as per:
Edit: Yeah I had to install I'm not sure where would've been best to document this. Probably in upgrade guides for the plugins were causing these collisions. Slightly painful couple of hours. Could the error above be changed to include "please install gatsby-plugin-image"? |
…in-image (gatsbyjs#32544) Co-authored-by: Ward Peeters <[email protected]>
Description
This PR allows Gatsby apps to use more than one source that uses gatsby-plugin-image.
For example, users can use
gatsby-source-prismic
andgatsby-source-shopify
together on the same app with this PR.Without this PR, using multiple sources that use gatsby-plugin-image results in the following error during Gatsby's bootstrap phase:
Why does this happen?
I believe this is a result of
getGatsbyImageResolver
andgetGatsbyImageFieldConfig
using GraphQL type constructors from thegraphql
package. Gatsby (i.e. graphql-compose) sees each newly created type as unique (e.g. theGatsbyImageFormat
enum).Because multiple plugins are calling
getGatsbyImageFieldConfig
and passing it to Gatsby, shared types such asGatsbyImageFormat
are registered twice in the GraphQL schema.How is it fixed?
This can be fixed by using Gatsby's schema helpers which is built upon graphql-compose. We can reference these Gatsby-specific types using strings rather than concrete object references. This allows us to register the type only once.
gatsby-plugin-image
'screateSchemaCustomization
API. Taking this approach requires users to addgatsby-plugin-image
to theirgatsby-config.js
, potentially making this a breaking change.Alternatively, the types could be exported by
gatsby-plugin-image
and required to be registered by plugins.Recommended change: As a final alternative option, it could be added to Gatsby as a first-class type, like
File
. It doesn't matter where the types are registered, as long as it happens somewhere at least once.Documentation
If users are required to add
gatsby-plugin-image
as a plugin (currently this is optional), documentation may need to be updated. The current documentation already instructs users to add the plugin togatsby-config.js
, but makes no mention that it is optional.Related Issues
From
gatsby-source-prismic
: prismicio/prismic-gatsby#416