GraphQL错误字段“;“图像”;“类型”的;文件";必须选择子字段。你的意思是“什么?”;图像{…}";?

GraphQL错误字段“;“图像”;“类型”的;文件";必须选择子字段。你的意思是“什么?”;图像{…}";?,graphql,gatsby,netlify,netlify-cms,Graphql,Gatsby,Netlify,Netlify Cms,我正在与盖茨比和Netlify CMS建立一个网站。我用的是盖茨比场地起动器 我一直得到一个类型为“File”的“GraphQL Error Field”image,它必须有一个子字段的选择。您的意思是“image{…}”吗?尝试部署到Netlify时出错。在localhost上,一切都可以完美地工作,但图像似乎有问题。我查看了Netlify CMS页面上提供的示例,发现有人具有完全相同的设置,一个列表小部件(充当图库),其中包含图像和描述 config.yml backend: name:

我正在与盖茨比和Netlify CMS建立一个网站。我用的是盖茨比场地起动器

我一直得到一个类型为“File”的“GraphQL Error Field”image,它必须有一个子字段的选择。您的意思是“image{…}”吗?尝试部署到Netlify时出错。在localhost上,一切都可以完美地工作,但图像似乎有问题。我查看了Netlify CMS页面上提供的示例,发现有人具有完全相同的设置,一个列表小部件(充当图库),其中包含图像和描述

config.yml

backend:
  name: git-gateway
  repo: grantballmer/gatsby-starter-netlify-cms
  branch: master

media_folder: static/img
public_folder: /img

collections:

  - name: "gallery"
    label: "Gallery"
    folder: "src/pages/services"
    create: true
    fields: 
      - { label: "Template Key", name: "templateKey", widget: "hidden", default: "gallery" }
      - {label: "Title", name: "title", widget: "string"}
      - label: "Grid"
        name: "grid"
        widget: "list"
        fields: 
          - {label: "Image", name: "image", widget: "image"}
          - {label: "Band Name", name: "band", widget: "string"}`
gallery.js(模板文件)


我还没有使用Netlify CMS,但看起来您的图像可能是一个带有子字段的集合(例如:
Image{source,id..}
,在这种情况下,您应该重写查询,如下所示:

export const galleryQuery = graphql `
  query Gallery($id: String!) {
    markdownRemark(id: { eq: $id }) {
      html
      frontmatter {
        title
        grid {
          image { 
             id
             source
             ..
          }
          band
        }
      }
    }
  }
`;

试着用pluginsharp的插件添加一些东西

与此相关的东西:

export const galleryQuery = graphql`
  query Gallery($id: String!) {
    markdownRemark(id: { eq: $id }) {
      html
      frontmatter {
        title
        grid {
          image {
            childImageSharp {
              fluid(maxWidth: 2048, quality: 100) {
                ...GatsbyImageSharpFluid
              }
            }
          }
          band
        }
      }
    }
  }
`

感谢您的回答,我会试一试。唯一的问题是,在我的config.yml文件中,我只是将图像作为“列表”小部件中的字段列出,但没有任何与图像相关的“字段”。只需{label:“image”,name:“image”,widget:“image”}。它在本地编译得很好,这就是令人沮丧的地方。你有GraphQL游乐场吗?或者GraphiQL?错误可能来自其他地方,而不是这个文件吗?你是在其他地方查询GraphQL中的
image
字段吗?或者,你的开发分支和
masterbranch?嗨!你最终解决了吗?因为我现在面临同样的问题,netlify只抛出这个错误。我的图像链接只是URL字符串,甚至没有实际的文件。
export const galleryQuery = graphql `
  query Gallery($id: String!) {
    markdownRemark(id: { eq: $id }) {
      html
      frontmatter {
        title
        grid {
          image { 
             id
             source
             ..
          }
          band
        }
      }
    }
  }
`;
export const galleryQuery = graphql`
  query Gallery($id: String!) {
    markdownRemark(id: { eq: $id }) {
      html
      frontmatter {
        title
        grid {
          image {
            childImageSharp {
              fluid(maxWidth: 2048, quality: 100) {
                ...GatsbyImageSharpFluid
              }
            }
          }
          band
        }
      }
    }
  }
`