Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions src/Neo4jQueryAPI.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Neo4j\QueryAPI;

use GuzzleHttp\Client;
Expand All @@ -14,38 +13,21 @@

class Neo4jQueryAPI
{
public function __construct(
private ClientInterface $client,
private ResponseParser $responseParser,
private Neo4jRequestFactory $requestFactory
) {
}
private ClientInterface $client;
private ResponseParser $responseParser;
private Neo4jRequestFactory $requestFactory;

/**
* @api
*/
public static function login(string $address, AuthenticateInterface $auth = null): self
{
$client = new Client();

return new self(
client: $client,
responseParser: new ResponseParser(
ogm: new OGM()
),
requestFactory: new Neo4jRequestFactory(
psr17Factory: new Psr17Factory(),
streamFactory: new Psr17Factory(),
configuration: new Configuration(
baseUri: $address
),
auth: $auth ?? Authentication::fromEnvironment()
)
);
public function __construct(
ClientInterface $client,
ResponseParser $responseParser,
Neo4jRequestFactory $requestFactory
) {
$this->client = $client;
$this->responseParser = $responseParser;
$this->requestFactory = $requestFactory;
}



/**
* Executes a Cypher query.
*/
Expand Down
42 changes: 42 additions & 0 deletions src/abc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

require __DIR__ . '/../vendor/autoload.php';

use Neo4j\QueryAPI\Neo4jQueryAPI;
use Neo4j\QueryAPI\Authentication\AuthenticateInterface;
use Neo4j\QueryAPI\Objects\Authentication;
use Neo4j\QueryAPI\Configuration;
use Neo4j\QueryAPI\Results\ResultSet;

$neo4jUrl = 'bb79fe35.databases.neo4j.io'; // Your Neo4j Aura instance URL (without `neo4j+s://`)
$neo4jUsername = 'neo4j'; // Your Neo4j username
$neo4jPassword = 'OXDRMgdWFKMcBRCBrIwXnKkwLgDlmFxipnywT6t_AK0'; // Your Neo4j password

try {
// Correctly instantiate the $auth object with basic authentication
$auth = Authentication::basic($neo4jUsername, $neo4jPassword);

// Call the login method with your custom library (using Bolt protocol)
$neo4j = Neo4jQueryAPI::login(
$neo4jUrl, // URL without `neo4j+s://`
$auth
);

// Run a simple Cypher query
$cypher = 'MATCH (n) RETURN n LIMIT 10';
$resultSet = $neo4j->run($cypher);

// Check the result structure (debugging purposes)
var_dump($resultSet); // To inspect the response data

// Handle results
foreach ($resultSet as $row) {
echo "Node: " . json_encode($row) . "\n";
}

// Optionally, start a transaction
$transaction = $neo4j->beginTransaction();

Check failure on line 38 in src/abc.php

View workflow job for this annotation

GitHub Actions / Run Psalm

UnusedVariable

src/abc.php:38:5: UnusedVariable: $transaction is never referenced or the value is not used (see https://psalm.dev/077)

} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
16 changes: 15 additions & 1 deletion tests/Integration/Neo4jQueryAPIIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,23 @@ public function testInvalidQueryHandling()
}


private function initializeApi(): Neo4jQueryAPI
/*private function initializeApi(): Neo4jQueryAPI
{
return Neo4jQueryAPI::login(getenv('NEO4J_ADDRESS'), Authentication::fromEnvironment());
}*/

private function initializeApi(): Neo4jQueryAPI
{
$client = new Client();
$responseParser = new ResponseParser(ogm: new OGM());

$requestFactory = new Neo4jRequestFactory(
psr17Factory: new Psr17Factory(),
streamFactory: new Psr17Factory(),
configuration: new Configuration(baseUri: getenv('NEO4J_ADDRESS')),
auth: Authentication::fromEnvironment()
);
return new Neo4jQueryAPI($client, $responseParser, $requestFactory);
}

public function testCounters(): void
Expand Down
25 changes: 23 additions & 2 deletions tests/Integration/Neo4jTransactionIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
namespace Neo4j\QueryAPI\Tests\Integration;

use Exception;
use GuzzleHttp\Client;
use Neo4j\QueryAPI\Configuration;
use Neo4j\QueryAPI\Neo4jRequestFactory;
use Neo4j\QueryAPI\Objects\Authentication;
use GuzzleHttp\Exception\GuzzleException;
use Neo4j\QueryAPI\Neo4jQueryAPI;
use Neo4j\QueryAPI\OGM;
use Neo4j\QueryAPI\ResponseParser;
use Nyholm\Psr7\Factory\Psr17Factory;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -28,14 +34,29 @@ public function setUp(): void
/**
* @throws Exception
*/
private function initializeApi(): Neo4jQueryAPI
/* private function initializeApi(): Neo4jQueryAPI
{
return Neo4jQueryAPI::login(
getenv('NEO4J_ADDRESS'),
Authentication::fromEnvironment(),
);
}
}*/
private function initializeApi(): Neo4jQueryAPI
{
$client = new Client(); // Guzzle Client


$responseParser = new ResponseParser(ogm: new OGM());

$requestFactory = new Neo4jRequestFactory(
psr17Factory: new Psr17Factory(),
streamFactory: new Psr17Factory(),
configuration: new Configuration(baseUri: getenv('NEO4J_ADDRESS')),
auth: Authentication::fromEnvironment()
);

return new Neo4jQueryAPI($client, $responseParser, $requestFactory);
}
/**
* @throws GuzzleException
*/
Expand Down
Loading