GraphQL Apollo接收数据对象未定义

时间:2018-10-05 10:35:10

标签: graphql apollo react-apollo mutation

我正在做一个突变,它需要一个用户名和密码,并作为响应从服务器获得登录响应。

<Mutation mutation={SIGN_UP}>
        {(signUp, data) => (
         <form onSubmit={e => {
            e.preventDefault();
            signUp({
                 variables: { 
                    user: {
                    "email": input_email.value as String, 
                    "password": input_password.value as String
                    }
                }
            });
            console.log("Signup", signUp)
            console.log("Data", data.data);

            input_email.value = "";
            input_password.value = "";
         }}>
            <div className="col-sm">
                <div className="signin__header">Signup IMPACT R&D</div>
            </div>
            <div className="col-sm signin__input" >
                <div className="signin__input__header" >Email</div>
                <input className="signin__input__email" type="text" placeholder="Enter email" required ref={node=> {input_email = node}}></input>
                <div className="signin__divide-line"></div>
            </div>
            <div className="col-sm signin__input">
                <div className="signin__input__header" >Password</div>
                <input className="signin__input__password" type="password" placeholder="Enter password" ref={node=> {input_password = node}}></input>
                <div className="signin__divide-line"></div>
            </div>
            <div className="col-sm-3">
                <button className="signin__input__button" type="submit">Sign Up</button>
            </div>
         </form>
    )}
</Mutation>

这是我的GraphQLtag。

 export const SIGN_UP : any = gql`
 mutation Register($user: UserInput!) {
    register(user: $user) {
        status,
        refreshToken,
        token,
        error
    }
 } 
`;

在浏览器网络中,我可以看到我收到了数据。但是当我尝试将其打印出来时,我的数据对象仍然为空...帮助!

1 个答案:

答案 0 :(得分:0)

发现我需要在注册后等待一个带有答应的响应

{ blob:
   Blob {
     [Symbol(type)]: 'image/png',
     [Symbol(buffer)]: <Buffer 89  ... > },
  contentType: 'image/png',
  fileName: 'image.png' }
}