Skip to content

Commit

Permalink
Merge 1cbb24a into 7c5fcb7
Browse files Browse the repository at this point in the history
  • Loading branch information
pmantica1 committed May 8, 2019
2 parents 7c5fcb7 + 1cbb24a commit 0a17606
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
28 changes: 15 additions & 13 deletions graphql_compiler/schema_generation/schema_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .schema_properties import (
COLLECTION_PROPERTY_TYPES, ILLEGAL_PROPERTY_NAME_PREFIXES, ORIENTDB_BASE_EDGE_CLASS_NAME,
ORIENTDB_BASE_VERTEX_CLASS_NAME, PROPERTY_TYPE_LINK_ID, PropertyDescriptor,
get_graphql_scalar_type_or_raise, parse_default_property_value
parse_default_property_value, try_get_graphql_scalar_type
)
from .utils import toposort_classes

Expand Down Expand Up @@ -615,20 +615,21 @@ def _get_element_properties(self, class_name, non_link_property_definitions):
u'more than once, this is not allowed!'
.format(property_name, class_name))

graphql_type = self._get_graphql_type(class_name, property_definition)
default_value = _get_default_value(class_name, property_definition)
property_descriptor = PropertyDescriptor(graphql_type, default_value)
property_name_to_descriptor[property_name] = property_descriptor
maybe_graphql_type = self._try_get_graphql_type(class_name, property_definition)
if maybe_graphql_type is None:
default_value = _get_default_value(class_name, property_definition)
property_descriptor = PropertyDescriptor(maybe_graphql_type, default_value)
property_name_to_descriptor[property_name] = property_descriptor
return property_name_to_descriptor

def _get_graphql_type(self, class_name, property_definition):
"""Return the GraphQLType corresponding to the non-link property definition."""
def _try_get_graphql_type(self, class_name, property_definition):
"""Return the matching GraphQLType for the non-link property or None if none exists."""
name = property_definition['name']
type_id = property_definition['type']
linked_class = property_definition.get('linkedClass', None)
linked_type = property_definition.get('linkedType', None)

graphql_type = None
maybe_graphql_type = None
if type_id == PROPERTY_TYPE_LINK_ID:
raise AssertionError(u'Found a improperly named property of type Link: '
u'{} {}. Links must be named either "in" or "out"'
Expand All @@ -639,8 +640,9 @@ def _get_graphql_type(self, class_name, property_definition):
u'a linked type: {}'.format(name, property_definition))
elif linked_type is not None and linked_class is None:
# No linked class, must be a linked native OrientDB type.
inner_type = get_graphql_scalar_type_or_raise(name + ' inner type', linked_type)
graphql_type = GraphQLList(inner_type)
maybe_inner_type = try_get_graphql_scalar_type(name + ' inner type', linked_type)
if maybe_inner_type is None:
maybe_graphql_type = GraphQLList(maybe_inner_type)
elif linked_class is not None and linked_type is None:
# No linked type, must be a linked non-graph user-defined type.
if linked_class not in self._non_graph_class_names:
Expand All @@ -654,15 +656,15 @@ def _get_graphql_type(self, class_name, property_definition):
.format(class_name, property_definition))
# Don't include the fields and implemented interfaces, this information is already
# stored in the SchemaGraph.
graphql_type = GraphQLList(GraphQLObjectType(linked_class, {}, []))
maybe_graphql_type = GraphQLList(GraphQLObjectType(linked_class, {}, []))
else:
raise AssertionError(u'Property "{}" is an embedded collection but has '
u'neither a linked class nor a linked type: '
u'{}'.format(name, property_definition))
else:
graphql_type = get_graphql_scalar_type_or_raise(name, type_id)
maybe_graphql_type = try_get_graphql_scalar_type(name, type_id)

return graphql_type
return maybe_graphql_type

def _link_vertex_and_edge_types(self):
"""For each edge, link it to the vertex types it connects to each other."""
Expand Down
14 changes: 8 additions & 6 deletions graphql_compiler/schema_generation/schema_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import namedtuple
import datetime
import time
import warnings

from graphql.type import GraphQLBoolean, GraphQLFloat, GraphQLInt, GraphQLString
import six
Expand Down Expand Up @@ -111,12 +112,13 @@
ORIENTDB_DATE_FORMAT = '%Y-%m-%d'


def get_graphql_scalar_type_or_raise(property_name, property_type_id):
"""Return the matching GraphQLScalarType for the property type id, asserting it exists."""
if property_type_id not in ORIENTDB_TO_GRAPHQL_SCALARS:
raise AssertionError(u'Property "{}" has unsupported property type id: '
u'{}'.format(property_name, property_type_id))
return ORIENTDB_TO_GRAPHQL_SCALARS[property_type_id]
def try_get_graphql_scalar_type(property_name, property_type_id):
"""Return the matching GraphQLScalarType for the property type id or None if none exists."""
maybe_graphql_type = ORIENTDB_TO_GRAPHQL_SCALARS.get(property_type_id, None)
if not maybe_graphql_type:
warnings.warn(u'Ignoring property "{}" with unsupported property type id: 'u'{}'
.format(property_name, property_type_id))
return maybe_graphql_type


def _parse_bool_default_value(property_name, default_value_string):
Expand Down

0 comments on commit 0a17606

Please sign in to comment.