Skip to content

Commit

Permalink
Add redirect messaging for service-restricted Neptune magics (#643)
Browse files Browse the repository at this point in the history
* Add redirect messaging for service-restricted Neptune magics

* update changelog
  • Loading branch information
michaelnchin authored Jul 13, 2024
1 parent 94ae6b2 commit 6c6ecd5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd
- Path: 01-Neptune-Database > 03-Sample-Applications > 07-Games-Industry-Graphs
- Added `--connected-table` option to magics with table widget output ([Link to PR](https://github.com/aws/graph-notebook/pull/634))
- Added `--silent` option to the `%%graph_notebook_config` line and cell magics ([Link to PR](https://github.com/aws/graph-notebook/pull/641))
- Added helpful redirect messaging for service-specific Neptune magics ([Link to PR](https://github.com/aws/graph-notebook/pull/643))
- Changed `%%gremlin --store-to` to also store exceptions from non-Neptune queries ([Link to PR](https://github.com/aws/graph-notebook/pull/635))
- Fixed broken `--help` option for `%%gremlin` ([Link to PR](https://github.com/aws/graph-notebook/pull/630))
- Fixed openCypher query bug regression in the [`01-About-the-Neptune-Notebook`](https://github.com/aws/graph-notebook/blob/main/src/graph_notebook/notebooks/01-Getting-Started/01-About-the-Neptune-Notebook.ipynb) sample ([Link to PR](https://github.com/aws/graph-notebook/pull/631))
Expand Down
17 changes: 17 additions & 0 deletions src/graph_notebook/decorators/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
check_if_access_regex = re.compile(r'^[a-zA-Z0-9_]+((\[\'.*?\'\])|(\[\".*?\"\])|(\[.*?\]))+$')
var_name_regex = re.compile(r'^[^\[]*')

db_to_graph_redirects = {
"statistics": "summary",
"db_reset": "graph_reset"
}

graph_to_db_redirects = {
"get_graph": "status",
"reset_graph": "db_reset",
"graph_reset": "db_reset"
}


def get_variable_injection_name_and_indices(raw_var: str, keys_are_str: bool = True):
# get the name of the dict
Expand Down Expand Up @@ -138,12 +149,15 @@ def neptune_db_only(func):
@functools.wraps(func)
def check_neptune_db(*args, **kwargs):
self = args[0]
magic_name = func.__name__
if not hasattr(self.graph_notebook_config, 'neptune_service'):
return func(*args, **kwargs)
else:
service_type = self.graph_notebook_config.neptune_service
if service_type == NEPTUNE_ANALYTICS_SERVICE_NAME:
print(f'This magic is unavailable for Neptune Analytics.')
if magic_name in db_to_graph_redirects:
print(f'\nPlease use %{db_to_graph_redirects[magic_name]} instead.')
return
else:
return func(*args, **kwargs)
Expand All @@ -155,12 +169,15 @@ def neptune_graph_only(func):
@functools.wraps(func)
def check_neptune_graph(*args, **kwargs):
self = args[0]
magic_name = func.__name__
if not hasattr(self.graph_notebook_config, 'neptune_service'):
return func(*args, **kwargs)
else:
service_type = self.graph_notebook_config.neptune_service
if service_type == NEPTUNE_DB_SERVICE_NAME:
print(f'This magic is unavailable for Neptune DB.')
if magic_name in graph_to_db_redirects:
print(f'\nPlease use %{graph_to_db_redirects[magic_name]} instead.')
return
else:
return func(*args, **kwargs)
Expand Down

0 comments on commit 6c6ecd5

Please sign in to comment.