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

**URL:** <https://forum.devtalk.com/t/exploring-graphs-with-elixir-missing-behaviour-import-struct-cypher-file-p-181/9206>\
**Category:** PragProg Customers\
**Tags:** book-exploring-graphs-with-elixir, errata\
**Created:** [30 April 2021 13:09 UTC](https://forum.devtalk.com/t/exploring-graphs-with-elixir-missing-behaviour-import-struct-cypher-file-p-181/9206 "2021-04-30T13:09:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mvellandi](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mvellandi/32/2726_2.png) [@mvellandi](https://forum.devtalk.com/u/mvellandi)\
**Post date:** [30 April 2021 13:09 UTC](https://forum.devtalk.com/t/exploring-graphs-with-elixir-missing-behaviour-import-struct-cypher-file-p-181/9206/1 "2021-04-30T13:09:13Z")

</div>

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:

```auto
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:

```auto
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:

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

```

Shortly later, we call:

```auto
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

```auto
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:

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

```

---

<div class="post-metadata">

**Author:** ![mvellandi](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mvellandi/32/2726_2.png) [@mvellandi](https://forum.devtalk.com/u/mvellandi)\
**Post date:** [3 May 2021 21:50 UTC](https://forum.devtalk.com/t/exploring-graphs-with-elixir-missing-behaviour-import-struct-cypher-file-p-181/9206/2 "2021-05-03T21:50:30Z")

</div>

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:

```auto
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):

```auto
{ :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
