graphQl变异查询不使用变量

时间:2017-05-18 12:51:43

标签: reactjs graphql relay

我是graphql的新手,并且没有得到任何流程如何使用variabls运行此变异查询。 请帮帮我。

mutation SignupUser($signupData : SignupInput) {
      signupUser(signupData: {username: $username, password: $password, email: $email, firstname: $firstname, lastname: $lastname, shareRateCards: $shareRateCards, freeTrial: $freeTrial, termsOfAgreement:$termsOfAgreement, clientId: $clientId }) {
      user {
      firstName
      lastName
      email
      shareRateCards
      freeTrial
      termsOfAgreement
      clientId
      username}
      }
      }


    let variables = {
       username: this.username,
       password: this.password,
       email: this.email,
       firstname: this.firstname,
       lastname: this.lastname,
       shareRateCards: true, 
       freeTrial: true, 
       termsOfAgreement: true, 
       clientId:5
    };

请让我知道怎么做。 提前谢谢。

1 个答案:

答案 0 :(得分:1)

您可以将变异更改为:



gql`
mutation SignupUser($signupData: SignupInput) {
  signupUser(signupData: $signupData) {
    user {
      firstName
      lastName
      email
      shareRateCards
      freeTrial
      termsOfAgreement
      clientId
      username
    }
  }
}`




在服务器上,您可以定义突变,如:



`mutation signupUser(signupData: SignupInput): User`


// resolver:

signupUser(_, { signupData }) {
  // return user
}