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

Popular Prag Prog topics Top

jimschubert
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
New
Razor54672
The answer to 3rd Problem of Chapter 5 (Making Choices) of “Practical Programming, Third Edition” seems incorrect in the given answer ke...
New
jamis
The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=&gt; (create-...
New
HarryDeveloper
Hi @venkats, It has been mentioned in the description of ‘Supervisory Job’ title that 2 things as mentioned below result in the same eff...
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
adamwoolhether
When trying to generate the protobuf .go file, I receive this error: Unknown flag: --go_opt libprotoc 3.12.3 MacOS 11.3.1 Googling ...
New
AndyDavis3416
@noelrappin Running the webpack dev server, I receive the following warning: ERROR in tsconfig.json TS18003: No inputs were found in c...
New
New
AufHe
I’m a newbie to Rails 7 and have hit an issue with the bin/Dev script mentioned on pages 112-113. Iteration A1 - Seeing the list of prod...
New

Other popular topics Top

AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
New
AstonJ
I have seen the keycaps I want - they are due for a group-buy this week but won’t be delivered until October next year!!! :rofl: The Ser...
New
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
PragmaticBookshelf
Author Spotlight Mike Riley @mriley This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New

Latest in PragProg

View all threads ❯