**已解决** GraphQL / Apollo部分更新发送带有空值的完整对象块

时间:2019-05-08 16:27:45

标签: graphql apollo

嘿,我刚遇到某种问题。在操场上,一切正常,但在应用程序中,我发送的所有对象都带有空字段,而我尝试更新的字段除外。

所以我正在尝试更新用户的名字和姓氏。

这是我的变异

export default gql`
  mutation updateUser(
    $_id: ID!
    $email: String
    $password: String
    $firstName: String
    $lastName: String
    $phone: String
    $description: String
    $role: String
    $avatar: String
    $houseName: String
    $streetName: String
    $city: String
    $postCode: String
    $newUser: Boolean
    $expoPushToken: String
    $birthday: String
    $countryOfResidence: String
    $nationality: String
  ) {
    updateUser(
      _id: $_id
      email: $email
      password: $password
      firstName: $firstName
      lastName: $lastName
      phone: $phone
      description: $description
      role: $role
      avatar: $avatar
      houseName: $houseName
      streetName: $streetName
      city: $city
      postCode: $postCode
      newUser: $newUser
      expoPushToken: $expoPushToken
      birthday: $birthday
      countryOfResidence: $countryOfResidence
      nationality: $nationality
    ) {
      _id
    }
  }
`;

我在这里做突变

this.props.updateUser(_id, firstName, lastName);

const mutationConfig = {
  props: ({ mutate }) => ({
    updateUser: (_id, firstName, lastName) =>
      mutate({
        variables: { _id, firstName, lastName }
      })
  })
};

我在数据库中得到的东西

{ email: null,
  password: null,
  firstName: 'John',
  lastName: 'Doe',
  phone: null,
  description: null,
  role: null,
  avatar: null,
  houseName: null,
  streetName: null,
  city: null,
  postCode: null,
  newUser: null,
  expoPushToken: null,
  birthday: null,
  countryOfResidence: null,
  nationality: null }

如果我在操场上做同样的事情

mutation{
  updateUser(_id: "5cd2f8612a89ff61aed9f43c", firstName: "John", lastName:"Doe"){
    _id
  }
}

响应看起来像这样

{ firstName: 'John', lastName: 'Doe' }

有什么想法吗?

已解决

我发现唯一的问题来自react-apollo@2.5.5,所以我回到react-apollo@2.4.1直到发布新版本为止

0 个答案:

没有答案