gatsby-image-graphql-schema v1.1.1
Gatsby image from GraphQL schema
Use case
This plugin generates fileNodes in your graphQL schema and add File type to it. You can now use
gatsby-plugin-sharp and gatsby-transformer-sharp in your GraphQL schema.
Installation
Add plugin to your project's dependencies
yarn add gatsby-image-graphql-schemaUpdate and configure plugin in your gatsby-config file :
...
{
resolve: "gatsby-image-graphql-schema",
options: {
imageNames: ["publicURL", "strapi_UploadFile.url"],
schemaTypeName: "drupal",
},
},imageNamesis the name of the fields where your images url appears in your graphQL schema. With a dot separation ("."), you can set a specific parent type for field name. In this example, the plugin will take allpublicURLfield names and onlyurlfield name withstrapi_UploadFileparent typeschemaTypeNameis the root schema type name where the plugin will search in to transform your images. (you must have the same value as thetypeNameoptions in thegatsby-source-graphqlplugin).baseUrloptional this plugin option allows you to concatenate image url with a base path (usefull when you only have the name of your images in your query result)
Result
You can now query your images and they come with access to childImageSharp feature :
thumbnail {
url
urlSharp {
childImageSharp {
fixed(width: 500, height: 500) {
...GatsbyImageSharpFixed_withWebp
}
}
}
}