问题描述
我正尝试向gql突变发送我的Google OAuth响应以验证用户身份/登录他们。从google获得响应时,我正在执行以下操作:
const authGQL = (user) => graphql(gql`
mutation {
LoginOrSignup(name: ${user.profileObj.name},email: ${user.profileObj.email},googleId:
${user.googleId},imageUrl: ${user.profileObj.imageUrl}) {
name
email
googleId
imageUrl
}
}
`);
这在我的突变文件中:
const mutation = new GraphQLObjectType({
name: 'Mutation',fields: {
LoginOrSignup: {
type: UserType,args: {
name: { type: new GraphQLNonNull(GraphQLString) },email: { type: new GraphQLNonNull(GraphQLString) },googleId: { type: new GraphQLNonNull(GraphQLString) },imageUrl: { type: new GraphQLNonNull(GraphQLString) }
},resolve(parentValue,{ name,email,googleId,imageUrl},request) {
return AuthService.verifyUser({ name,imageUrl,req: request })
}
}
}
});
它没有达到解析功能,我不确定为什么!预先感谢。
解决方法
感谢azium向我指出正确的方向。我必须使用变量:
const mutation = gql`
mutation LoginOrSignup($name: String!,$email: String!,$googleId: String!,$imageUrl: String!,$id_token: String!){
LoginOrSignup(name: $name,email: $email,googleId: $googleId,imageUrl: $imageUrl,id_token: $id_token) {
email
name
}
}
`
在React中,我必须使用props.mutate来设置这些变量:
props.mutate({
variables: {
name: res.profileObj.name,email: res.profileObj.email,googleId: res.googleId,imageUrl: res.profileObj.imageUrl,id_token: res.tokenObj.id_token
}
})