public function mutate($mutations, $options = null)
    {
        $mut = $mutations;
        if ($mut instanceof Patch) {
            $mut = ['patch' => $mut->serialize()];
        } elseif ($mut instanceof Transaction) {
            $mut = $mut->serialize();
        }

        $body = ['mutations' => !isset($mut[0]) ? [$mut] : $mut];
        $queryParams = $this->getMutationQueryParams($options);
        $requestOptions = [
            'method' => 'POST',
            'query' => $queryParams,
            'headers' => ['Content-Type: application/json'],
            'body' => json_encode($body),
            'url' => '/data/mutate/' . $this->clientConfig['dataset'],
        ];

        // Try to perform request
        $body = $this->request($requestOptions);

        // Should we return the documents?
        $returnDocuments = isset($options['returnDocuments']) && $options['returnDocuments'];
        $returnFirst = isset($options['returnFirst']) && $options['returnFirst'];
        $results = isset($body['results']) ? $body['results'] : [];

        if ($returnDocuments && $returnFirst) {
            return isset($results[0]) ? $results[0]['document'] : null;
        } elseif ($returnDocuments) {
            return array_column($results, 'document', 'id');
        }

        // Return a reduced subset
        if ($returnFirst) {
            $ids = isset($results[0]) ? $results[0]['id'] : null;
        } else {
            $ids = array_column($results, 'id');
        }

        $key = $returnFirst ? 'documentId' : 'documentIds';
        return [
          'transactionId' => $body['transactionId'],
          'results' => $results,
          $key => $ids,
        ];
    }