[英]There was an error in your GraphQL query: Cannot query field “childImageSharp” on type “StrapiPropiedadesImagen”
When you want to bring me the image with the graphics query, I get an error当你想用图形查询给我带来图像时,我得到一个错误
Cannot query field "childImageSharp" on type "StrapiPropiedadesImagen".
无法在类型“StrapiPropiedadesImagen”上查询字段“childImageSharp”。
And she won't let me bring her.而且她不让我带她。 This is the query that I use to try to bring me the image, the others as description, id, wc, parking, price brings it to me without any problem.
这是我用来尝试给我带来图像的查询,其他的作为描述,id,wc,停车,价格给我带来没有任何问题。 But I can't find the problem when trying to bring me the image.
但是当我试图给我带来图像时,我找不到问题。
const usePropiedades = () => {const datos = useStaticQuery(graphql`
query {
allStrapiPropiedades {
nodes {
nombre
descripcion
id
wc
precio
estacionamiento
habitaciones
categorias {
nombre
}
agentes {
nombre
Telefono
email
}
imagen {
sharp: childImageSharp {
fluid(maxWidth: 600, maxHeight: 400) {
...GatsbyImageSharpFluid
}
}
}
}
}
}
` `
And I want to show it here:我想在这里展示它:
const PropiedadPreview = ({propiedad}) => {
const { nombre, descripcion, imagen, wc, estacionamiento, habitaciones, precio } = propiedad;
return (<Card>
<Image
fluid={imagen.sharp.fluid} // Here I try to show
/>
<Contenido>
<h3>{nombre}</h3>
<p className="precio">$ {precio} </p>
<Iconos
wc={wc}
estacionamiento={estacionamiento}
habitaciones={habitaciones}
/>
</Contenido></Card>
);}
Your childImageSharp
is returning a null
value, you can't even query it in the GraphQL playground ( localhost:8000/___graphql
) so in your component, your code is breaking.您的
childImageSharp
正在返回null
值,您甚至无法在 GraphQL 操场( localhost:8000/___graphql
)中查询它,因此在您的组件中,您的代码正在中断。
<Image
fluid={imagen.sharp.fluid} // Here I try to show
/>
imagen
is never getting the data to display a fluid
asset since the query is null
.由于查询是
null
,因此imagen
永远不会获取数据来显示fluid
资产。
The answer is simple, you need to fix your image path and filesystem to allow Gatsby (and its transformers) to create queryable nodes from your Strapi images, until you don't fix that, you won't be able to use gatsby-image
with those assets.答案很简单,您需要修复图像路径和文件系统,以允许 Gatsby(及其转换器)从您的 Strapi 图像创建可查询节点,直到您不修复它,您将无法使用
gatsby-image
与这些资产。
Have you tried removing "sharp" from your query?您是否尝试过从查询中删除“尖锐”? Just like this:
像这样:
imagen {
childImageSharp {
fluid(maxWidth: 600, maxHeight: 400) {
...GatsbyImageSharpFluid
}
}
}
You have to put this in the hooks file:你必须把它放在钩子文件中:
imagen {
sharp: childImageSharp {
fluid( maxWidth: 600, maxHeight: 400 ){
...GatsbyImageSharpFluid_withWebp
}
}
}
And also if you have the same error you should disable multiple images in the image 'propiedades' strapi type builder而且,如果您遇到相同的错误,您应该在图像“propiedades”strapi 类型构建器中禁用多个图像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.