mvellandi

mvellandi

Exploring Graphs with Elixir: Missing behaviour import, struct, cypher file (p.181)

Exploring Graphs with Elixir by @tonyhammond: P.181 — Ch 5 > Setting Up a Graph Service > API Demo

After starting iex in the umbrella project, then importing PropertyGraph, we are told to call:

iex>​​ ​​default_graph​​ ​​=​​ ​​read_graph(​​"default.cypher"​​)​
​ 	​#GraphCommons.Graph<type: property, file: "...", data: "CREATE (a)-[:EX]...">

However, read_graph hasn’t been defined yet.
We need to first add the following to the PropertyGraph module:

use GraphCommons.Graph, graph_type: :property, graph_module: __MODULE__

From that read_graph call, I don’t recall creating nor seeing the “default.cypher” in the source codebase:
graph_commons/priv/storage/property/graphs/default.cypher

I believe perhaps a cypher file with the following should work:

CREATE (a)-[:EX]->(b)

Shortly later, we call:

iex>​​ ​​graph_info​
​%GraphCommons.Service.GraphInfo{
​ 	  labels: [],
​ 	  num_edges: 1,
​ 	  num_nodes: 2,
​ 	  type: :property
​}

For me, this returned an undefined function error for PropertyGraph.new_query/1
So I looked at the definition of graph_info/0 in the book’s previous section on p.182

def​ graph_info() ​do​
​ 	  {​:ok​, [stats]} =
​ 	    @cypher_info
​ 	    |> PropertyGraph.new_query()
​ 	    |> query_graph
​ 	
​ 	  %GraphCommons.Service.GraphInfo{
​ 	    ​type:​ ​:property​,
​ 	    ​num_nodes:​ stats[​"​​nodeCount"​],
​ 	    ​num_edges:​ stats[​"​​relCount"​],
​ 	    ​labels:​ Map.keys(stats[​"​​labels"​])
​ 	  }
​ end

I noticed
1:
Although GraphCommons.Query hasn’t been formally defined, by duplicating GraphCommons.Graph to GraphCommons.Query
and changing “graph” to “query” references and checking the module’s source codebase, we should have a new_query/3 function.

However, PropertyGraph.new_query is called here with only 2 out of 3 arguments: @cypher_info and (implicitly) the query_type
Is there a missing argument for query_file ?
I couldn’t figure this out.

2:
And for graph_info/0 to return a %GraphCommons.Service.GraphInfo{} struct, I believe we need to first define the module which I didn’t see in the source codebase. So I made one here:
graph_commons/lib/graph_commons/service/graph_info.ex

Searching the source codebase for GraphInfo structs, I found the following attributes variously used, and so defined the module as follows:

defmodule GraphCommons.Service.GraphInfo do
    defstruct ~w[type num_nodes num_edges labels density file]a
end

First Post!

mvellandi

mvellandi

Regarding #1 above, getting PropertyGraph.new_query to work with one or two arguments:
I revised the definition of “using” macro in GraphCommons.Query to use a default arg:

def new_query(query_data, query_file \\ "") do
   if unquote(query_type) in [:dgraph, :native, :property, :rdf, :tinker] do
      GraphCommons.Query.new(query_data, query_file, unquote(query_type))
   end
end

Simple fix.
A code editor’s language server may need some time to recognize this as not an issue.

If you now run PropertyGraph.graph_info/0 again and get this next error below (like I did):

{ :error,
   %Bolt.Sips.Error{
      code: "Neo.ClientError.Procedure.ProcedureNotFound", 
      message: "There is no procedure with the name `apoc.meta.stats` registered for this database instance. Please ensure you've spelled the procedure name correctly and that the procedure is properly deployed."
   }
}

It means APOC-Core, included with Neo4j, hasn’t been added as a plugin.
Lastly, the Neo4j security settings configuration may need a one-line config for enabling plugin/other resource full database access.
I’ve written another post on DevTalk with how I installed Neo4j on OSX.

Cheers

Where Next?

Popular Pragmatic Bookshelf topics Top

jimmykiang
This test is broken right out of the box… — FAIL: TestAgent (7.82s) agent_test.go:77: Error Trace: agent_test.go:77 agent_test.go:...
New
iPaul
page 37 ANTLRInputStream input = new ANTLRInputStream(is); as of ANTLR 4 .8 should be: CharStream stream = CharStreams.fromStream(i...
New
belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
brianokken
Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not decl...
New
jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
New
ianwillie
Hello Brian, I have some problems with running the code in your book. I like the style of the book very much and I have learnt a lot as...
New
cro
I am working on the “Your Turn” for chapter one and building out the restart button talked about on page 27. It recommends looking into ...
New
rmurray10127
Title: Intuitive Python: docker run… denied error (page 2) Attempted to run the docker command in both CLI and Powershell PS C:\Users\r...
New
jskubick
I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint. As entered, the SwitchCompat changes color to hol...
New
Charles
In general, the book isn’t yet updated for Phoenix version 1.6. On page 18 of the book, the authors indicate that an auto generated of ro...
New

Other popular topics Top

siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
AstonJ
I’ve been hearing quite a lot of comments relating to the sound of a keyboard, with one of the most desirable of these called ‘thock’, he...
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1142 25765 758
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
PragmaticBookshelf
Author Spotlight Rebecca Skinner @RebeccaSkinner Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New
PragmaticBookshelf
Develop, deploy, and debug BEAM applications using BEAMOps: a new paradigm that focuses on scalability, fault tolerance, and owning each ...
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New

Sub Categories: