Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Generating Types for Image queries fluid/fixed ambiguous? #111

Open
wapenshaw opened this issue Nov 25, 2020 · 0 comments
Open

Generating Types for Image queries fluid/fixed ambiguous? #111

wapenshaw opened this issue Nov 25, 2020 · 0 comments

Comments

@wapenshaw
Copy link

I am not sure if this is a bug but I checked through the issues and couldn't find any. Except #54 but that got me no where.

When I am writing an image query like this

const data = useStaticQuery<GetImageQuery>(graphql`
		query getImage {
			image: file(relativePath: { eq: "myface.jpg" }) {
				childImageSharp {
					fluid {
						...GatsbyImageSharpFluid
						...GatsbyImageSharpFluidLimitPresentationSize
					}
				}
			}
		}
	`);

These are the types generated for that query

export type GetImageQueryVariables = Exact<{ [key: string]: never; }>;
export type GetImageQuery = { image?: Maybe<{ childImageSharp?: Maybe<{ fluid?: Maybe<(
        GatsbyImageSharpFluidFragment
        & GatsbyImageSharpFluidLimitPresentationSizeFragment
      )> }> }> };

Now, whenever I am trying to use the Fluid image object for gatsby-image's Img tag like this

fluid={data.image.childImageSharp.fluid } className="m-4 sm:my-4 w-64 rounded-full shadow-2xl border-indigo-400 border-4" />

I get this error and the compile fails
image

However, if I cast the object manually, like this fluid={data.image.childImageSharp.fluid as FluidObject } (as FluidObject) everything works fine. The image loads and I'm all good. However is this the right way? what am I doing wrong?

Here is my plugin config

resolve: `gatsby-plugin-ts`,
  options: {
    tsLoader: {
      logLevel: 'warn',
    },
    forkTsCheckerPlugin: {
      eslint: true,
    },
    fileName: `types/graphql-types.ts`,
    codegen: true,
    codegenDelay: 250,
    typeCheck: true,
    pluckConfig: {
      globalGqlIdentifierName: 'graphql',
      modules: [{ name: 'gatsby', identifier: 'graphql' }],
    },
},

Environment:

Windows 10, "gatsby-plugin-ts": "^2.7.1", "gatsby": "^2.27.2", "gatsby-image": "^2.6.0",

Any corrections/suggestions appreaciated! Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant