【发布时间】:2019-04-07 13:35:41
【问题描述】:
在您可以查看自己的个人资料和查看他人个人资料的应用中:
您会将其设计为 1 个带有可选 id arg 的查询吗?
profile: async (root, { id }, context) => {
if (!context.user) throw unauthorized error
if (id)
profile = get profile for the passed in id
return profile
// if no id passed, get the current user instead
profile = get profile for context.user.id
return profile
}
或 2 个单独的查询,1 个用于当前登录的用户,1 个用于其他用户?
ownProfile: async (root, {}, context) => { get from context.user.id }
profile: async (root, { id }, context) => { get from id arg } // otherProfile
【问题讨论】:
标签: graphql apollo apollo-server