Andrew
Andrew

Reputation: 21

Fatal Error : Unsupported media type : querying neo4j via php/graphaware

I'm starting out on a small home project using Neo4J and coding in PHP.

I've set up a couple of Docker containers using the following yml file:

services:
  neo4j:
    build: ./
    image: neo4j:latest
    volumes:
      - $HOME/Documents/GitHub/engine/neo4j/data:/data
      - $HOME/Documents/GitHub/engine/neo4j/logs:/logs
      - $HOME/Documents/GitHub/engine/neo4j/import:/var/lib/neo4j/import
      - $HOME/Documents/GitHub/engine/neo4j/plugins:/plugins
    ports:
      - "7474:7474"
      - "7687:7687"
    restart: always
    environment:
      NEO4J_AUTH: neo4j/test
      NEO4J_default_listen_address: 0.0.0.0
  apache-php:
    depends_on:
      - neo4j
    build: ./
    image: php:7.2-apache
    volumes:
      - $HOME/Documents/GitHub/engine/php:/var/www/html
    ports:
      - "80:80"
    restart: always
volumes:
  neo4j-data:
    driver: local
  neo4j-logs:
    driver: local
  neo4j-import:
    driver: local
  neo4j-plugins:
    driver: local
  php:
    driver: local

I have a simple index.php that should connect, run a simple query and return the results:


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

use GraphAware\Neo4j\Client\ClientBuilder;

$client = ClientBuilder::create()
    ->addConnection('default', 'http://neo4j:test@neo4j:7474') // Example for HTTP connection configuration (port is optional)
    ->build();

$
$query = 'MATCH (n:Person)-[:FOLLOWS]->(friend) RETURN n.name, collect(friend) as friends';
$result = $client->run($query);

foreach ($result->getRecords() as $record) {
    echo sprintf('Person name is : %s and has %d number of friends', $record->value('name'), count($record->value('friends')));
}
?>

But on loading the index.php I get the following error:

Fatal error: Uncaught Http\Client\Common\Exception\ClientErrorException: Unsupported Media Type 
in /var/www/html/vendor/php-http/client-common/src/Plugin/ErrorPlugin.php:72 Stack trace: #0 
/var/www/html/vendor/php-http/client-common/src/Plugin/ErrorPlugin.php(54): 
Http\Client\Common\Plugin\ErrorPlugin-
>transformResponseToException(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) 
#1 /var/www/html/vendor/php-http/httplug/src/Promise/HttpFulfilledPromise.php(34): 
Http\Client\Common\Plugin\ErrorPlugin->Http\Client\Common\Plugin\{closure}
(Object(GuzzleHttp\Psr7\Response)) #2 /var/www/html/vendor/php-http/client-
common/src/Plugin/ErrorPlugin.php(55): Http\Client\Promise\HttpFulfilledPromise-
>then(Object(Closure)) #3 /var/www/html/vendor/php-http/client-common/src/PluginClient.php(161): 
Http\Client\Common\Plugin\ErrorPlugin->handleRequest(Object(GuzzleHttp\Psr7\Request), 
Object(Closure), Object(Closure)) #4 /var/www/html/vendor/php-http/client-
common/src/PluginClient.php(175): Http\Client\Common\PluginClient->H in 
/var/www/html/vendor/php-http/client-common/src/Plugin/ErrorPlugin.php on line 72

I can connect to the Neo4J database via the default web client on localhost:7474 and perform the query as required with the correct results back.

I was following the info found here: https://github.com/graphaware/neo4j-php-client

Any pointers on what's missing? Ta

Upvotes: 2

Views: 363

Answers (0)

Related Questions