投稿のリストを取得するには、apiからjson呼び出しを行います。私の問題は、すべての投稿オブジェクトの応答の中に、私は投稿カテゴリのオブジェクトの他の配列を持っているということです。 Graphqlを使用して配列オブジェクトカテゴリを取得するにはどうすればよいですか?オブジェクト内のGraphQl配列オブジェクト
私はこれを試してますが、私は
const Cat = new ObjectType({
name: 'CatItem',
description: 'cat',
fields:() => ({
id: {
type: new NonNull(ID),
description: 'cat',
resolve: (root) => root.id
},
slug: {
type: StringType,
description: 'cat',
resolve: (root) => root.slug
},
name: {
type: StringType,
description: 'cat',
resolve: (root) => root.name
},
}),
});
const PostType = new ObjectType({
name: 'PostItem',
description: 'post',
fields:() => ({
id: {
type: new NonNull(ID),
description: 'post',
resolve: (root) => root.id
},
slug: {
type: StringType,
description: 'post',
resolve: (root) => root.slug
},
title: {
type: StringType,
description: 'post',
resolve: (root) => root.title
},
content: {
type: StringType,
description: 'post',
resolve: (root) => root.content
},
categories: {
type: new List(CatType),
description: 'post',
resolve: (root) => root.category
},
date: {
type: StringType,
description: 'post',
resolve: (root) => root.date
},
authorName: {
type: StringType,
description: 'post',
resolve: (root) => root.display_name
},
authorAvatar: {
type: StringType,
description: 'post',
resolve: (root) => root.user_avatar
},
}),
});
をエラーを返すには、あなたが取得したいcategories
内のどのフィールド(サブセレクション)GraphQLを伝えるために持っているので、あなたはそのメッセージを取得している
一般に、何かにエラーが生じている場合は、そのエラーの内容も投稿する必要があります。他の人が何が間違っているのかを知るのに役立ちます。 –
私のエラーメッセージは、 "[CatItem]"タイプのフィールド "categories"にはサブ選択がある必要があります – gig