【发布时间】:2018-02-13 00:26:16
【问题描述】:
fetchFriends: {
type: new GraphQLList(UserType),
args: {
currentId: { type: new GraphQLNonNull(GraphQLID) }
},
resolve: (_, {currentId}) => {
return Promise.resolve()
.then(() => {
User.findById(currentId, (err, users) => {
users.getFriends((err, user) => {
console.log(user);
return user;
});
});
})
}
/* another version what i tried that returns only the initial findById user
resolve: (_, {currentId}) => {
var value = User.findById(currentId, (err, user) => {
new Promise((resolve, reject) => {
user.getFriends((err, user) => {
console.log('fetch: ', user);
err ? reject(err) : resolve(user)
});
})
})
return value;
}*/
},
我有一个 graphql 解析,我在 findById 回调中获取了 User 对象。该特定对象调用getFriends,它是猫鼬插件(朋友之友)的一部分,并且getFriends回调中的console.log包含终端中的列表,所以我知道getFriends 正在返回正确的数据,但我不知道如何将值返回到我的 React-Native 组件中。在过去的 8 小时里,我已经尝试了所有我能想到的东西,但无法从这个函数中得到返回的值。
【问题讨论】:
-
你尝试过使用 state 吗?
标签: react-native mongoose callback graphql graphql-js