使用Apollo Client和Apollo Server与React Native应用进行突变的类型未知的参数““ on on”“

时间:2019-02-14 12:53:30

标签: react-native neo4j cypher graphql apollo

const Profile = t.struct({
 name: t.String,
 city: t.String,
 about: t.String,
});

const UPDATE_USER = gql`
 mutation UpdateAccountForm(
   $id: ID!
   $name: String
   $about: String
   $city: String
 ) {
   UpdateUser(id: $id, name: $name, about: $about, city: $city) {
     id
   }
 }
`;

export default class UpdateAccountForm extends React.Component {
 state = {
   user: {
     name: '',
     about: '',
     city: '',
   },
 };
 render() {
   const { user } = this.state;
   return (
     <Mutation mutation={UPDATE_USER}>
       {(UpdateUser, { data }) => (
         <View style={styles.container}>
           <Image
             source={require('../Images/logoBlue.jpg')}
             style={{ width: 120, height: 120 }}
           />
           <Form
             type={Profile}
             value={user}
             options={options}
             onChange={this.onChange}
           />
           <Button
             title="Submit"
             type="clear"
             titleStyle={{ color: '#4873a6' }}
             onPress={() => this._handleSaveAccount(UpdateUser)}
             containerStyle={{ marginTop: 20 }}
           />
         </View>
       )}
     </Mutation>
   );
 }

  componentDidMount = () => {
   client
     .query({
        query: gql`
         query getUser($id: ID!) {
          User(id: $id) {
              name
              city
              about
           }
          }
       `,
       variables: { id: this.props.loggedInUserId },
     })   

  _handleSaveAccount = async UpdateUser => {
   const { name, about, city } = this.state.user;
   const id = this.props.loggedInUserId;
   const { goToBookshelf } = this.props;

   await UpdateUser({
     variables: {
       id,
       name,
       about,
       city,
     },
   }).then(() => {
     goToBookshelf(id);
   });
 };
}

有人可以帮助我们确定问题所在吗?

似乎对某些突变和查询有效,有时 抛出这样的不可预测的错误。我们正在使用react expo和 前端是apollo客户端,背面是graphql,apollo客户端和neo4j。

架构

    
type User {
  id: ID!
  uid: ID!
  name: String!
  username: String!
  email: String!
  about: String
  city: String
}

2 个答案:

答案 0 :(得分:0)

您忘记了data:{}

const UPDATE_USER = gql`
 mutation UpdateAccountForm(
   data:{$id: ID!, $name: String}     
 ) {
   UpdateUser(id: $id, name: $name) {
     id
   }
 }
`;

仔细检查是否可以发送ID,因为有时它是自动创建的!

祝你好运!

答案 1 :(得分:-1)

我唯一能看到的问题是分隔符,称为逗号“,”

const UPDATE_USER = gql`
     mutation UpdateAccountForm($id: ID!, $name: String,
                             $about: String,$city: String ) {
          UpdateUser(id: $id, name: $name, about: $about, city: $city) {
             id
          }
     }`;

或请检查在变异中通过表格传递的变异变量类型。