Skip to content
This repository was archived by the owner on Feb 23, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4ecd597
Fix name of AQL endpoint
waxlamp Aug 20, 2019
afe1469
Replace some graphql endpoints with new REST endpoints
waxlamp Aug 20, 2019
e0c8206
Add endpoint to get rows of a particular table
waxlamp Aug 21, 2019
6629029
Add a graph detail endpoint
waxlamp Aug 22, 2019
b44d84d
Add endpoints for retreiving data from a graph
waxlamp Aug 22, 2019
62d6597
Remove GraphQL
waxlamp Aug 22, 2019
ed22999
Remove GraphiQL app
waxlamp Aug 22, 2019
6160bc0
Replace references to `sys` with `sysdb`
jjnesbitt Aug 23, 2019
50bb632
Eliminate dead code from db.py
waxlamp Aug 23, 2019
b4ce5fc
Use flask exception handler to avoid repeated checks
waxlamp Aug 25, 2019
4055f2e
Merge remote-tracking branch 'origin/master' into remove-graphql
waxlamp Aug 25, 2019
22a1b22
Rename `sys` to `sysdb`
waxlamp Aug 26, 2019
bf574d4
Remove legacy functions used with graphql
waxlamp Aug 26, 2019
16ba7aa
Use a function to return streaming responses
waxlamp Aug 26, 2019
a620afd
Reformat list comprehension
waxlamp Aug 26, 2019
52ad667
Remove obsolete function
waxlamp Aug 26, 2019
26ac2fa
Use more targeted NotFound exceptions
waxlamp Aug 26, 2019
3882875
Enable filtering tables by type
waxlamp Aug 26, 2019
a28c4c7
Split apart "path" node argument into table and node
waxlamp Aug 26, 2019
2e2201a
Return structured response for single workspace
waxlamp Aug 26, 2019
5c8b1af
Retrieve a singular edge collection
waxlamp Aug 26, 2019
efc366e
Refactor repeated code
waxlamp Aug 26, 2019
e25a1b9
Use appropriate error exception instead of RuntimeError
waxlamp Aug 26, 2019
4ad2cdf
Reformat code
waxlamp Aug 26, 2019
3109162
Remove stray bad test code
waxlamp Aug 26, 2019
f13b2c4
Split "GET graph" endpoint into base info and nodes
waxlamp Aug 26, 2019
8387e8a
Swap out "data" for "attributes" in endpoint name
waxlamp Aug 26, 2019
3700423
Use more error exception types
waxlamp Aug 26, 2019
5384a5c
Fix bad endpoint in client
waxlamp Aug 26, 2019
9ef777d
Add dummy "writers" field to workspace response
waxlamp Aug 26, 2019
8f84c6d
Fix linting errors
waxlamp Aug 26, 2019
f1daea8
Move utility functions into own module
waxlamp Aug 26, 2019
7e735f5
Update client to use new node API
waxlamp Aug 27, 2019
648d653
Include table name when matching node edges in database
waxlamp Aug 27, 2019
9543550
Use error exceptions in remaining instances
waxlamp Aug 27, 2019
56e8914
Fix typo in exception invocation
waxlamp Aug 27, 2019
1d3dbdb
Invoke TableNotFound() correctly
waxlamp Aug 27, 2019
329cb5e
Invoke GraphNotFound() correctly
waxlamp Aug 27, 2019
d4baec0
Merge branch 'master' into remove-graphql
waxlamp Aug 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enable filtering tables by type
  • Loading branch information
waxlamp committed Aug 26, 2019
commit 3882875dada239efc8d28b2859dd55fde429ebd1
14 changes: 7 additions & 7 deletions client/src/views/WorkspaceDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ export default {
methods: {
async update () {
// Get lists of node and edge tables.
let response = await api().get(`workspaces/${this.workspace}/tables?fields=true`);
const tables = response.data;
let response = await api().get(`workspaces/${this.workspace}/tables?type=node`);
const nodeTables = response.data;

const nodeTable = table => table.fields.indexOf('_from') === -1 || table.fields.indexOf('_to') === -1;
const edgeTable = table => table.fields.indexOf('_from') > -1 && table.fields.indexOf('_to') > -1;
response = await api().get(`workspaces/${this.workspace}/tables?type=edge`);
const edgeTables = response.data;

this.tables = tables.map(d => d.table);
this.nodeTables = tables.filter(nodeTable).map(d => d.table);
this.edgeTables = tables.filter(edgeTable).map(d => d.table);
this.tables = nodeTables.concat(edgeTables);
this.nodeTables = nodeTables;
this.edgeTables = edgeTables;

// Get list of graphs.
response = await api().get(`workspaces/${this.workspace}/graphs`);
Expand Down
6 changes: 3 additions & 3 deletions multinet/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def get_workspace(workspace):


@bp.route("/workspaces/<workspace>/tables", methods=["GET"])
@use_kwargs({"fields": fields.Str()})
def get_workspace_tables(workspace, fields=""):
@use_kwargs({"type": fields.Str()})
def get_workspace_tables(workspace, type="all"):
"""Retrieve the tables of a single workspace."""
tables = db.workspace_tables(workspace, fields)
tables = db.workspace_tables(workspace, type)
return stream(tables)


Expand Down
34 changes: 23 additions & 11 deletions multinet/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from arango.exceptions import DatabaseCreateError
from requests.exceptions import ConnectionError

from .errors import WorkspaceNotFound, TableNotFound, GraphNotFound, NodeNotFound
from .errors import BadQueryArgument, WorkspaceNotFound, TableNotFound, GraphNotFound, NodeNotFound


def with_client(fun):
Expand Down Expand Up @@ -109,28 +109,40 @@ def get_workspaces(arango=None):
"""Return a list of all workspace names."""
sysdb = db("_system", arango=arango)
return (
{"name": workspace, "owner": None, "read": []}
workspace
for workspace in sysdb.databases()
if workspace != "_system"
)


@with_client
def workspace_tables(workspace, fields=True, arango=None):
def workspace_tables(workspace, type, arango=None):
"""Return a list of all table names in the workspace named `workspace`."""

def edge_table(fields):
return "_from" in fields and "_to" in fields

space = get_workspace_db(workspace, arango=arango)
tables = [
{"table": table["name"]}
tables = (
(table["name"], edge_table(table_fields(workspace, table["name"], arango=arango)))
for table in space.collections()
if not table["name"].startswith("_")
]
)

if fields:
for table in tables:
fields = table_fields(workspace, table["table"])
table["fields"] = fields
if type == "all":
desired_type = lambda x: True
elif type == "node":
desired_type = lambda x: not x[1]
elif type == "edge":
desired_type = lambda x: x[1]
else:
raise BadQueryArgument("type", type, ["all", "node", "edge"])

return tables
return (
table[0]
for table in tables
if desired_type(table)
)


@with_client
Expand Down
20 changes: 20 additions & 0 deletions multinet/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,23 @@ class NodeNotFound(NotFound):
def __init__(self, table, node):
"""Initialize the exception."""
super().__init__("Node", f"{table}/{node}")


class BadQueryArgument(ServerError):
"""Exception for illegal query argument value."""

def __init__(self, argument, value, allowed=[]):
self.argument = argument
self.value = value
self.allowed = allowed

def flask_response(self):
payload = {
"argument": self.argument,
"value": self.value,
}

if (self.allowed):
payload["allowed"] = self.allowed

return (payload, "400 Bad Query Argument")