2929from SPARQLWrapper import SPARQLWrapper
3030from botocore .session import get_session
3131from gremlin_python .driver .protocol import GremlinServerError
32+ from gremlin_python .structure .graph import Path
3233from IPython .core .display import HTML , display_html , display
3334from IPython .core .magic import (Magics , magics_class , cell_magic , line_magic , line_cell_magic , needs_local_scope )
3435from ipywidgets .widgets .widget_description import DescriptionStyle
@@ -809,15 +810,15 @@ def gremlin(self, line, cell, local_ns: dict = None):
809810 parser .add_argument ('--explain-type' , type = str .lower , default = '' ,
810811 help = 'Explain mode to use when using the explain query mode.' )
811812 parser .add_argument ('-p' , '--path-pattern' , default = '' , help = 'path pattern' )
812- parser .add_argument ('-g' , '--group-by' , type = str , default = 'T.label ' ,
813+ parser .add_argument ('-g' , '--group-by' , type = str , default = '' ,
813814 help = 'Property used to group nodes (e.g. code, T.region) default is T.label' )
814815 parser .add_argument ('-gd' , '--group-by-depth' , action = 'store_true' , default = False ,
815816 help = "Group nodes based on path hierarchy" )
816817 parser .add_argument ('-gr' , '--group-by-raw' , action = 'store_true' , default = False ,
817818 help = "Group nodes by the raw result" )
818- parser .add_argument ('-d' , '--display-property' , type = str , default = 'T.label ' ,
819+ parser .add_argument ('-d' , '--display-property' , type = str , default = '' ,
819820 help = 'Property to display the value of on each node, default is T.label' )
820- parser .add_argument ('-de' , '--edge-display-property' , type = str , default = 'T.label ' ,
821+ parser .add_argument ('-de' , '--edge-display-property' , type = str , default = '' ,
821822 help = 'Property to display the value of on each edge, default is T.label' )
822823 parser .add_argument ('-t' , '--tooltip-property' , type = str , default = '' ,
823824 help = 'Property to display the value of on each node tooltip. If not specified, tooltip '
@@ -937,8 +938,16 @@ def gremlin(self, line, cell, local_ns: dict = None):
937938 else :
938939 first_tab_html = pre_container_template .render (content = 'No profile found' )
939940 else :
941+ using_http = False
940942 query_start = time .time () * 1000 # time.time() returns time in seconds w/high precision; x1000 to get in ms
941- query_res = self .client .gremlin_query (cell , transport_args = transport_args )
943+ if self .graph_notebook_config .proxy_host != '' and self .client .is_neptune_domain ():
944+ using_http = True
945+ query_res_http = self .client .gremlin_http_query (cell , headers = {'Accept' : 'application/vnd.gremlin-v1.0+json;types=false' })
946+ query_res_http .raise_for_status ()
947+ query_res_http_json = query_res_http .json ()
948+ query_res = query_res_http_json ['result' ]['data' ]
949+ else :
950+ query_res = self .client .gremlin_query (cell , transport_args = transport_args )
942951 query_time = time .time () * 1000 - query_start
943952 if not args .silent :
944953 gremlin_metadata = build_gremlin_metadata_from_query (query_type = 'query' , results = query_res ,
@@ -952,18 +961,30 @@ def gremlin(self, line, cell, local_ns: dict = None):
952961 logger .debug (f'edge_display_property: { args .edge_display_property } ' )
953962 logger .debug (f'label_max_length: { args .label_max_length } ' )
954963 logger .debug (f'ignore_groups: { args .ignore_groups } ' )
955- gn = GremlinNetwork (group_by_property = args .group_by , display_property = args .display_property ,
964+ gn = GremlinNetwork (group_by_property = args .group_by ,
965+ display_property = args .display_property ,
956966 group_by_raw = args .group_by_raw ,
957967 group_by_depth = args .group_by_depth ,
958968 edge_display_property = args .edge_display_property ,
959969 tooltip_property = args .tooltip_property ,
960970 edge_tooltip_property = args .edge_tooltip_property ,
961971 label_max_length = args .label_max_length ,
962972 edge_label_max_length = args .edge_label_max_length ,
963- ignore_groups = args .ignore_groups )
973+ ignore_groups = args .ignore_groups ,
974+ using_http = using_http )
975+
976+ if using_http and 'path()' in cell and query_res :
977+ first_path = query_res [0 ]
978+ if isinstance (first_path , dict ) and first_path .keys () == {'labels' , 'objects' }:
979+ query_res_to_path_type = []
980+ for path in query_res :
981+ new_path_list = path ['objects' ]
982+ new_path = Path (labels = [], objects = new_path_list )
983+ query_res_to_path_type .append (new_path )
984+ query_res = query_res_to_path_type
964985
965986 if args .path_pattern == '' :
966- gn .add_results (query_res )
987+ gn .add_results (query_res , is_http = using_http )
967988 else :
968989 pattern = parse_pattern_list_str (args .path_pattern )
969990 gn .add_results_with_pattern (query_res , pattern )
0 commit comments