所以我想做的是GraphQL
如果可能的话像这样:
{
people {
_id
name
acted {
_id
title
coactors {
name
}
}
}
}
所以我正在做的就是找演员(人),然后找他们演的电影,效果很好。所以我正在努力寻找那部电影的合作演员。我正在考虑将当前演员的 id 作为参数传递给 coactors 字段,如下所示:
{
people {
_id
name
acted {
_id
title
coactors(actor: people._id) {
name
}
}
}
}
显然,我遇到了错误,并且不知道这是否可以在内部完成。
这是我的类型:
const MovieType = new GraphQLObjectType({
name: 'movie',
fields: () => ({
_id: {
type: GraphQLInt
},
title: {
type: GraphQLString
},
tagline: {
type: GraphQLString
},
released: {
type: GraphQLInt
},
actors: {
type: new GraphQLList(PersonType),
resolve: (movie) => {
return [];
}
},
coactors: {
type: new GraphQLList(PersonType),
args: {
actor: {
type: GraphQLInt
}
},
resolve: (movie, args) => {
getCoActorsFor(movie, args.actor) // How can I do something like this
.then((actors) => {
return actors;
})
}
}
})
});
const PersonType = new GraphQLObjectType({
name: 'person',
fields: ()=> ({
_id: {
type: GraphQLInt
},
name: {
type: GraphQLString
},
born: {
type: GraphQLInt
},
acted: {
type: new GraphQLList(MovieType),
resolve: (person) => {
return [];
}
}
})
});