【发布时间】:2018-06-29 02:48:03
【问题描述】:
在我的 GraphQL 应用程序中,有一个参考其他 mongo/mongoose 对象的 mongo 集合:
export const SingerType = new GraphQLObjectType({
name: "Singer",
description: "A band´s singer",
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLID),
},
name: {
type: new GraphQLNonNull(GraphQLString)
},
band: {
type: new GraphQLNonNull(BandType),
resolve: (source, args, context) => {
return Band.findOne({
_id: source.band_id
}).exec();
}
}
albuns: {
type: new GraphQLList(AlbumType),
resolve: (source, args, context) => {
return Album.find({
_id: source._id
}).exec();
}
}
})
});
export const SingerInputType = new GraphQLInputObjectType({
name: "SingerInput",
description: "Band´s singer input type",
fields: () => ({
name: {
type: new GraphQLNonNull(GraphQLString)
},
band_id: {
type: new GraphQLNonNull(GraphQLString) <<== GraphQLString or GraphQLID here ???
},
albuns: {
type: new GraphQLList(GraphQLString) <<== GraphQLString or GraphQLID here ???
} }
})
});
我的疑问是:
我应该使用GraphQLString 或GraphQLID 来引用其他对象 - 单独或在数组中 - 如示例代码中所述?
【问题讨论】:
标签: mongodb facebook-graph-api mongoose graphql graphql-js