useMutation 不改变本地状态

useMutation not mutating the local state

我在尝试改变 apollo 中的本地状态时遇到此错误。

errInvariant Violation: Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a "gql" tag? http://docs.apollostack.com/apollo-client/core.html#gql

初始状态

registration: {
    __typename: 'Registration',
    tempMerchantId: '',
    authorizeProfile: {
      __typename: 'AuthorizePersonProfile',
      nid_front: '',
      nid_back: '',
      authorized_person_photo: ''
    }
  }

我的变异

export const setAuthorizePersonQuery = gql`
    mutation setAuthorizePersonProfileInfo($authorizePerosnData: Object!){
        setAuthorizePersonProfileInfo(authorizePersonData: $authorizePerosnData) @client
    }
`;

我的解析器

export const setAuthorizePersonProfileInfo = (
  _, { authorizePersonData }, { cache }
) => {
  try {
    const prevData = cache.readQuery({ getAuthorizePersonProfileQuery });
    cache.writeQuery({
      getAuthorizePersonProfileQuery,
      data: {
        registration: {
          __typename: 'Registration',
          authorizeProfile: {
            __typename: 'AuthorizePersonProfile',
            ...prevData.registration.authorizeProfile,
            ...authorizePersonData
          }
        }
      }
    });
  } catch (e) {
    console.log(`err${e}`);
  }
  return null;
};

我正在尝试改变按下按钮时的本地状态,函数是

const handlePressedNext = () => {
    Promise.all([
      setAuthorizePersonProfileInfo({
        variables: { authorizePersonData: generateNidData() }
      })
    ])
      .then(() => {
        navigation.navigate('Photograph');
      });
  };

generateNidData 函数如下

const generateNidData = () => ({
    nid_front: nidFrontImage,
    nid_back: nidBackImage
  });

我是 apollo 客户端的新手。我不明白我做错了什么。谁能帮我解决问题?

getAuthorizePersonProfileQuery 不是 readQuery 的有效选项。据推测,您的意思是改用 query