创建一个突变成分

时间:2019-05-18 03:20:33

标签: graphql apollo react-apollo

我正在尝试创建一个graphql突变组件。我的目标是能够导入它并调用registerUser(userInfo)来运行和执行我的变异。

const registerUser = (user) => {
  const REGISTER_USER = gql`
  mutation RegisterUser($email: String!, $password: String!, $username: String!){
    RegisterUser(email: $email, password: $password, username: $username){
    id
    username   
    email  
    }
  } 
  `
  const variables = {
    email: user.email,
    password: user.password,
    username: user.username,

  };

  return (
    <Mutation mutation={REGISTER_USER} variables={variables}>
      {(registerUser, { error, data }) => {
        if (error) console.log('error', error);
        if (data) console.log('data', data);

        registerUser()
      }}
    </Mutation>
  )
}

export default registerUser;

0 个答案:

没有答案