Skip to content

Commit

Permalink
Remove direct access of Neo4j::Driver result data
Browse files Browse the repository at this point in the history
The undocumented internal data structure of the Neo4j::Driver::Result module may differ between driver versions, between server versions, and between result formats (Bolt/Jolt/JSON). Direct access is possible, but brittle.

At the same time, the REST action URIs are not even supported anymore in Neo4j 4. Therefore, they won't change in future and hard-coding them here is not a problem.
  • Loading branch information
johannessen committed Jan 31, 2021
1 parent 9589d0e commit 088829b
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions lib/REST/Neo4p/Agent/Neo4j/Driver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ my $WARN_ON_ERROR;
BEGIN {
}

my %REST_ACTIONS = (
all_relationships => 'relationships/all',
all_typed_relationships => 'relationships/all/{-list|&|types}',
create_relationship => 'relationships',
incoming_relationships => 'relationships/in',
incoming_typed_relationships => 'relationships/in/{-list|&|types}',
labels => 'labels',
outgoing_relationships => 'relationships/out',
outgoing_typed_relationships => 'relationships/out/{-list|&|types}',
paged_traverse => 'paged/traverse/{returnType}{?pageSize,leaseTime}',
properties => 'properties',
property => 'properties/{key}',
traverse => 'traverse/{returnType}',
);

sub new {
my ($class, @args) = @_;
my $self = {
Expand Down Expand Up @@ -177,21 +192,7 @@ sub connect {
last if $f;
}
# set actions
try {
my $tx = $self->session->begin_transaction;
my $n = $tx->run('create (n) return n')->single;
my $actions = $n->{rest}[0];
$tx->rollback;
foreach (keys %$actions) {
next if /^extensions|metadata|self$/;
# strip any trailing slash
$actions->{$_} =~ s|/+$||;
my ($suffix) = $actions->{$_} =~ m|.*node/[0-9]+/(.*)|;
$self->{_actions}{$_} = $suffix;
}
} catch {
REST::Neo4p::LocalException->throw("While determining actions: $_");
};
$self->{_actions}{$_} = $REST_ACTIONS{$_} for keys %REST_ACTIONS;
return 1;
}

Expand Down

0 comments on commit 088829b

Please sign in to comment.