如何使用新的GraphQL Schema语言为我的friendList制作解析器?friendList有一组人_id.
我的新朋友使用GraphQL Schema语言输入:
const schema = buildSchema(`
type People {
_id: String
firstName: String
lastName: String
demo: String
friendList: [People]
}
type Query {
getPeople(_id: String): People
}
`);Run Code Online (Sandbox Code Playgroud)
我的老人用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 } …Run Code Online (Sandbox Code Playgroud)