Skip to content
Merged
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
94 changes: 94 additions & 0 deletions Contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Contributing to Neo4j QueryAPI he PHP Client

Thank you for your interest in contributing to the Neo4j QueryAPI PHP Client! We welcome all contributions, whether it's bug fixes, feature enhancements, or documentation improvements.

## Getting Started

1. **Fork the Repository**\
Click the "Fork" button at the top right of the repository page.

2. **Clone Your Fork**

```bash
git clone https://github.com/your-username/Neo4j-Client.git
cd Neo4j-Client
```

3. **Set Up the Environment**

- Ensure you have PHP installed (compatible with PHP < 7.1).
- Install dependencies using Composer:

```bash
composer install
```

- Copy the `phpunit.dist.xml` file to `phpunit.xml` and configure the necessary environment variables like `NEO4J_ADDRESS`, `NEO4J_USERNAME`, `NEO4J_PASSWORD`.



4. **Run Tests**\
Our tests use PHPUnit. To run tests:

```bash
composer/phpunit
```

## Code Guidelines

- Ensure your code is **PSR-12 compliant**.
- Use **Psalm** for static analysis. Run:
```bash
composer psalm
```
- Apply **code style fixes** using:
```bash
composer cs:fix
```

## Making Changes

1. **Create a New Branch**\
Use a descriptive branch name:

```bash
git checkout -b fix/issue-123
```

2. **Make Your Edits**\
Ensure all tests pass and code is properly formatted.

3. **Commit Your Changes**\
Write clear commit messages:

```bash
git commit -m "Fix: Corrected query parsing for ProfiledQueryPlan"
```

4. **Push Your Branch**

```bash
git push origin fix/issue-123
```

## Submitting a Pull Request

1. Go to your forked repository on GitHub.
2. Click on the "New pull request" button.
3. Select your branch and submit the pull request.
4. Add a clear description of the changes you made.

## Review Process

- All PRs are reviewed by the maintainers.
- Ensure CI tests pass before requesting a review.
- Be open to feedback and make revisions as needed.

## Reporting Issues

