【问题标题】:Unknown argument ""on field""of type Mutation with React Native app using Apollo Client and Apollo Server使用 Apollo Client 和 Apollo Server 的 React Native 应用程序的 Mutation 类型的未知参数“”on field“”
【发布时间】:2019-07-08 12:12:42
【问题描述】:
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);
   });
 };
}

有人可以帮助我们找出问题所在吗?

它似乎适用于一些突变和查询,有时它 抛出这样的不可预测的错误。我们正在使用反应博览会和 前端是 apollo 客户端,后端是 graphql、apollo 客户端和 neo4j。

架构

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

【问题讨论】:

  • 你确定数据类型 "id: ID" 吗? graphQL 将其视为独特且与 String 相似。

标签: react-native neo4j cypher graphql apollo


【解决方案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
          }
     }`;

或者请检查突变中表单传递的突变变量类型。

【讨论】:

  • 我在代码中看不到逗号?请阿肖克进一步解释一下?
【解决方案2】:

你忘了data:{}

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

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

祝你好运!

【讨论】:

    猜你喜欢
    • 2021-10-04
    • 2021-07-31
    • 2020-10-26
    • 2021-01-15
    • 2019-10-18
    • 2019-01-26
    • 2018-07-18
    • 2021-08-29
    • 2021-05-27
    相关资源
    最近更新 更多