-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(gatsby-transformer-sharp): Use explicit graphql type definit…
…ion vs inferring (#18871) * refactor(gatsby-transformer-sharp): Use explicit graphql type definition vs inferring (#17531) * Change minimal version of gatsby dependency to the one having schema customization API
- Loading branch information
Showing
3 changed files
with
37 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,14 @@ | ||
const fs = require(`fs-extra`) | ||
|
||
exports.onCreateNode = require(`./on-node-create`) | ||
exports.setFieldsOnGraphQLNodeType = require(`./extend-node-type`) | ||
exports.createSchemaCustomization = require(`./customize-schema`) | ||
|
||
exports.onPreExtractQueries = async ({ store, getNodesByType }) => { | ||
exports.onPreExtractQueries = async ({ store }) => { | ||
const program = store.getState().program | ||
|
||
// Check if there are any ImageSharp nodes. If so add fragments for ImageSharp. | ||
// The fragment will cause an error if there are no ImageSharp nodes. | ||
if (getNodesByType(`ImageSharp`).length == 0) { | ||
return | ||
} | ||
|
||
// We have ImageSharp nodes so let's add our fragments to .cache/fragments. | ||
// Add fragments for ImageSharp to .cache/fragments. | ||
await fs.copy( | ||
require.resolve(`gatsby-transformer-sharp/src/fragments.js`), | ||
`${program.directory}/.cache/fragments/image-sharp-fragments.js` | ||
) | ||
} | ||
|
||
exports.sourceNodes = ({ actions }) => { | ||
const { createTypes } = actions | ||
|
||
if (createTypes) { | ||
createTypes(` | ||
type ImageSharp implements Node @infer @childOf(types: ["File"]) { | ||
id: ID! | ||
} | ||
`) | ||
} | ||
} |