If you spot a bug or want to suggest a new feature, please [open an issue](https://github.com/NagelsIT/Neo4j-Client/issues) and provide detailed information.

---

We appreciate your contribution — let’s build something powerful together!

136 changes: 132 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,138 @@
Neo4jQueryAPI client

The Neo4j QueryAPI client is for developers and data engineers who want to interact programmatically with Neo4j databases — running queries, handling results, and managing database configurations. It offers:

- Easy configuration to pick and choose drivers
- An intuitive API for smooth query execution
- Extensibility for custom use cases
- Built and tested under close collaboration with the official Neo4j driver team
- Easier to start with, just need a client to any neo4j instance
- Fully typed with Psalm and CS fixed for code quality
- It does not supports Bolt, Rather compatible with HTTP, and auto-routed drivers



# Query API

Usage example:
A PHP client for Neo4j, a graph database.

## Installation

You can install the package via Composer:

```sh
composer require this-repo/neo4j-client
```

## Usage

### Connecting to Neo4j

```php
use Neo4j\QueryAPI\Neo4jQueryAPI;
use Neo4j\QueryAPI\Objects\Authentication;
use Neo4j\QueryAPI\Authentication\AuthenticateInterface;

$client = Neo4jQueryAPI::login('http://localhost:7474', new AuthenticateInterface('username', 'password'));
```

### Running a Query

```php
$query = 'MATCH (n) RETURN n';
$result = $client->run($query);

foreach ($result as $record) {
print_r($record);
}
```

### Transactions

#### Begin a Transaction

```php
$transaction = $client->beginTransaction();
```

#### Run a Query in a Transaction

```php
$query = 'CREATE (n:Person {name: $name}) RETURN n';
$parameters = ['name' => 'John Doe'];
$result = $transaction->run($query, $parameters);
```

#### Commit a Transaction

```php
$transaction->commit();
```

#### Rollback a Transaction

```php
$transaction->rollback();
```

## Testing

To run the tests, execute the following command:

```sh
vendor/bin/phpunit
```

Cypher values and types map to these php types and classes:

| Cypher | PHP |
|--------------------|:-----------------:|
| Single name | |
| Integer | ``` * int ``` |
| Float | ``` * float ``` |
| Boolean | ``` * bool ``` |
| Null | ``` * null ``` |
| String | ``` * string ``` |
| Array | |
| Date | |
| Duration | |
| 2D Point | |
| 3D Point | |
| Cartesian 2D Point | |
| Cartesian 3D Point | |
| Node | |
| Path | |
| Map | |
| Exact name | |
| Bookmarks | Yes |

## Diving deeper:

| Feature | Supported? |
|----------|:-------------:|
| Authentication | Yes |
| Transaction | Yes |
| HTTP | Yes |
| Cluster | Yes |
| Aura | Partly (recent versions) |
| Bookmarks | Yes |

> **_NOTE:_** It supports neo4j databases versions > 5.25 (which has QueryAPI enabled.)



## Contributing

Please see CONTRIBUTING for details.

## Security

If you discover any security-related issues, please email *[email protected]* instead of using the issue tracker.

## Credits

- [Your Name](https://github.com/your-github-username)
- [All Contributors](https://github.com/your-repo/neo4j-client/graphs/contributors)

## License

$client = Neo4jQueryAPI::login('https://myaddress.com', Authentication::bearer('mytokken'))
```
The MIT License (MIT). Please see License File for more information.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"scripts": {
"cs": "vendor/bin/php-cs-fixer fix --dry-run --diff --allow-risky=yes",
"cs:fix": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
"psalm": "vendor/bin/psalm --no-cache --show-info=true"
"psalm": "vendor/bin/psalm --no-cache --show-info=true",
"phpunit" : "vendor/bin/phpunit"
}

}
4 changes: 4 additions & 0 deletions phpunit.dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
<log type="testdox" target="php://stdout" />
</logging>
-->

<!-- <env name="NEO4J_ADDRESS" value="<put your address here>"/>-->
<!-- <env name="NEO4J_USERNAME" value="<put your name here>"/>-->
<!-- <env name="NEO4J_PASSWORD" value="<put your password here>"/>-->
<!-- No need to set sensitive information here -->
</phpunit>
19 changes: 6 additions & 13 deletions src/Neo4jQueryAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use http\Exception\RuntimeException;
use InvalidArgumentException;
use Neo4j\QueryAPI\Exception\Neo4jException;
use Psr\Http\Client\ClientInterface;
Expand All @@ -16,20 +15,15 @@

final class Neo4jQueryAPI
{
private Configuration $config;

public function __construct(
private ClientInterface $client,
private ResponseParser $responseParser,
private Neo4jRequestFactory $requestFactory,
?Configuration $config = null
private Configuration $config
) {
$this->config = $config ?? new Configuration(baseUri: 'http://myaddress'); // Default configuration if not provided

}

/**
* @api
*/
public static function login(string $address = null, ?AuthenticateInterface $auth = null, ?Configuration $config = null): self
{
$config = $config ?? new Configuration(baseUri: $address ?? '');
Expand Down Expand Up @@ -57,19 +51,18 @@ public static function login(string $address = null, ?AuthenticateInterface $aut
);
}

/**
* @api
*/
public function create(Configuration $configuration, AuthenticateInterface $auth = null): self
public static function create(Configuration $configuration, AuthenticateInterface $auth = null): self
{
return self::login(auth: $auth, config: $configuration);
}


public function getConfig(): Configuration
{
return $this->config;
}


/**
* Executes a Cypher query.
*/
Expand Down Expand Up @@ -122,7 +115,7 @@ private function handleRequestException(RequestExceptionInterface $e): void
$response = method_exists($e, 'getResponse') ? $e->getResponse() : null;

if ($response instanceof ResponseInterface) {
$errorResponse = json_decode((string) $response->getBody(), true);
$errorResponse = json_decode((string)$response->getBody(), true);
throw Neo4jException::fromNeo4jResponse($errorResponse, $e);
}

Expand Down
3 changes: 0 additions & 3 deletions src/Neo4jRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamFactoryInterface;

/**
* @api
*/
class Neo4jRequestFactory
{
public function __construct(
Expand Down
7 changes: 2 additions & 5 deletions src/OGM.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use Neo4j\QueryAPI\Objects\Path;
use InvalidArgumentException;

/**
* @api
*/
class OGM
{
/**
Expand Down Expand Up @@ -57,14 +54,14 @@ private function mapNode(array $nodeData): Node
{
return new Node(
labels: $nodeData['_labels'] ?? [],
properties: $this->mapProperties($nodeData['_properties'] ?? []) // ✅ Fix: Ensure properties exist
properties: $this->mapProperties($nodeData['_properties'] ?? [])
);
}

private function mapRelationship(array $relationshipData): Relationship
{
return new Relationship(
type: $relationshipData['_type'] ?? 'UNKNOWN', // ✅ Fix: Default to 'UNKNOWN'
type: $relationshipData['_type'] ?? 'UNKNOWN',
properties: $this->mapProperties($relationshipData['_properties'] ?? [])
);
}
Expand Down
6 changes: 0 additions & 6 deletions src/Objects/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
use Neo4j\QueryAPI\Authentication\BearerAuthentication;
use Neo4j\QueryAPI\Authentication\NoAuth;

/**
* @api
*/
class Authentication
{
public static function basic(string $username, string $password): AuthenticateInterface
Expand All @@ -32,9 +29,6 @@ public static function fromEnvironment(): AuthenticateInterface
);
}




public static function noAuth(): AuthenticateInterface
{
return new NoAuth();
Expand Down
5 changes: 1 addition & 4 deletions src/Objects/Bookmarks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

use JsonSerializable;

/**
* @api
*/
class Bookmarks implements \Countable, JsonSerializable
final class Bookmarks implements \Countable, JsonSerializable
{
public function __construct(private array $bookmarks)
{
Expand Down
Loading