title: How to correctly configure OptimisticResponse in Apollo local cache in the case of manual update?
body: <p>I'm working with the Apollo local cache and it contains a list of comments. Every item has a <em>liked</em> property and I'd like to change the <em>liked</em> property on the user action. To achieve the fastest client UI update I want to use the <em>optimisticResponse</em> however, I can't find any possibility to do it. Is it possible at all?</p>
  <p>I believe the main problem in my case is that I have the <code>getCommets</code> query and the <code>likeComment</code> dedicated mutation. Here are the detailed code examples:</p>
  <p>A single Comment item schema:</p>
  <pre><code>{
    &quot;__typename&quot;: &quot;Comment&quot;,
    &quot;contentOwner&quot;: true,
    &quot;id&quot;: &quot;61b219358393f922246e5c5d&quot;,
    &quot;text&quot;: &quot;Some comment text&quot;,
    &quot;liked&quot;: true,
  }
  </code></pre>
  <p>To like a comment I have an appropriate mutation:</p>
  <pre><code>export const LIKE_COMMENT = gql`
    mutation LikeComment($status: Boolean!, $commentId: String!) {
      likeComment(status: $status, commentId: $commentId)
    }
  `;
  </code></pre>
  <p>After the mutation execution, I update the local cache to reflect the changes in the Client UI and to avoidthe network delay I wanted to use the <strong>OptimisticResponse</strong> however, it didn't work somehow so I'm wondering if I did everything correctly, or is it just doesn't work because of the difference between <code>likeComment</code>mutation and <code>comments</code> query?</p>
  <pre><code>const data = props.data; // a comment object from the parent HOC
  
  const [
    likeComment,
    { loading: likeCommentLoading, error: likeCommentError },
  ] = useMutation(LIKE_COMMENT, {
  variables: {
    status: !data.liked,
    commentId: data.id,
  },
  
  optimisticResponse: {
    comments: { // is my query name to get all the comments
      id: data.id,
      __typename: &quot;Comment&quot;,
      likeComment: !data.liked,
    },
  },
  
  update(
    cache
  ) {
    const ident = cache.identify(data);
    cache.writeFragment({
      id: ident,
      fragment: gql`
        fragment LikeCommentUpdate on Comment {
          liked
        }
      `,
      data: {
        liked: !data.liked,
      },
    });
  },
  </code></pre>
  <p>});</p>
  <p>P.S. Not sure if it's important but here is my <code>getComments</code> query. Just to be sure that the field <code>comments</code> in the optimisticResponse configuration object is correct</p>
  <pre><code>export const GET_COMMENTS_QUERY = gql`
    ${BASE_AUTHOR_FIELDS}
    ${EXTENDED_COMMENT_FIELDS}
    ${BASE_PAGINATION_FIELDS}
    ${BASE_REPORT_FIELDS}
    query comments(
      $before: String
      $first: Int
      $after: String
      $threadId: String!
      $communityId: String!
      $parentId: String
    ) {
      comments(...)
  }
  </code></pre>
  <p>Many thanks for any help or info <br />
  Kind regards!</p>