1
votes

I'm getting this error while trying to mutate the local state in 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

Initial state

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

My mutation

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

My resolver

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;
};

I'm trying to mutate the local state on button press, the function is

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

generateNidData function is like bellow

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

I'm new to apollo client. I can not understand what I'm doing wrong. Can anyone help me figure out the problem?

1

1 Answers

2
votes

getAuthorizePersonProfileQuery is not a valid option for readQuery. Presumably, you meant use query instead.