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

feat(gatsby-transformer-sharp): Add default types for ImageSharp #15285

Merged
merged 3 commits into from
Jul 2, 2019

Conversation

sidharthachatterjee
Copy link
Contributor

Now that themes is almost ready to go, we've surfaced upon an issue in ChristopherBiscardi/gatsby-themes-stable-test#1 where a theme without any content will break with

There was an error in your GraphQL query:

Unknown type "ImageSharpFixed".

File: node_modules/gatsby-transformer-sharp/src/fragments.js:5:37

This occurs because the node the above definition is trying to create a fragment on (ImageSharp) doesn't exist because no image file was present in the project.

To fix this, we need to add default types for ImageSharp, File and more in the respective plugins that own them.

CC @freiksenet @pieh @KyleAMathews

Copy link
Contributor

@freiksenet freiksenet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the fragments work if the types only have ID? We might need to add full type definitions. Also I'm worried about other types that aren't defined.

packages/gatsby-source-filesystem/src/gatsby-node.js Outdated Show resolved Hide resolved
packages/gatsby-transformer-sharp/src/gatsby-node.js Outdated Show resolved Hide resolved
@@ -43,7 +43,15 @@ exports.sourceNodes = (
{ actions, getNode, createNodeId, hasNodeChanged, reporter, emitter },
pluginOptions
) => {
const { createNode, deleteNode } = actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use createSchemaCustomization instead of sourceNodes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we would use createSchemaCustomization here, users would be required to run at least gatsby@2.12.0 and it will inevitably cause issues for people updating just plugin and not core gatsby package.

IMO, if this is just more correct API to use, but doesn't ultimately change how things work, it's just safer to keep it in sourceNodes (at least until we need to do major release for that plugin where we can bump minimal supported Gatsby version without interupting users)

@@ -18,3 +18,15 @@ exports.onPreExtractQueries = async ({ store, getNodesByType }) => {
`${program.directory}/.cache/fragments/image-sharp-fragments.js`
)
}

exports.sourceNodes = ({ actions }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto about createSchemaCustomization.

Co-Authored-By: Mikhail Novikov <freiksenet@gmail.com>
@sidharthachatterjee sidharthachatterjee changed the title [WIP] feat(gatsby): Add default types for File and ImageSharp feat(gatsby): Add default types for ImageSharp Jul 2, 2019
@sidharthachatterjee sidharthachatterjee changed the title feat(gatsby): Add default types for ImageSharp feat(gatsby-transformer-sharp): Add default types for ImageSharp Jul 2, 2019
@sidharthachatterjee sidharthachatterjee merged commit 44580c6 into master Jul 2, 2019
@sidharthachatterjee sidharthachatterjee deleted the fix/add-default-types branch July 2, 2019 18:10
@sidharthachatterjee
Copy link
Contributor Author

Published in gatsby-transformer-sharp@2.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants