friendListの新しいGraphQLスキーマ言語でのリゾルバの作成方法を教えてください。 friendListは_idの配列を持っています。新しいGraphQLのネストされたクエリbuildSchema
私の新しい人々がGraphQLスキーマ言語と入力します。
const PeopleType = new GraphQLObjectType({
name: 'People',
fields:() => ({
_id: {
type: GraphQLString,
},
firstName: {
type: GraphQLString,
},
lastName: {
type: GraphQLString,
},
friendList: {
type: new GraphQLList(PeopleType),
// pass @friends parentValue
resolve: ({ friends }) {
return People.find({ _id: { $in: friends } }).then(res => res);
},
}),
});
私はこのクエリを達成したい:
私の昔の人々はGraphQLObjectTypeと入力しconst schema = buildSchema(`
type People {
_id: String
firstName: String
lastName: String
demo: String
friendList: [People]
}
type Query {
getPeople(_id: String): People
}
`);
{
people(_id: "ABC123") {
firstName
lastName
friendList {
firstName
lastName
}
}
これまでにこの回答が見つかりましたか?今自分自身で苦労している。 –