-
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): add support for image-cdn #34825
Conversation
56b467b
to
11a8c68
Compare
11a8c68
to
cfa9a86
Compare
b0dfb18
to
6ef7bf2
Compare
@wardpeet nice work! 🙌 The polyfill means it will work for users upgrading source plugins while staying on an old gatsby version. What about the other way around? Users upgrading gatsby but not source plugins. Will that break their existing GraphQL queries? I think we need to release a breaking change release for source plugins, but for gatsby we should probably put the new resolver changes under a flag or some other opt-in mechanism (perhaps a new gql field to make it opt-in?) |
581402b
to
c608729
Compare
packages/gatsby-plugin-utils/src/polyfill-remote-file/jobs/dispatchers.ts
Outdated
Show resolved
Hide resolved
packages/gatsby-plugin-utils/src/polyfill-remote-file/placeholder-handler.ts
Show resolved
Hide resolved
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.
Only managed to look at the first couple of files, need to look at it again tomorrow
e2e-tests/production-runtime/cypress/integration/remote-file.js
Outdated
Show resolved
Hide resolved
packages/gatsby-plugin-utils/src/polyfill-remote-file/__tests__/resize-resolver.ts
Outdated
Show resolved
Hide resolved
export default function (source: string): string { | ||
let lmdbBinaryLocation | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export default function (this: any, source: string): string { |
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.
These changes are necessary as lmdb can also be required from gatsby-core-utils which can lead to multiple versions. Wich leads to different paths and we want to patch all lmdb versions that need patching.
@@ -71,7 +71,7 @@ export async function createGraphqlEngineBundle( | |||
module: { | |||
rules: [ | |||
{ | |||
test: require.resolve(`lmdb`), | |||
test: /node_modules[/\\]lmdb[/\\].*\.[cm]?js/, |
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.
make the test reach other lmdb modules
@@ -22,7 +22,7 @@ describe(`NodeModel`, () => { | |||
`SiteBuildMetadata`, | |||
`Author`, | |||
`Contributor`, | |||
`RemoteFile`, | |||
`ExternalFile`, |
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.
Changes necessary to pass tests, without it name conflicts happen
…_/resize-resolver.ts Co-authored-by: Tyler Barnes <[email protected]>
Quick question on this. If you do a 'gatsby clean' on your development machine, does this delete the cache folder containing any processed images? I love the feature though! |
@nrandell it does 👍 On Gatsby Cloud images will be cached even when the site cache is invalidated but locally the images will be deleted. The nice thing is they're only fetched and processed once you visit localhost in |
Description
Improve remote file handling by adding a new interface "RemoteFile" to GraphQL. This new interface allows source plugins to lazily download images and has native compatibility with gatsby-plugin-image.
To enable support for RemoteInterface, you'll need a couple of fields to be present on your node:
As noted about only url, filename and mimeType are mandatory for regular files. Images also need width & height specified. The placeholderUrl field is a bit special as we added the option to give use a url with macros, so we can generate a smaller image to generate a placeholder to speed up query running.
With these nodes the RemoteFile Interface adds custom resolvers to your GraphQL type, without you needing to know how they work.
It adds publicUrl to generate a public facing url, resize to resize an image to a specific size and gatsbyImageData to give you a compatible data blob to use with gatsby-plugin-image.
The implementation is a bit hard to follow as everything is added inside
gatsby-plugin-utils
to support older gatsby v4 versions as well. You can upgrade gatsby-source-contentful without upgrading gatsby itself.A source plugin can implement Gatsby's image CDN by wrapping the GraphQL type with the
addRemoteFilePolyfillInterface
in `createSchemaCustimization like thisLast but not least you'll need to add some extra routes to the dev server as well.
Documentation
Related Issues