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,
        ];
    }
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,
        ];
    }
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 , ] ; }
Send a set of mutations to the API for processing

@param array|Patch|Transaction $mutations Either an array of mutations, a patch or a transaction
@param array $options Optional array of options for the request
@return array Mutation result
Send a set of mutations to the API for processing