【问题标题】:GraphQL Cannot query field \"childImageSharp\" despite the feild being available on graphiqlGraphQL 无法查询字段“childImageSharp”,尽管该字段在 graphiql 上可用
【发布时间】:2020-12-08 03:55:09
【问题描述】:

对于我选择的任何 childimagesharp 变体,我收到此错误“无法在类型“StrapiHomesGalleryImageFormatsMedium”上查询字段“childImageSharp”,即使它们可以在左侧菜单中选择。我无法弄清楚为什么它在何时不可查询其他一切正常。Galleryimage 是一组图像。

应用代码 -

import React from "react"
import { graphql, Link } from "gatsby"
import Image from "gatsby-image"
import ImageGallery from 'react-image-gallery';

const ComponentName = ({ data }) => {
  const {id, galleryImage} = data.home
  console.log('data is', data)
  
  const images = [];

return (
    <Layout>
    <section className="template">
    <ImageGallery items={images} />;
    </section>
    </Layout>
    
)
}

export const query = graphql`
  query GetSingleHome($slug: String) {
    home: strapiHomes(slug: { eq: $slug }) {
    galleryImage {
      formats {
        large {
          childImageSharp {
            fluid {
              ...GatsbyImageSharpFluid
            }
            id
          }
        }
        small {
          childImageSharp {
            fluid {
              ...GatsbyImageSharpFluid
            }
            id
          }
        }
      }
    }
    MainImage {
      childImageSharp {
        fluid {
          ...GatsbyImageSharpFluid
        }
      }
    }
    }
  }
`

【问题讨论】:

    标签: graphql gatsby


    【解决方案1】:

    当您在 Strapi 字段中允许多个图像时,Strapi 和 childImageSharp 存在一个已知问题。转到 Strapi 中的内容类型构建器,并尝试将媒体从多张图像更改为单张图像。

    不幸的是,如果你想使用 GatsbyImage,目前它必须是 Strapi 的单一类型。

    【讨论】:

      猜你喜欢
      • 2021-04-10
      • 2016-03-03
      • 2020-02-19
      • 2020-02-28
      • 2019-10-09
      • 1970-01-01
      • 2021-11-13
      • 2020-12-04
      • 2016-12-05
      相关资源
      最近更新 更多