我在下面有以下redux-form ...如何让console.log
从graphQL变异结果数据中获取user.id?
const withForm = compose(
withMySignupMutation,
reduxForm({
...
onSubmit: async (values, dispatch, {
mySignup,
}) => {
try {
const result = await mySignup(values);
console.log('I Need user.id here');
console.log(result.user.id);
...
withMySignupMutation
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
export const SIGNUP_MUTATION = gql`
mutation (
$email: String!
$name: String!
) {
signup(authProvider: {
mySignup: {
email: $email
name: $name
}
}) {
token
}
}
`;
export default graphql(
SIGNUP_MUTATION,
{
props: ({ mutate }) => ({
mySignup: async (variables) => {
const { data } = await mutate({ variables });
},
}),
}
);
谢谢!节日快乐
答案 0 :(得分:0)
在我看来,它应该是result.data.signup.id
,但我们需要查看解析器和您的架构定义。这取决于解析器发回的内容。它应该是用户类型。
无论如何,你必须在变异中询问身份否则就无法解决:
export const SIGNUP_MUTATION = gql`
mutation (
$email: String!
$name: String!
) {
signup(authProvider: {
mySignup: {
email: $email
name: $name
}
}) {
token
id ### <===HERE===
}
}
`
如果你有对服务器的graphiql访问权限:
DOCS
按钮的右上角,然后点击mutation: Mutation
signup(authProvider: AuthProviderNewcomerData!): User
然后你知道你会得到一个User
。