Skip to content

Commit

Permalink
Merge f7220ee into 209b9b1
Browse files Browse the repository at this point in the history
  • Loading branch information
pmantica1 committed Nov 12, 2019
2 parents 209b9b1 + f7220ee commit 57a8d02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from .edge_descriptors import validate_edge_descriptors
from .scalar_type_mapper import try_get_graphql_scalar_type
from .utils import (
validate_that_tables_belong_to_the_same_metadata_object, validate_that_tables_have_primary_keys
validate_that_sqlalchemy_tables_have_a_single_vertex_name,
validate_that_tables_belong_to_the_same_metadata_object,
validate_that_tables_have_primary_keys
)


Expand All @@ -35,6 +37,7 @@ def get_sqlalchemy_schema_graph(vertex_name_to_table, direct_edges):
validate_that_tables_belong_to_the_same_metadata_object(vertex_name_to_table.values())
validate_edge_descriptors(vertex_name_to_table, direct_edges)
validate_that_tables_have_primary_keys(vertex_name_to_table.values())
validate_that_sqlalchemy_tables_have_a_single_vertex_name(vertex_name_to_table)

vertex_types = {
vertex_name: _get_vertex_type_from_sqlalchemy_table(vertex_name, table)
Expand Down
13 changes: 13 additions & 0 deletions graphql_compiler/schema_generation/sqlalchemy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ def validate_that_tables_have_primary_keys(tables):
.format(table.name, table.schema))


def validate_that_sqlalchemy_tables_have_a_single_vertex_name(vertex_name_to_table):
"""Validate that each SQLAlchemy Table has only one corresponding vertex type name."""
table_to_vertex_name = {}

for vertex_name, table in vertex_name_to_table.items():
if table in table_to_vertex_name:
other_vertex_name = vertex_name_to_table[table]
raise AssertionError('Table {} is associated with multiple vertex types: {} and {}.'
.format(table.fullname, vertex_name, other_vertex_name))
else:
table_to_vertex_name[table] = vertex_name


def validate_that_tables_belong_to_the_same_metadata_object(tables):
"""Validate that all the SQLAlchemy Table objects belong to the same MetaData object."""
metadata = None
Expand Down

0 comments on commit 57a8d02

Please sign in to comment.