-
Notifications
You must be signed in to change notification settings - Fork 1.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
gatsbyImageData property is typed as any #5748
Comments
Custom scalars(other than primitive default ones) are typed as |
Hm... yeah, seems like it's a problem with gatsby But maybe it's possible somehow to make graphql-code-generator to use gatsby's own type for this specific field? https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-image/src/components/gatsby-image.browser.tsx#L47 |
You can use scalars:
JSON: my-types.ts#MyType But it is not possible to do this for a specific type for now. |
Maybe it's possible to do via custom plugin? |
Ok, figured out how to solve it. First of all we need to change return type for gatsbyImageData function in graphql: gatsby-node.js exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
scalar GatsbyImageData
type ImageSharp {
gatsbyImageData(
aspectRatio: Float
avifOptions: AVIFOptions
backgroundColor: String
blurredOptions: BlurredOptions
breakpoints: [Int]
formats: [ImageFormat]
height: Int
jpgOptions: JPGOptions
layout: ImageLayout = CONSTRAINED
outputPixelDensities: [Float]
placeholder: ImagePlaceholder
pngOptions: PNGOptions
quality: Int
sizes: String
tracedSVGOptions: Potrace
transformOptions: TransformOptions
webpOptions: WebPOptions
width: Int
): GatsbyImageData!
}
`
createTypes(typeDefs)
} And then in in codegen.yml config:
scalars:
GatsbyImageData: gatsby-plugin-image#IGatsbyImageData |
@ardatan thx for the help |
@smashercosmo I am trying to do this same thing but am running into errors with |
no, sorry, I haven't. this solution still works for me even with latest Gatsby 3.3. |
With gatsbyjs/gatsby#35683 the return type should become a custom scalar, not |
Describe the bug
Gatsby has recently introduced new image plugin. In order to use it, you have to query for 'gatsbyImageData', like this
for some reason in types generated by graphql-code-generator gatsbyImageData property is typed like this
which results in gatsbyImageData being of type 'any'. Though in graphql schema this property is typed like this
https://github.com/gatsbyjs/gatsby/blob/57c131db9d43e526e6228df4502119b8296ebfb6/packages/gatsby-transformer-sharp/src/customize-schema.js#L568
https://github.com/gatsbyjs/gatsby/blob/57c131db9d43e526e6228df4502119b8296ebfb6/packages/gatsby-transformer-sharp/src/customize-schema.js#L403
I'm not sure, if it's a bug or I'm doing something wrong.
To Reproduce
If it's not something obvious, I'll provide example repo. But basically it can be reproduced with any new gatsby project.
My
codegen.yml
config file:Environment:
The text was updated successfully, but these errors were encountered: