ulobby / NeoEloquent

An extension of Laravel Elqouent that supports Neo4j, a native graph database
MIT License
40 stars 17 forks source link

where queries and Laravel Telescope query watcher #50

Open screw opened 2 years ago

screw commented 2 years ago

I've upgraded to neoEloquent 9.0.5 which now works with Laravel Telescope, but it fails when I use where().

Just to clarify: if I turn off telescope's query watcher, I can do all sorts of cypherQueries. But when I enable the query watcher, only simple queries - (without where filters, just get all nodes of a certain type for example).

$data = $neoClass::query(); $result=$data->paginate();

When I try to include filters aka WHERE clause ->where(...), the query fails:

           $data ->when($filterNeo, function ($query, $filterNeo) {
                return $query->where(NeoClass::COL_SOMEFIELD, 'STARTS WITH', "$filterNeo");
            });

The problem is in the telescope because it doesn't check what is returned from getPdo() (link snipped below). But they are not willing to address it within their code.

protected function quoteStringBinding($event, $binding)
    {
        try {
            return $event->connection->getPdo()->quote($binding);
        } catch (\PDOException $e) {
            throw_if('IM001' !== $e->getCode(), $e);
        }

I am wondering how NeoEloquent works with the simple queries since those are logged in the telescope. Maybe there is a fix since some queries work with the telescope.

Call stack:

{
    "message": "Call to a member function quote() on null",
    "exception": "Error",
    "file": "/var/www/vendor/laravel/telescope/src/Watchers/QueryWatcher.php",
    "line": 122,
    "trace": [
        {
            "file": "/var/www/vendor/laravel/telescope/src/Watchers/QueryWatcher.php",
            "line": 103,
            "function": "quoteStringBinding",
            "class": "Laravel\\Telescope\\Watchers\\QueryWatcher",
            "type": "->"
        },
        {
            "file": "/var/www/vendor/laravel/telescope/src/Watchers/QueryWatcher.php",
            "line": 42,
            "function": "replaceBindings",
            "class": "Laravel\\Telescope\\Watchers\\QueryWatcher",
            "type": "->"
        },
        {
            "file": "/var/www/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php",
            "line": 404,
            "function": "recordQuery",
            "class": "Laravel\\Telescope\\Watchers\\QueryWatcher",
            "type": "->"
        },
        {
            "file": "/var/www/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php",
            "line": 249,
            "function": "Illuminate\\Events\\{closure}",
            "class": "Illuminate\\Events\\Dispatcher",
            "type": "->"
        },
        {
            "file": "/var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php",
            "line": 887,
            "function": "dispatch",
            "class": "Illuminate\\Events\\Dispatcher",
            "type": "->"
        },
        {
            "file": "/var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php",
            "line": 728,
            "function": "event",
            "class": "Illuminate\\Database\\Connection",
            "type": "->"
        },
        {
            "file": "/var/www/vendor/ulobby/neoeloquent/src/Connection.php",
            "line": 489,
            "function": "logQuery",
            "class": "Illuminate\\Database\\Connection",
            "type": "->"
        },
        {
            "file": "/var/www/vendor/ulobby/neoeloquent/src/Connection.php",
            "line": 214,
            "function": "run",
            "class": "Vinelab\\NeoEloquent\\Connection",
            "type": "->"
        },
        {
            "file": "/var/www/vendor/ulobby/neoeloquent/src/Query/Builder.php",
            "line": 629,
            "function": "select",
            "class": "Vinelab\\NeoEloquent\\Connection",
            "type": "->"
        },
        {
            "file": "/var/www/vendor/ulobby/neoeloquent/src/Query/Builder.php",
            "line": 975,
            "function": "runSelect",
            "class": "Vinelab\\NeoEloquent\\Query\\Builder",
            "type": "->"
        },
        {
            "file": "/var/www/vendor/ulobby/neoeloquent/src/Query/Builder.php",
            "line": 257,
            "function": "get",
            "class": "Vinelab\\NeoEloquent\\Query\\Builder",
            "type": "->"
        },
        {
            "file": "/var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php",
            "line": 808,
            "function": "getCountForPagination",
            "class": "Vinelab\\NeoEloquent\\Query\\Builder",
            "type": "->"
        },
berteltorp commented 2 years ago

Haven't tried telescope - but can recommend clockwork as replacement https://github.com/itsgoingd/clockwork

screw commented 2 years ago

Haven't tried telescope - but can recommend clockwork as replacement https://github.com/itsgoingd/clockwork

Thank you, that looks great. I'll give it a try. And just to be clear, you know clockwork works with NeoEloquent (and the new Laudis/neo4jphp client)?