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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/gatsby-source-filesystem/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

const { createNode, deleteNode, createTypes } = actions

if (createTypes) {
createTypes(`
type File implements Node {
pieh marked this conversation as resolved.
Show resolved Hide resolved
id: ID!
}
`)
}

// Validate that the path exists.
if (!fs.existsSync(pluginOptions.path)) {
Expand Down
12 changes: 12 additions & 0 deletions packages/gatsby-transformer-sharp/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

const { createTypes } = actions

if (createTypes) {
createTypes(`
type ImageSharp implements Node {
pieh marked this conversation as resolved.
Show resolved Hide resolved
id: ID!
}
`)
}
}