这是我对GET请求的JSON响应:
[{
id: 1,
title: {rendered: 'Project 1'},
content: {rendered: 'Lorem ipsum'}
},
{
id: 2,
title: {rendered: 'Project 2'},
content: {rendered: 'Lorem ipsum'}
},
{
id: 3,
title: {rendered: 'Project 3'},
content: {rendered: 'Lorem ipsum'}
}]
这是我创建GraphQL对象的方式:
const ProjectsType = new GraphQLObjectType({
name: 'ProjectItem',
description: 'This object is a project',
fields: () => ({
title: {
description: 'Le titre du projet',
type: StringType
},
content: {
description: 'Le contenu html du projet',
type: StringType
},
}),
});
如何访问我的第二个对象标题和内容?我知道我必须解决这个问题,但我不明白这一点。
答案 0 :(得分:0)
这应该对你有用
fields: () => ({
title: {
description: 'Le titre du projet',
type: StringType,
resolve: (root) => root.title.rendered
},
content: {
description: 'Le contenu html du projet',
type: StringType,
resolve: (root) => root.content.rendered
},
}),