如何使用新的GraphQL Schema語言爲我的friendList製作解析器? friendList有一組人_id。新的GraphQL的嵌套查詢buildSchema
我新,人型與GraphQL模式語言:
const schema = buildSchema(`
type People {
_id: String
firstName: String
lastName: String
demo: String
friendList: [People]
}
type Query {
getPeople(_id: String): People
}
`);
我的老人們輸入與GraphQLObjectType:
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);
},
}),
});
我想要實現這個查詢:
{
people(_id: "ABC123") {
firstName
lastName
friendList {
firstName
lastName
}
}
你有沒有找到答案?現在正在努力克服這一點。 –