@@ -52,8 +52,10 @@ def __init__(self, graph, response):
5252 self .parse_statistics (response [0 ])
5353 else :
5454 # start by parsing statistics, matches the one we have
55- self .parse_statistics (response [- 1 ]) # Last element.
55+ self .parse_statistics (response [2 ]) # Third element, after header and records .
5656 self .parse_results (response )
57+ if len (response ) == 4 :
58+ self .parse_metadata (response [3 ])
5759
5860 def _check_for_errors (self , response ):
5961 if isinstance (response [0 ], ResponseError ):
@@ -89,6 +91,36 @@ def parse_statistics(self, raw_statistics):
8991 if v is not None :
9092 self .statistics [s ] = v
9193
94+ def parse_metadata (self , raw_metadata ):
95+ # Decode metadata:
96+ # [
97+ # ["version", VERSION],
98+ # ["labels", [[VALUE_STRING, "label_1"] ... ]],
99+ # ["relationship types ", [[VALUE_STRING, "reltype_1"] ... ]],
100+ # ["property keys", [[VALUE_STRING, "prop_1"] ... ]]
101+ # ]
102+ version = raw_metadata [0 ][1 ]
103+ raw_labels = raw_metadata [1 ][1 ]
104+ raw_reltypes = raw_metadata [2 ][1 ]
105+ raw_props = raw_metadata [3 ][1 ]
106+
107+ # Arrays to be passed into the internal graph structure.
108+ labels = [None ] * len (raw_labels )
109+ reltypes = [None ] * len (raw_reltypes )
110+ properties = [None ] * len (raw_props )
111+
112+ for idx , label in enumerate (raw_labels ):
113+ labels [idx ] = self .parse_scalar (label )
114+
115+ for idx , reltype in enumerate (raw_reltypes ):
116+ reltypes [idx ] = self .parse_scalar (reltype )
117+
118+ for idx , prop in enumerate (raw_props ):
119+ properties [idx ] = self .parse_scalar (prop )
120+
121+ # Update the graph's internal metadata.
122+ self .graph .refresh_metadata (version , labels , reltypes , properties )
123+
92124 def parse_header (self , raw_result_set ):
93125 # An array of column name/column type pairs.
94126 header = raw_result_set [0 ]
0 commit comments