Strapi/Graphql。我做错了什么?
对不起,我完全是业余爱好者。我在Strapi cms中有一个简单的api,它与两种类型的博客和画廊有着密切的关系。我正在尝试从api获取数据,但我不知道如何从嵌套数组类型获取数据Strapi/Graphql。我做错了什么?,graphql,next.js,strapi,Graphql,Next.js,Strapi,对不起,我完全是业余爱好者。我在Strapi cms中有一个简单的api,它与两种类型的博客和画廊有着密切的关系。我正在尝试从api获取数据,但我不知道如何从嵌套数组类型获取数据 import { useQuery } from "@apollo/react-hooks"; import { gql } from "apollo-boost"; import {Row, Col} from './../../style/grid' const GET_POSTS = gql` {
import { useQuery } from "@apollo/react-hooks";
import { gql } from "apollo-boost";
import {Row, Col} from './../../style/grid'
const GET_POSTS = gql`
{
blogs {
id
title
article
galleries {
id
title
image {
id
name
url
}
}
}
}
`;
function Blog() {
const { data } = useQuery(GET_POSTS);
if (data && data.blogs) {
return (
<>
{data.blogs.map((post) => (
<Row>
<Col key={post.galleries.title}>
{post.galleries.image.url} //this not
</Col>
<Col key={post.id}>
{post.title} {post.article} //this works
</Col>
</Row>
))}
</>
);
}
return <div>Loading...</div>;
}
export default Blog;
你还需要绘制画廊的地图
function Blog() {
const { data } = useQuery(GET_POSTS);
if (data && data.blogs) {
return (
<>
{data.blogs.map((post) => (
<Row>
{post.galleries.map((gallery) => (
<Col key={gallery.title}>
{gallery.image.url} //this not
</Col>
))}
<Col key={post.id}>
{post.title} {post.article} //this works
</Col>
</Row>
))}
</>
);
}
return <div>Loading...</div>;
}
function Blog() {
const { data } = useQuery(GET_POSTS);
if (data && data.blogs) {
return (
<>
{data.blogs.map((post) => (
<Row>
{post.galleries.map((gallery) => (
<Col key={gallery.title}>
{gallery.image.url} //this not
</Col>
))}
<Col key={post.id}>
{post.title} {post.article} //this works
</Col>
</Row>
))}
</>
);
}
return <div>Loading...</div>;
}