【发布时间】:2018-04-15 06:19:53
【问题描述】:
我正在尝试在 GraphQL 中包装一个 REST API,我遇到了这个问题。想象一下我有以下类型:
const CbookType = new GraphQLObjectType({
name: 'CbookType',
fields: () => ({
id: { type: GraphQLID },
title: { type: GraphQLString },
user: {
type: UserType,
args: {
userToken: { type: new GraphQLNonNull(GraphQLString) },
userId: { type: new GraphQLNonNull(GraphQLString) }
},
resolve(parentValue, { userToken, userId }) {
return UserController.user({ targetUserId: parentValue.user_id, userToken, userId });
}
}
});
用户字段位于另一个 REST 端点上,因此我必须再次传递我的令牌和 user_id,这会创建丑陋的查询,我必须永久为我的令牌和 user_id 添加 args。
有没有办法让我保留在我的 RootQuery 中传递的参数并在我的类型中重用它们?我调查了 parentValue 但他们不在那里。
【问题讨论】:
标签: javascript node.js graphql