signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def setUp(self): | self.maxDiff = None<EOL>self.schema = get_schema()<EOL>_, sqlalchemy_metadata = get_animal_schema_sql_metadata()<EOL>self.sql_metadata = SqlMetadata(sqlite.dialect.name, sqlalchemy_metadata)<EOL> | Disable max diff limits for all tests. | f12632:c0:m0 |
def get_function_names_from_module(module): | return {<EOL>member<EOL>for member, member_type in getmembers(module)<EOL>if isfunction(member_type)<EOL>}<EOL> | Return a set of function names present in a given module. | f12633:m0 |
def load_schema(client): | project_root = path.dirname(path.dirname(path.abspath(__file__)))<EOL>file_path = path.join(project_root, '<STR_LIT>')<EOL>sql_files = glob(file_path)<EOL>if len(sql_files) > <NUM_LIT:1>:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>')<EOL><DEDENT>if len(sql_files) == <NUM_LIT:0> or sql_files[<NUM_LIT:0... | Read the schema file and apply the specified SQL updates to the client. | f12635:m0 |
def generate_orient_snapshot_data(client): | project_root = path.dirname(path.abspath(__file__))<EOL>sql_files = glob(path.join(project_root, '<STR_LIT>'))<EOL>_load_sql_files_to_orient_client(client, sql_files)<EOL> | Create OrientDB test DB from the SQL commands file for snapshot testing. | f12636:m0 |
def generate_orient_integration_data(client): | project_root = path.dirname(path.abspath(__file__))<EOL>sql_files = glob(path.join(project_root, '<STR_LIT>'))<EOL>_load_sql_files_to_orient_client(client, sql_files)<EOL> | Create OrientDB test DB from the SQL commands file for snapshot testing. | f12636:m1 |
def _load_sql_files_to_orient_client(client, sql_files): | for filepath in sql_files:<EOL><INDENT>with open(filepath) as f:<EOL><INDENT>for command in f.readlines():<EOL><INDENT>sanitized_command = command.strip()<EOL>if len(sanitized_command) == <NUM_LIT:0> or sanitized_command[<NUM_LIT:0>] == '<STR_LIT:#>':<EOL><INDENT>continue<EOL><DEDENT>client.command(sanitized_command)<E... | Load list of supplied SQL files into the supplied OrientDB client. | f12636:m2 |
def get_animal_schema_sql_metadata(): | metadata = MetaData()<EOL>animal_table = Table(<EOL>'<STR_LIT>',<EOL>metadata,<EOL>Column('<STR_LIT>', String(<NUM_LIT>), primary_key=True),<EOL>Column('<STR_LIT:name>', String(length=<NUM_LIT:12>), nullable=False),<EOL>Column('<STR_LIT>', Numeric, nullable=False),<EOL>Column('<STR_LIT>', Date, nullable=False),<EOL>)<E... | Return Dict[str, Table] table lookup, and associated metadata, for the Animal test schema. | f12636:m6 |
def get_orientdb_url(database_name): | template = '<STR_LIT>'<EOL>return template.format(ORIENTDB_SERVER, database_name)<EOL> | Return an OrientDB path for the specified database on the ORIENTDB_SERVER. | f12638:m0 |
def recursive_field_type_is_subtype_of_parent_field(): | graphql_input = '''<STR_LIT>'''<EOL>expected_output_metadata = {<EOL>'<STR_LIT>': OutputMetadata(type=GraphQLString, optional=False),<EOL>}<EOL>expected_input_metadata = {}<EOL>type_equivalence_hints = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>return CommonTestData(<EOL>graphql_input=graphql_input,<EOL>expected_output_... | Ensure that recursion is allowed along an edge linked to a supertype of the parent field. | f12640:m98 |
def transform(emitted_output): | return WHITESPACE_PATTERN.sub(u'<STR_LIT>', emitted_output)<EOL> | Transform emitted_output into a unique representation, regardless of lines / indentation. | f12641:m0 |
def _get_mismatch_message(expected_blocks, received_blocks): | pretty_expected = pformat(expected_blocks)<EOL>pretty_received = pformat(received_blocks)<EOL>return u'<STR_LIT>'.format(pretty_expected, pretty_received)<EOL> | Create a well-formated error message indicating that two lists of blocks are mismatched. | f12641:m1 |
def get_schema(): | ast = parse(SCHEMA_TEXT)<EOL>schema = build_ast_schema(ast)<EOL>return schema<EOL> | Get a schema object for testing. | f12641:m8 |
def generate_schema_graph(graph_client): | schema_records = graph_client.command(ORIENTDB_SCHEMA_RECORDS_QUERY)<EOL>schema_data = [x.oRecordData for x in schema_records]<EOL>return SchemaGraph(schema_data)<EOL> | Generate SchemaGraph from a pyorient client | f12641:m9 |
def generate_schema(graph_client, class_to_field_type_overrides=None, hidden_classes=None): | schema_records = graph_client.command(ORIENTDB_SCHEMA_RECORDS_QUERY)<EOL>schema_data = [x.oRecordData for x in schema_records]<EOL>return get_graphql_schema_from_orientdb_schema_data(schema_data, class_to_field_type_overrides,<EOL>hidden_classes)<EOL> | Generate schema and type equivalence dict from a pyorient client | f12641:m10 |
def construct_location_types(location_types_as_strings): | schema = get_schema()<EOL>return {<EOL>location: schema.get_type(type_name)<EOL>for location, type_name in six.iteritems(location_types_as_strings)<EOL>}<EOL> | Convert the supplied dict into a proper location_types dict with GraphQL types as values. | f12641:m11 |
def setUp(self): | self.schema = get_schema()<EOL> | Initialize the test schema once for all tests. | f12642:c0:m0 |
def convert_decimals_to_strings(value): | if isinstance(value, tuple):<EOL><INDENT>return tuple(str(element) for element in value)<EOL><DEDENT>elif isinstance(value, Decimal):<EOL><INDENT>return str(value)<EOL><DEDENT>elif isinstance(value, six.string_types):<EOL><INDENT>return value<EOL><DEDENT>else:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LI... | Convert all decimals to strings in the given scalar or tuple. | f12643:m0 |
def setUp(self): | self.maxDiff = None<EOL>self.schema = get_schema()<EOL> | Initialize the test schema once for all tests, and disable max diff limits. | f12643:c0:m0 |
def setUp(self): | self.maxDiff = None<EOL>self.schema = get_schema()<EOL> | Initialize the test schema once for all tests, and disable max diff limits. | f12643:c1:m0 |
def sort_db_results(results): | sort_order = []<EOL>if len(results) > <NUM_LIT:0>:<EOL><INDENT>sort_order = sorted(six.iterkeys(results[<NUM_LIT:0>]))<EOL><DEDENT>def sort_key(result):<EOL><INDENT>"""<STR_LIT>"""<EOL>return tuple((result[col] is not None, result[col]) for col in sort_order)<EOL><DEDENT>return sorted(results, key=sort_key)<EOL> | Deterministically sort DB results.
Args:
results: List[Dict], results from a DB.
Returns:
List[Dict], sorted DB results. | f12644:m0 |
def try_convert_decimal_to_string(value): | if isinstance(value, list):<EOL><INDENT>return [try_convert_decimal_to_string(subvalue) for subvalue in value]<EOL><DEDENT>if isinstance(value, Decimal):<EOL><INDENT>return str(value)<EOL><DEDENT>return value<EOL> | Return Decimals as string if value is a Decimal, return value otherwise. | f12644:m1 |
def compile_and_run_match_query(schema, graphql_query, parameters, graph_client): | <EOL>converted_parameters = {<EOL>name: try_convert_decimal_to_string(value)<EOL>for name, value in six.iteritems(parameters)<EOL>}<EOL>compilation_result = graphql_to_match(schema, graphql_query, converted_parameters)<EOL>query = compilation_result.query<EOL>results = [row.oRecordData for row in graph_client.command(q... | Compiles and runs a MATCH query against the supplied graph client. | f12644:m2 |
def compile_and_run_sql_query(schema, graphql_query, parameters, engine, metadata): | dialect_name = engine.dialect.name<EOL>sql_metadata = SqlMetadata(dialect_name, metadata)<EOL>compilation_result = graphql_to_sql(schema, graphql_query, parameters, sql_metadata, None)<EOL>query = compilation_result.query<EOL>results = []<EOL>connection = engine.connect()<EOL>with connection.begin() as trans:<EOL><INDE... | Compiles and runs a SQL query against the supplied SQL backend. | f12644:m3 |
@classmethod<EOL><INDENT>def setUpClass(cls):<DEDENT> | cls.maxDiff = None<EOL>cls.schema = get_schema()<EOL> | Initialize the test schema once for all tests, and disable max diff limits. | f12646:c0:m0 |
def assertResultsEqual(self, graphql_query, parameters, backend_name, expected_results): | backend_results = self.compile_and_run_query(graphql_query, parameters, backend_name)<EOL>try:<EOL><INDENT>self.assertListEqual(sort_db_results(expected_results),<EOL>sort_db_results(backend_results))<EOL><DEDENT>except AssertionError as error:<EOL><INDENT>args = [u'<STR_LIT>'.format(backend_name, error.args[<NUM_LIT:0... | Assert that two lists of DB results are equal, independent of order. | f12646:c0:m1 |
@classmethod<EOL><INDENT>def compile_and_run_query(cls, graphql_query, parameters, backend_name):<DEDENT> | if backend_name in SQL_BACKENDS:<EOL><INDENT>engine = cls.sql_backend_name_to_engine[backend_name]<EOL>results = compile_and_run_sql_query(<EOL>cls.schema, graphql_query, parameters, engine, cls.sql_metadata)<EOL><DEDENT>elif backend_name in MATCH_BACKENDS:<EOL><INDENT>results = compile_and_run_match_query(<EOL>cls.sch... | Compiles and runs the graphql query with the supplied parameters against all backends.
Args:
graphql_query: str, GraphQL query string to run against every backend.
parameters: Dict[str, Any], input parameters to the query.
backend_name: str, the name of the test backend to g... | f12646:c0:m2 |
def setUp(self): | self.maxDiff = None<EOL> | Disable max diff limits for all tests. | f12648:c0:m0 |
def setUp(self): | self.maxDiff = None<EOL> | Disable max diff limits for all tests. | f12648:c1:m0 |
def _unused_function(*args, **kwargs): | raise NotImplementedError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(args, kwargs))<EOL> | Must not be called. Placeholder for functions that are required but aren't used. | f12649:m0 |
def _serialize_date(value): | if not isinstance(value, date):<EOL><INDENT>raise ValueError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(type(value), value))<EOL><DEDENT>return value.isoformat()<EOL> | Serialize a Date object to its proper ISO-8601 representation. | f12649:m1 |
def _parse_date_value(value): | return arrow.get(value, '<STR_LIT>').date()<EOL> | Deserialize a Date object from its proper ISO-8601 representation. | f12649:m2 |
def _serialize_datetime(value): | if not isinstance(value, (datetime, arrow.Arrow)):<EOL><INDENT>raise ValueError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(type(value), value))<EOL><DEDENT>return value.isoformat()<EOL> | Serialize a DateTime object to its proper ISO-8601 representation. | f12649:m3 |
def _parse_datetime_value(value): | if value.endswith('<STR_LIT>'):<EOL><INDENT>value = value[:-<NUM_LIT:1>] + '<STR_LIT>'<EOL><DEDENT>return arrow.get(value, '<STR_LIT>').datetime<EOL> | Deserialize a DateTime object from its proper ISO-8601 representation. | f12649:m4 |
def is_meta_field(field_name): | return field_name in ALL_SUPPORTED_META_FIELDS<EOL> | Return True if the field is considered a meta field in the schema, and False otherwise. | f12649:m5 |
def insert_meta_fields_into_existing_schema(graphql_schema): | root_type_name = graphql_schema.get_query_type().name<EOL>for type_name, type_obj in six.iteritems(graphql_schema.get_type_map()):<EOL><INDENT>if type_name.startswith('<STR_LIT>') or type_name == root_type_name:<EOL><INDENT>continue<EOL><DEDENT>if not isinstance(type_obj, (GraphQLObjectType, GraphQLInterfaceType)):<EOL... | Add compiler-specific meta-fields into all interfaces and types of the specified schema.
It is preferable to use the EXTENDED_META_FIELD_DEFINITIONS constant above to directly inject
the meta-fields during the initial process of building the schema, as that approach
is more robust. This function does its b... | f12649:m6 |
def validate_supported_property_type_id(property_name, property_type_id): | if property_type_id not in PROPERTY_TYPE_ID_TO_NAME:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(property_name, property_type_id))<EOL><DEDENT> | Ensure that the given property type_id is supported by the graph. | f12650:m0 |
def _parse_bool_default_value(property_name, default_value_string): | lowercased_value_string = default_value_string.lower()<EOL>if lowercased_value_string in {'<STR_LIT:0>', '<STR_LIT:false>'}:<EOL><INDENT>return False<EOL><DEDENT>elif lowercased_value_string in {'<STR_LIT:1>', '<STR_LIT:true>'}:<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL... | Parse and return the default value for a boolean property. | f12650:m1 |
def _parse_datetime_default_value(property_name, default_value_string): | <EOL>parsed_value = time.strptime(default_value_string, ORIENTDB_DATETIME_FORMAT)<EOL>return datetime.datetime(<EOL>parsed_value.tm_year, parsed_value.tm_mon, parsed_value.tm_mday,<EOL>parsed_value.tm_hour, parsed_value.tm_min, parsed_value.tm_sec, <NUM_LIT:0>, None)<EOL> | Parse and return the default value for a datetime property. | f12650:m2 |
def _parse_date_default_value(property_name, default_value_string): | <EOL>parsed_value = time.strptime(default_value_string, ORIENTDB_DATE_FORMAT)<EOL>return datetime.date(parsed_value.tm_year, parsed_value.tm_mon, parsed_value.tm_mday)<EOL> | Parse and return the default value for a date property. | f12650:m3 |
def parse_default_property_value(property_name, property_type_id, default_value_string): | if property_type_id == PROPERTY_TYPE_EMBEDDED_SET_ID and default_value_string == '<STR_LIT:{}>':<EOL><INDENT>return set()<EOL><DEDENT>elif property_type_id == PROPERTY_TYPE_EMBEDDED_LIST_ID and default_value_string == '<STR_LIT>':<EOL><INDENT>return list()<EOL><DEDENT>elif (property_type_id == PROPERTY_TYPE_STRING_ID a... | Parse the default value string into its proper form given the property type ID.
Args:
property_name: string, the name of the property whose default value is being parsed.
Used primarily to construct meaningful error messages, should the default
value prove inva... | f12650:m4 |
def _get_referenced_type_equivalences(graphql_types, type_equivalence_hints): | referenced_types = set()<EOL>for graphql_type in graphql_types.values():<EOL><INDENT>if isinstance(graphql_type, (GraphQLObjectType, GraphQLInterfaceType)):<EOL><INDENT>for _, field in graphql_type.fields.items():<EOL><INDENT>if isinstance(field.type, GraphQLList):<EOL><INDENT>referenced_types.add(field.type.of_type.na... | Filter union types with no edges from the type equivalence hints dict. | f12651:m0 |
def _get_inherited_field_types(class_to_field_type_overrides, schema_graph): | inherited_field_type_overrides = dict()<EOL>for superclass_name, field_type_overrides in class_to_field_type_overrides.items():<EOL><INDENT>for subclass_name in schema_graph.get_subclass_set(superclass_name):<EOL><INDENT>inherited_field_type_overrides.setdefault(subclass_name, dict())<EOL>inherited_field_type_overrides... | Return a dictionary describing the field type overrides in subclasses. | f12651:m1 |
def _validate_overriden_fields_are_not_defined_in_superclasses(class_to_field_type_overrides,<EOL>schema_graph): | for class_name, field_type_overrides in six.iteritems(class_to_field_type_overrides):<EOL><INDENT>for superclass_name in schema_graph.get_inheritance_set(class_name):<EOL><INDENT>if superclass_name != class_name:<EOL><INDENT>superclass = schema_graph.get_element_by_class_name(superclass_name)<EOL>for field_name in fiel... | Assert that the fields we want to override are not defined in superclasses. | f12651:m2 |
def _property_descriptor_to_graphql_type(property_obj): | property_type = property_obj.type_id<EOL>scalar_types = {<EOL>PROPERTY_TYPE_BOOLEAN_ID: GraphQLBoolean,<EOL>PROPERTY_TYPE_DATE_ID: GraphQLDate,<EOL>PROPERTY_TYPE_DATETIME_ID: GraphQLDateTime,<EOL>PROPERTY_TYPE_DECIMAL_ID: GraphQLDecimal,<EOL>PROPERTY_TYPE_DOUBLE_ID: GraphQLFloat,<EOL>PROPERTY_TYPE_FLOAT_ID: GraphQLFloa... | Return the best GraphQL type representation for an OrientDB property descriptor. | f12651:m3 |
def _get_union_type_name(type_names_to_union): | if not type_names_to_union:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(type_names_to_union))<EOL><DEDENT>return u'<STR_LIT>' + u'<STR_LIT>'.join(sorted(type_names_to_union))<EOL> | Construct a unique union type name based on the type names being unioned. | f12651:m4 |
def _get_fields_for_class(schema_graph, graphql_types, field_type_overrides, hidden_classes,<EOL>cls_name): | properties = schema_graph.get_element_by_class_name(cls_name).properties<EOL>all_properties = {<EOL>property_name: _property_descriptor_to_graphql_type(property_obj)<EOL>for property_name, property_obj in six.iteritems(properties)<EOL>}<EOL>result = {<EOL>property_name: graphql_representation<EOL>for property_name, gra... | Return a dict from field name to GraphQL field type, for the specified graph class. | f12651:m5 |
def _create_field_specification(schema_graph, graphql_types, field_type_overrides,<EOL>hidden_classes, cls_name): | def field_maker_func():<EOL><INDENT>"""<STR_LIT>"""<EOL>result = EXTENDED_META_FIELD_DEFINITIONS.copy()<EOL>result.update(OrderedDict([<EOL>(name, GraphQLField(value))<EOL>for name, value in sorted(six.iteritems(_get_fields_for_class(<EOL>schema_graph, graphql_types, field_type_overrides, hidden_classes, cls_name)),<EO... | Return a function that specifies the fields present on the given type. | f12651:m6 |
def _create_interface_specification(schema_graph, graphql_types, hidden_classes, cls_name): | def interface_spec():<EOL><INDENT>"""<STR_LIT>"""<EOL>abstract_inheritance_set = (<EOL>superclass_name<EOL>for superclass_name in sorted(list(schema_graph.get_inheritance_set(cls_name)))<EOL>if (superclass_name not in hidden_classes and<EOL>schema_graph.get_element_by_class_name(superclass_name).abstract)<EOL>)<EOL>ret... | Return a function that specifies the interfaces implemented by the given type. | f12651:m7 |
def _create_union_types_specification(schema_graph, graphql_types, hidden_classes, base_name): | <EOL>def types_spec():<EOL><INDENT>"""<STR_LIT>"""<EOL>return [<EOL>graphql_types[x]<EOL>for x in sorted(list(schema_graph.get_subclass_set(base_name)))<EOL>if x not in hidden_classes<EOL>]<EOL><DEDENT>return types_spec<EOL> | Return a function that gives the types in the union type rooted at base_name. | f12651:m8 |
def get_graphql_schema_from_schema_graph(schema_graph, class_to_field_type_overrides,<EOL>hidden_classes): | _validate_overriden_fields_are_not_defined_in_superclasses(class_to_field_type_overrides,<EOL>schema_graph)<EOL>inherited_field_type_overrides = _get_inherited_field_types(class_to_field_type_overrides,<EOL>schema_graph)<EOL>if not schema_graph.get_element_by_class_name(ORIENTDB_BASE_VERTEX_CLASS_NAME).properties:<EOL>... | Return a GraphQL schema object corresponding to the schema of the given schema graph.
Args:
schema_graph: SchemaGraph
class_to_field_type_overrides: dict, class name -> {field name -> field type},
(string -> {string -> GraphQLType}). Used to override the
... | f12651:m9 |
def _validate_non_abstract_edge_has_defined_endpoint_types(class_name, properties): | edge_source = properties.get(EDGE_SOURCE_PROPERTY_NAME, None)<EOL>edge_destination = properties.get(EDGE_DESTINATION_PROPERTY_NAME, None)<EOL>has_defined_endpoint_types = all((<EOL>edge_source is not None and edge_source.type_id == PROPERTY_TYPE_LINK_ID,<EOL>edge_destination is not None and edge_destination.type_id == ... | Validate that the non-abstract edge properties dict has defined in/out link properties. | f12653:m0 |
def _validate_non_edges_do_not_have_edge_like_properties(class_name, properties): | has_source = EDGE_SOURCE_PROPERTY_NAME in properties<EOL>has_destination = EDGE_DESTINATION_PROPERTY_NAME in properties<EOL>if has_source or has_destination:<EOL><INDENT>raise IllegalSchemaStateError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(class_name, properties))<EOL><DEDENT>for property_name, property_descriptor in six.... | Validate that non-edges do not have the in/out properties defined. | f12653:m1 |
def _validate_edges_do_not_have_extra_links(class_name, properties): | for property_name, property_descriptor in six.iteritems(properties):<EOL><INDENT>if property_name in {EDGE_SOURCE_PROPERTY_NAME, EDGE_DESTINATION_PROPERTY_NAME}:<EOL><INDENT>continue<EOL><DEDENT>if property_descriptor.type_id == PROPERTY_TYPE_LINK_ID:<EOL><INDENT>raise IllegalSchemaStateError(u'<STR_LIT>'<EOL>u'<STR_LI... | Validate that edges do not have properties of Link type that aren't the edge endpoints. | f12653:m2 |
def _validate_property_names(class_name, properties): | for property_name in properties:<EOL><INDENT>if not property_name or property_name.startswith(ILLEGAL_PROPERTY_NAME_PREFIXES):<EOL><INDENT>raise IllegalSchemaStateError(u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(class_name, property_name))<EOL><DEDENT><DEDENT> | Validate that properties do not have names that may cause problems in the GraphQL schema. | f12653:m3 |
def _validate_collections_have_default_values(class_name, property_name, property_descriptor): | <EOL>if property_descriptor.type_id in COLLECTION_PROPERTY_TYPES:<EOL><INDENT>if property_descriptor.default is None:<EOL><INDENT>raise IllegalSchemaStateError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(class_name, property_name))<EOL><DEDENT><DEDENT> | Validate that if the property is of collection type, it has a specified default value. | f12653:m4 |
def get_superclasses_from_class_definition(class_definition): | <EOL>superclasses = class_definition.get('<STR_LIT>', None)<EOL>if superclasses:<EOL><INDENT>return list(superclasses)<EOL><DEDENT>superclass = class_definition.get('<STR_LIT>', None)<EOL>if superclass:<EOL><INDENT>return [superclass]<EOL><DEDENT>return []<EOL> | Extract a list of all superclass names from a class definition dict. | f12653:m5 |
def __init__(self, class_name, kind, abstract, properties, class_fields): | if kind == SchemaElement.ELEMENT_KIND_EDGE:<EOL><INDENT>_validate_edges_do_not_have_extra_links(class_name, properties)<EOL>if not abstract:<EOL><INDENT>_validate_non_abstract_edge_has_defined_endpoint_types(class_name, properties)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>_validate_non_edges_do_not_have_edge_like_properti... | Create a new SchemaElement object.
Args:
class_name: string, the name of the schema element class.
kind: string, one of the values of ELEMENT_KIND_VERTEX, ELEMENT_KIND_EDGE or
ELEMENT_KIND_NON_GRAPH. Describes whether the schema class is a vertex, edge,
... | f12653:c0:m0 |
@property<EOL><INDENT>def abstract(self):<DEDENT> | return self._abstract<EOL> | Return True if the represented type is abstract, and False otherwise. | f12653:c0:m1 |
@property<EOL><INDENT>def class_name(self):<DEDENT> | return self._class_name<EOL> | Return the name of the type that the schema element represents. | f12653:c0:m2 |
@property<EOL><INDENT>def properties(self):<DEDENT> | return self._properties<EOL> | Return a dict of property name to property descriptor for this schema element. | f12653:c0:m3 |
@property<EOL><INDENT>def class_fields(self):<DEDENT> | return self._class_fields<EOL> | Return a dict containing all class fields defined on the schema element. | f12653:c0:m4 |
@property<EOL><INDENT>def is_vertex(self):<DEDENT> | return self._kind == SchemaElement.ELEMENT_KIND_VERTEX<EOL> | Return True if the schema element represents a vertex type, and False otherwise. | f12653:c0:m5 |
@property<EOL><INDENT>def is_edge(self):<DEDENT> | return self._kind == SchemaElement.ELEMENT_KIND_EDGE<EOL> | Return True if the schema element represents an edge type, and False otherwise. | f12653:c0:m6 |
@property<EOL><INDENT>def is_non_graph(self):<DEDENT> | return self._kind == SchemaElement.ELEMENT_KIND_NON_GRAPH<EOL> | Return True if the schema element represents a non-graph type, and False otherwise. | f12653:c0:m7 |
def freeze(self): | self.in_connections = frozenset(self.in_connections)<EOL>self.out_connections = frozenset(self.out_connections)<EOL> | Make the SchemaElement's connections immutable. | f12653:c0:m8 |
def __str__(self): | return (<EOL>'<STR_LIT>'<EOL>.format(self._class_name, self._kind, self._abstract, self._properties,<EOL>self.in_connections, self.out_connections)<EOL>)<EOL> | Stringify the SchemaElement. | f12653:c0:m9 |
def __init__(self, schema_data): | toposorted_schema_data = toposort_classes(schema_data)<EOL>self._elements = dict()<EOL>self._inheritance_sets = dict()<EOL>self._subclass_sets = dict()<EOL>self._vertex_class_names = set()<EOL>self._edge_class_names = set()<EOL>self._non_graph_class_names = set()<EOL>self._set_up_inheritance_and_subclass_sets(toposorte... | Create a new SchemaGraph from the OrientDB schema.
Args:
schema_data: list of dicts describing the classes in the OrientDB schema. The following
format is the way the data is structured in OrientDB 2. See
the README.md file for an example of how to ... | f12653:c1:m0 |
def get_element_by_class_name(self, class_name): | return self._elements[class_name]<EOL> | Return the SchemaElement for the specified class name | f12653:c1:m1 |
def get_inheritance_set(self, cls): | return self._inheritance_sets[cls]<EOL> | Return all class names that the given class inherits from, including itself. | f12653:c1:m2 |
def get_subclass_set(self, cls): | return self._subclass_sets[cls]<EOL> | Return all class names that inherit from this class, including itself. | f12653:c1:m3 |
def get_default_property_values(self, classname): | schema_element = self.get_element_by_class_name(classname)<EOL>result = {<EOL>property_name: property_descriptor.default<EOL>for property_name, property_descriptor in six.iteritems(schema_element.properties)<EOL>}<EOL>if schema_element.is_edge:<EOL><INDENT>result.pop(EDGE_SOURCE_PROPERTY_NAME, None)<EOL>result.pop(EDGE... | Return a dict with default values for all properties declared on this class. | f12653:c1:m4 |
def _get_property_values_with_defaults(self, classname, property_values): | <EOL>final_values = self.get_default_property_values(classname)<EOL>final_values.update(property_values)<EOL>return final_values<EOL> | Return the property values for the class, with default values applied where needed. | f12653:c1:m5 |
def get_element_by_class_name_or_raise(self, class_name): | if class_name not in self._elements:<EOL><INDENT>raise InvalidClassError(u'<STR_LIT>'.format(class_name))<EOL><DEDENT>return self._elements[class_name]<EOL> | Return the SchemaElement for the specified class name, asserting that it exists. | f12653:c1:m6 |
def get_vertex_schema_element_or_raise(self, vertex_classname): | schema_element = self.get_element_by_class_name_or_raise(vertex_classname)<EOL>if not schema_element.is_vertex:<EOL><INDENT>raise InvalidClassError(u'<STR_LIT>'.format(vertex_classname))<EOL><DEDENT>return schema_element<EOL> | Return the schema element with the given name, asserting that it's of vertex type. | f12653:c1:m7 |
def get_edge_schema_element_or_raise(self, edge_classname): | schema_element = self.get_element_by_class_name_or_raise(edge_classname)<EOL>if not schema_element.is_edge:<EOL><INDENT>raise InvalidClassError(u'<STR_LIT>'.format(edge_classname))<EOL><DEDENT>return schema_element<EOL> | Return the schema element with the given name, asserting that it's of edge type. | f12653:c1:m8 |
def validate_is_vertex_type(self, vertex_classname): | self.get_vertex_schema_element_or_raise(vertex_classname)<EOL> | Validate that a vertex classname indeed corresponds to a vertex class. | f12653:c1:m9 |
def validate_is_edge_type(self, edge_classname): | self.get_edge_schema_element_or_raise(edge_classname)<EOL> | Validate that a edge classname indeed corresponds to a edge class. | f12653:c1:m10 |
def validate_is_non_abstract_vertex_type(self, vertex_classname): | element = self.get_vertex_schema_element_or_raise(vertex_classname)<EOL>if element.abstract:<EOL><INDENT>raise InvalidClassError(u'<STR_LIT>'<EOL>.format(vertex_classname))<EOL><DEDENT> | Validate that a vertex classname corresponds to a non-abstract vertex class. | f12653:c1:m11 |
def validate_is_non_abstract_edge_type(self, edge_classname): | element = self.get_edge_schema_element_or_raise(edge_classname)<EOL>if element.abstract:<EOL><INDENT>raise InvalidClassError(u'<STR_LIT>'<EOL>.format(edge_classname))<EOL><DEDENT> | Validate that a edge classname corresponds to a non-abstract edge class. | f12653:c1:m12 |
def validate_properties_exist(self, classname, property_names): | schema_element = self.get_element_by_class_name(classname)<EOL>requested_properties = set(property_names)<EOL>available_properties = set(schema_element.properties.keys())<EOL>non_existent_properties = requested_properties - available_properties<EOL>if non_existent_properties:<EOL><INDENT>raise InvalidPropertyError(<EOL... | Validate that the specified property names are indeed defined on the given class. | f12653:c1:m13 |
@property<EOL><INDENT>def class_names(self):<DEDENT> | return set(six.iterkeys(self._elements))<EOL> | Return the set of all class names | f12653:c1:m14 |
@property<EOL><INDENT>def vertex_class_names(self):<DEDENT> | return self._vertex_class_names<EOL> | Return the set of vertex class names in the SchemaGraph. | f12653:c1:m15 |
@property<EOL><INDENT>def edge_class_names(self):<DEDENT> | return self._edge_class_names<EOL> | Return the set of edge class names in the SchemaGraph. | f12653:c1:m16 |
@property<EOL><INDENT>def non_graph_class_names(self):<DEDENT> | return self._non_graph_class_names<EOL> | Return the set of non-graph class names in the SchemaGraph. | f12653:c1:m17 |
def _set_up_inheritance_and_subclass_sets(self, schema_data): | <EOL>for class_definition in schema_data:<EOL><INDENT>class_name = class_definition['<STR_LIT:name>']<EOL>immediate_superclass_names = get_superclasses_from_class_definition(<EOL>class_definition)<EOL>inheritance_set = set(immediate_superclass_names)<EOL>inheritance_set.add(class_name)<EOL>inheritance_set.update(chain.... | Load all inheritance data from the OrientDB schema. Used as part of __init__. | f12653:c1:m18 |
def _split_classes_by_kind(self, class_name_to_definition): | for class_name in class_name_to_definition:<EOL><INDENT>inheritance_set = self._inheritance_sets[class_name]<EOL>is_vertex = ORIENTDB_BASE_VERTEX_CLASS_NAME in inheritance_set<EOL>is_edge = ORIENTDB_BASE_EDGE_CLASS_NAME in inheritance_set<EOL>if is_vertex and is_edge:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u... | Assign each class to the vertex, edge or non-graph type sets based on its kind. | f12653:c1:m19 |
def _set_up_schema_elements_of_kind(self, class_name_to_definition, kind, class_names): | allowed_duplicated_edge_property_names = frozenset({<EOL>EDGE_DESTINATION_PROPERTY_NAME, EDGE_SOURCE_PROPERTY_NAME<EOL>})<EOL>orientdb_base_classes = frozenset({<EOL>ORIENTDB_BASE_VERTEX_CLASS_NAME,<EOL>ORIENTDB_BASE_EDGE_CLASS_NAME,<EOL>})<EOL>for class_name in class_names:<EOL><INDENT>class_definition = class_name_to... | Load all schema classes of the given kind. Used as part of __init__. | f12653:c1:m20 |
def _create_descriptor_from_property_definition(self, class_name, property_definition,<EOL>class_name_to_definition): | name = property_definition['<STR_LIT:name>']<EOL>type_id = property_definition['<STR_LIT:type>']<EOL>linked_class = property_definition.get('<STR_LIT>', None)<EOL>linked_type = property_definition.get('<STR_LIT>', None)<EOL>qualifier = None<EOL>validate_supported_property_type_id(name, type_id)<EOL>if type_id == PROPER... | Return a PropertyDescriptor corresponding to the given OrientDB property definition. | f12653:c1:m21 |
def _link_vertex_and_edge_types(self): | for edge_class_name in self._edge_class_names:<EOL><INDENT>edge_element = self._elements[edge_class_name]<EOL>if (EDGE_SOURCE_PROPERTY_NAME not in edge_element.properties or<EOL>EDGE_DESTINATION_PROPERTY_NAME not in edge_element.properties):<EOL><INDENT>if edge_element.abstract:<EOL><INDENT>continue<EOL><DEDENT>else:<E... | For each edge, link it to the vertex types it connects to each other. | f12653:c1:m22 |
def toposort_classes(classes): | def get_class_topolist(class_name, name_to_class, processed_classes, current_trace):<EOL><INDENT>"""<STR_LIT>"""<EOL>if class_name in processed_classes:<EOL><INDENT>return []<EOL><DEDENT>if class_name in current_trace:<EOL><INDENT>raise AssertionError(<EOL>'<STR_LIT>'.format(class_name))<EOL><DEDENT>cls = name_to_class... | Sort class metadatas so that a superclass is always before the subclass | f12654:m0 |
def _list_superclasses(class_def): | superclasses = class_def.get('<STR_LIT>', [])<EOL>if superclasses:<EOL><INDENT>return list(superclasses)<EOL><DEDENT>sup = class_def.get('<STR_LIT>', None)<EOL>if sup:<EOL><INDENT>return [sup]<EOL><DEDENT>else:<EOL><INDENT>return []<EOL><DEDENT> | Return a list of the superclasses of the given class | f12654:m1 |
def _construct_location_stack_entry(location, num_traverses): | if not isinstance(num_traverses, int) or num_traverses < <NUM_LIT:0>:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'<EOL>.format(num_traverses))<EOL><DEDENT>if not isinstance(location, Location):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'<EOL>.format(location))<EOL><DEDENT>return Loc... | Return a LocationStackEntry namedtuple with the specified parameters. | f12656:m0 |
def _get_fields(ast): | if not ast.selection_set:<EOL><INDENT>return [], []<EOL><DEDENT>property_fields = []<EOL>vertex_fields = []<EOL>seen_field_names = set()<EOL>switched_to_vertices = False <EOL>for field_ast in ast.selection_set.selections:<EOL><INDENT>if not isinstance(field_ast, Field):<EOL><INDENT>continue<EOL><DEDENT>name = get_ast_... | Return a list of vertex fields, and a list of property fields, for the given AST node.
Also verifies that all property fields for the AST node appear before all vertex fields,
raising GraphQLCompilationError if that is not the case.
Args:
ast: GraphQL AST node, obtained from the graphql library
... | f12656:m1 |
def _get_inline_fragment(ast): | if not ast.selection_set:<EOL><INDENT>return None<EOL><DEDENT>fragments = [<EOL>ast_node<EOL>for ast_node in ast.selection_set.selections<EOL>if isinstance(ast_node, InlineFragment)<EOL>]<EOL>if not fragments:<EOL><INDENT>return None<EOL><DEDENT>if len(fragments) > <NUM_LIT:1>:<EOL><INDENT>raise GraphQLCompilationError... | Return the inline fragment at the current AST node, or None if no fragment exists. | f12656:m2 |
def _mark_location(location): | return blocks.MarkLocation(location)<EOL> | Return a MarkLocation basic block that marks the present location in the query. | f12656:m3 |
def _process_output_source_directive(schema, current_schema_type, ast,<EOL>location, context, local_unique_directives): | <EOL>output_source_directive = local_unique_directives.get('<STR_LIT>', None)<EOL>if output_source_directive:<EOL><INDENT>if has_encountered_output_source(context):<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>')<EOL><DEDENT>if is_in_optional_scope(context):<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>... | Process the output_source directive, modifying the context as appropriate.
Args:
schema: GraphQL schema object, obtained from the graphql library
current_schema_type: GraphQLType, the schema type at the current location
ast: GraphQL AST node, obtained from the graphql library
locati... | f12656:m4 |
def _compile_property_ast(schema, current_schema_type, ast, location,<EOL>context, unique_local_directives): | validate_property_directives(unique_local_directives)<EOL>if location.field == COUNT_META_FIELD_NAME:<EOL><INDENT>if not is_in_fold_scope(context):<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>'<EOL>u'<STR_LIT>'<EOL>u'<STR_LIT>'<EOL>.format(COUNT_META_FIELD_NAME, location))<EOL><DEDENT><DEDENT>tag_directive = u... | Process property directives at this AST node, updating the query context as appropriate.
Args:
schema: GraphQL schema object, obtained from the graphql library
current_schema_type: GraphQLType, the schema type at the current location
ast: GraphQL AST node, obtained from the graphql library.... | f12656:m5 |
def _get_recurse_directive_depth(field_name, field_directives): | recurse_directive = field_directives['<STR_LIT>']<EOL>optional_directive = field_directives.get('<STR_LIT>', None)<EOL>if optional_directive:<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(field_name))<EOL><DEDENT>recurse_args = get_uniquely_named_objects_by_name(recurse_directive.argume... | Validate and return the depth parameter of the recurse directive. | f12656:m6 |
def _validate_recurse_directive_types(current_schema_type, field_schema_type, context): | <EOL>type_hints = context['<STR_LIT>'].get(field_schema_type)<EOL>type_hints_inverse = context['<STR_LIT>'].get(field_schema_type)<EOL>allowed_current_types = {field_schema_type}<EOL>if type_hints and isinstance(type_hints, GraphQLUnionType):<EOL><INDENT>allowed_current_types.update(type_hints.types)<EOL><DEDENT>if typ... | Perform type checks on the enclosing type and the recursed type for a recurse directive.
Args:
current_schema_type: GraphQLType, the schema type at the current location
field_schema_type: GraphQLType, the schema type at the inner scope
context: dict, various per-compilation data (e.g. decla... | f12656:m7 |
def _compile_vertex_ast(schema, current_schema_type, ast,<EOL>location, context, unique_local_directives, fields): | basic_blocks = []<EOL>query_metadata_table = context['<STR_LIT>']<EOL>current_location_info = query_metadata_table.get_location_info(location)<EOL>vertex_fields, property_fields = fields<EOL>validate_vertex_directives(unique_local_directives)<EOL>for field_ast in property_fields:<EOL><INDENT>field_name = get_ast_field_... | Return a list of basic blocks corresponding to the vertex AST node.
Args:
schema: GraphQL schema object, obtained from the graphql library
current_schema_type: GraphQLType, the schema type at the current location
ast: GraphQL AST node, obtained from the graphql library
location: Loc... | f12656:m8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.