gpt4 book ai didi

类型为 "image"的 GraphQL 错误字段 "File"必须选择子字段。你的意思是 "image { ... }"吗?

转载 作者:行者123 更新时间:2023-12-04 11:03:21 25 4
gpt4 key购买 nike

我正在使用 gatsby 和 Netlify CMS 构建一个站点。我使用了 Gatsby Site Starter。

我不断收到"file"类型的“GraphQL 错误字段”图像,必须选择子字段。您的意思是“图像 { ... }”吗?尝试部署到 Netlify 时出错。一切都在本地主机上完美运行,但图像似乎有些失败。我查看了 Netlify CMS 页面上提供的示例,发现有人具有完全相同的设置,一个列表小部件(充当画廊),其中包含图像和描述,here .

配置文件

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(模板文件)
import React from 'react';
import { graphql } from 'gatsby';
import Layout from "../components/Layout";
import PhotoGrid from "../components/services/PhotoGrid";

const GalleryTemplate = ({ data }) => {
const { markdownRemark: gallery } = data;
const images = gallery.frontmatter.grid;

return (
<Layout>
<PhotoGrid images={images} />
</Layout>
);
};

export default GalleryTemplate;

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

/services/photography.md
---
templateKey: 'gallery'
title: photography
grid:
- band: chris-cordle
image: /img/chris-cordle-lg.jpg
- band: 'chirp '
image: /img/chirp-lg-1-.jpg
---

最佳答案

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

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

关于类型为 "image"的 GraphQL 错误字段 "File"必须选择子字段。你的意思是 "image { ... }"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54700480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com