【发布时间】:2017-01-30 21:03:46
【问题描述】:
如何使用新的 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
}
`);
我的老人用 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
}
}
【问题讨论】:
-
你找到答案了吗?我自己现在正在努力解决这个问题。
标签: graphql graphql-js