Error trying to generate datocms types

While generating types for datocms I’m finding this weird issue.

Where the type that shows in datoCMS is FileField.

Where is this type ImageFileField coming from?

Hello @dev14 and welcome to the community!

Can you send us at support@datocms.com the URL of the project where you are receiving that error on codegen? Thank you!

Hi,

We have exactly the same issue. After having changed FileField to ImageFileField the codegen stopped throwing errors on images we load from DatoCMS.

This field type is nowhere documented, not even under the API Explorer within DatoCMS.

This case has been resolved, but it would be great to log the resolution or root cause here.

Best regards,
Ivar

1 Like

Hello @ivar.van.der.burg can you send us the body of the graphql query you are trying to generate the types from as well as any possible fragments you may have inside of it?

Thank you!

Seeing a similar issue:

The query

fragment ImageVariants on FileField {
  default: responsiveImage(imgixParams: { fit: crop, w: 1440, auto: format }) {
    ...ResponsiveImage
  }
  landscape: responsiveImage(
    imgixParams: { fit: crop, w: 1440, ar: "16:9", auto: format }
  ) {
    ...ResponsiveImage
  }
  portrait: responsiveImage(
    imgixParams: { fit: crop, w: 768, ar: "9:16", auto: format }
  ) {
    ...ResponsiveImage
  }
}

fragment Image on ImageRecord {
  __typename
  id
  image {
    __typename
    alt
    url
    width
    height
    ...ImageVariants
  }
}

Now if I run my generator I get the following:

Fragment "ImageVariants" cannot be spread here as objects of type "AltFileField" can never be of type "FileField".
      at /Users/herge/Fully/projects/folkteatern-web/src/graphql/fragments/blocks/Image.graphql:26:5

Which doesn’t happen if I switch to “AltFileField” as the error suggests - but that type doesn’t exist in the API.

Any help would be much appreciated!

@emil.hernqvist, sorry for the late reply here, I missed this when you first posted it.

Could you please try fragment ImageVariants on FileFieldInterface instead of FileField? That may or may not work.

If it doesn’t, could you please share your project URL with us (either here or via email at support@datocms.com) so I can take a look at your schema?

Hey @roger, thanks for the response. That does seem to work! Sneaky.

1 Like

I’m finding these issues have to do with the restrictions on the asset field in the schema. When the asset field is restricted to “Images”, then I have to use on FileField. When the asset field is restricted to “Images transformable by Imgix”, then I have to use on FileFieldInterface.

I was using a single fragment for multiple image fields, including in unions, where some were “images” and some “images transformable by imgix”. That leads to the cannot be spread here as objects of type "A" can never be of type "B" and/or the other way around. I could not get this to work using a single fragment “on anything”, so not on FileField or on ImageFileField or on FileFieldInterface. None of these work with the mixed asset field restrictions in the models.

After introducing two fragments, one on FileField and one on FileFieldInterface and using them for the different asset fields, everything finally worked.

1 Like

Welcome to the community, @root, and great find! Thank you for the tip :slight_smile: