idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
38,900 | def validate ( self ) : if not isinstance ( self . fold_scope_location , FoldScopeLocation ) : raise TypeError ( u'Expected FoldScopeLocation fold_scope_location, got: {} {}' . format ( type ( self . fold_scope_location ) , self . fold_scope_location ) ) allowed_block_types = ( GremlinFoldedFilter , GremlinFoldedTraver... | Validate that the GremlinFoldedContextField is correctly representable . |
38,901 | def from_traverse ( cls , traverse_block ) : if isinstance ( traverse_block , Traverse ) : return cls ( traverse_block . direction , traverse_block . edge_name ) else : raise AssertionError ( u'Tried to initialize an instance of GremlinFoldedTraverse ' u'with block of type {}' . format ( type ( traverse_block ) ) ) | Create a GremlinFoldedTraverse block as a copy of the given Traverse block . |
38,902 | def _get_referenced_type_equivalences ( graphql_types , type_equivalence_hints ) : referenced_types = set ( ) for graphql_type in graphql_types . values ( ) : if isinstance ( graphql_type , ( GraphQLObjectType , GraphQLInterfaceType ) ) : for _ , field in graphql_type . fields . items ( ) : if isinstance ( field . type... | Filter union types with no edges from the type equivalence hints dict . |
38,903 | def _get_inherited_field_types ( class_to_field_type_overrides , schema_graph ) : inherited_field_type_overrides = dict ( ) for superclass_name , field_type_overrides in class_to_field_type_overrides . items ( ) : for subclass_name in schema_graph . get_subclass_set ( superclass_name ) : inherited_field_type_overrides ... | Return a dictionary describing the field type overrides in subclasses . |
38,904 | def _validate_overriden_fields_are_not_defined_in_superclasses ( class_to_field_type_overrides , schema_graph ) : for class_name , field_type_overrides in six . iteritems ( class_to_field_type_overrides ) : for superclass_name in schema_graph . get_inheritance_set ( class_name ) : if superclass_name != class_name : sup... | Assert that the fields we want to override are not defined in superclasses . |
38,905 | def _property_descriptor_to_graphql_type ( property_obj ) : property_type = property_obj . type_id scalar_types = { PROPERTY_TYPE_BOOLEAN_ID : GraphQLBoolean , PROPERTY_TYPE_DATE_ID : GraphQLDate , PROPERTY_TYPE_DATETIME_ID : GraphQLDateTime , PROPERTY_TYPE_DECIMAL_ID : GraphQLDecimal , PROPERTY_TYPE_DOUBLE_ID : GraphQ... | Return the best GraphQL type representation for an OrientDB property descriptor . |
38,906 | def _get_union_type_name ( type_names_to_union ) : if not type_names_to_union : raise AssertionError ( u'Expected a non-empty list of type names to union, received: ' u'{}' . format ( type_names_to_union ) ) return u'Union__' + u'__' . join ( sorted ( type_names_to_union ) ) | Construct a unique union type name based on the type names being unioned . |
38,907 | def _get_fields_for_class ( schema_graph , graphql_types , field_type_overrides , hidden_classes , cls_name ) : properties = schema_graph . get_element_by_class_name ( cls_name ) . properties all_properties = { property_name : _property_descriptor_to_graphql_type ( property_obj ) for property_name , property_obj in six... | Return a dict from field name to GraphQL field type for the specified graph class . |
38,908 | def _create_field_specification ( schema_graph , graphql_types , field_type_overrides , hidden_classes , cls_name ) : def field_maker_func ( ) : result = EXTENDED_META_FIELD_DEFINITIONS . copy ( ) result . update ( OrderedDict ( [ ( name , GraphQLField ( value ) ) for name , value in sorted ( six . iteritems ( _get_fie... | Return a function that specifies the fields present on the given type . |
38,909 | def _create_interface_specification ( schema_graph , graphql_types , hidden_classes , cls_name ) : def interface_spec ( ) : abstract_inheritance_set = ( superclass_name for superclass_name in sorted ( list ( schema_graph . get_inheritance_set ( cls_name ) ) ) if ( superclass_name not in hidden_classes and schema_graph ... | Return a function that specifies the interfaces implemented by the given type . |
38,910 | def _create_union_types_specification ( schema_graph , graphql_types , hidden_classes , base_name ) : def types_spec ( ) : return [ graphql_types [ x ] for x in sorted ( list ( schema_graph . get_subclass_set ( base_name ) ) ) if x not in hidden_classes ] return types_spec | Return a function that gives the types in the union type rooted at base_name . |
38,911 | def get_graphql_schema_from_schema_graph ( schema_graph , class_to_field_type_overrides , hidden_classes ) : _validate_overriden_fields_are_not_defined_in_superclasses ( class_to_field_type_overrides , schema_graph ) inherited_field_type_overrides = _get_inherited_field_types ( class_to_field_type_overrides , schema_gr... | Return a GraphQL schema object corresponding to the schema of the given schema graph . |
38,912 | def workaround_lowering_pass ( ir_blocks , query_metadata_table ) : new_ir_blocks = [ ] for block in ir_blocks : if isinstance ( block , Filter ) : new_block = _process_filter_block ( query_metadata_table , block ) else : new_block = block new_ir_blocks . append ( new_block ) return new_ir_blocks | Extract locations from TernaryConditionals and rewrite their Filter blocks as necessary . |
38,913 | def _process_filter_block ( query_metadata_table , block ) : base_predicate = block . predicate ternary_conditionals = [ ] problematic_locations = [ ] def find_ternary_conditionals ( expression ) : if isinstance ( expression , TernaryConditional ) : ternary_conditionals . append ( expression ) return expression def ext... | Rewrite the provided Filter block if necessary . |
38,914 | def _create_tautological_expression_for_location ( query_metadata_table , location ) : location_type = query_metadata_table . get_location_info ( location ) . type location_exists = BinaryComposition ( u'!=' , ContextField ( location , location_type ) , NullLiteral ) location_does_not_exist = BinaryComposition ( u'=' ,... | For a given location create a BinaryComposition that always evaluates to true . |
38,915 | def get_only_element_from_collection ( one_element_collection ) : if len ( one_element_collection ) != 1 : raise AssertionError ( u'Expected a collection with exactly one element, but got: {}' . format ( one_element_collection ) ) return funcy . first ( one_element_collection ) | Assert that the collection has exactly one element then return that element . |
38,916 | def get_ast_field_name ( ast ) : replacements = { TYPENAME_META_FIELD_NAME : '@class' } base_field_name = ast . name . value normalized_name = replacements . get ( base_field_name , base_field_name ) return normalized_name | Return the normalized field name for the given AST node . |
38,917 | def get_field_type_from_schema ( schema_type , field_name ) : if field_name == '@class' : return GraphQLString else : if field_name not in schema_type . fields : raise AssertionError ( u'Field {} passed validation but was not present on type ' u'{}' . format ( field_name , schema_type ) ) return schema_type . fields [ ... | Return the type of the field in the given type accounting for field name normalization . |
38,918 | def get_vertex_field_type ( current_schema_type , vertex_field_name ) : if not is_vertex_field_name ( vertex_field_name ) : raise AssertionError ( u'Trying to load the vertex field type of a non-vertex field: ' u'{} {}' . format ( current_schema_type , vertex_field_name ) ) raw_field_type = get_field_type_from_schema (... | Return the type of the vertex within the specified vertex field name of the given type . |
38,919 | def get_edge_direction_and_name ( vertex_field_name ) : edge_direction = None edge_name = None if vertex_field_name . startswith ( OUTBOUND_EDGE_FIELD_PREFIX ) : edge_direction = OUTBOUND_EDGE_DIRECTION edge_name = vertex_field_name [ len ( OUTBOUND_EDGE_FIELD_PREFIX ) : ] elif vertex_field_name . startswith ( INBOUND_... | Get the edge direction and name from a non - root vertex field name . |
38,920 | def is_vertex_field_type ( graphql_type ) : underlying_type = strip_non_null_from_type ( graphql_type ) return isinstance ( underlying_type , ( GraphQLInterfaceType , GraphQLObjectType , GraphQLUnionType ) ) | Return True if the argument is a vertex field type and False otherwise . |
38,921 | def ensure_unicode_string ( value ) : if not isinstance ( value , six . string_types ) : raise TypeError ( u'Expected string value, got: {}' . format ( value ) ) return six . text_type ( value ) | Ensure the value is a string and return it as unicode . |
38,922 | def get_uniquely_named_objects_by_name ( object_list ) : if not object_list : return dict ( ) result = dict ( ) for obj in object_list : name = obj . name . value if name in result : raise GraphQLCompilationError ( u'Found duplicate object key: ' u'{} {}' . format ( name , object_list ) ) result [ name ] = obj return r... | Return dict of name - > object pairs from a list of objects with unique names . |
38,923 | def validate_safe_string ( value ) : legal_strings_with_special_chars = frozenset ( { '@rid' , '@class' , '@this' , '%' } ) if not isinstance ( value , six . string_types ) : raise TypeError ( u'Expected string value, got: {} {}' . format ( type ( value ) . __name__ , value ) ) if not value : raise GraphQLCompilationEr... | Ensure the provided string does not have illegal characters . |
38,924 | def validate_edge_direction ( edge_direction ) : if not isinstance ( edge_direction , six . string_types ) : raise TypeError ( u'Expected string edge_direction, got: {} {}' . format ( type ( edge_direction ) , edge_direction ) ) if edge_direction not in ALLOWED_EDGE_DIRECTIONS : raise ValueError ( u'Unrecognized edge d... | Ensure the provided edge direction is either in or out . |
38,925 | def validate_marked_location ( location ) : if not isinstance ( location , ( Location , FoldScopeLocation ) ) : raise TypeError ( u'Expected Location or FoldScopeLocation location, got: {} {}' . format ( type ( location ) . __name__ , location ) ) if location . field is not None : raise GraphQLCompilationError ( u'Cann... | Validate that a Location object is safe for marking and not at a field . |
38,926 | def invert_dict ( invertible_dict ) : inverted = { } for k , v in six . iteritems ( invertible_dict ) : if not isinstance ( v , Hashable ) : raise TypeError ( u'Expected an invertible dict, but value at key {} has type {}' . format ( k , type ( v ) . __name__ ) ) if v in inverted : raise TypeError ( u'Expected an inver... | Invert a dict . A dict is invertible if values are unique and hashable . |
38,927 | def read_file ( filename ) : here = os . path . abspath ( os . path . dirname ( __file__ ) ) with codecs . open ( os . path . join ( here , 'graphql_compiler' , filename ) , 'r' ) as f : return f . read ( ) | Read package file as text to get name and version |
38,928 | def find_version ( ) : version_file = read_file ( '__init__.py' ) version_match = re . search ( r'^__version__ = ["\']([^"\']*)["\']' , version_file , re . M ) if version_match : return version_match . group ( 1 ) raise RuntimeError ( 'Unable to find version string.' ) | Only define version in one place |
38,929 | def find_name ( ) : name_file = read_file ( '__init__.py' ) name_match = re . search ( r'^__package_name__ = ["\']([^"\']*)["\']' , name_file , re . M ) if name_match : return name_match . group ( 1 ) raise RuntimeError ( 'Unable to find name string.' ) | Only define name in one place |
38,930 | def workaround_type_coercions_in_recursions ( match_query ) : new_match_traversals = [ ] for current_traversal in match_query . match_traversals : new_traversal = [ ] for match_step in current_traversal : new_match_step = match_step has_coerce_type = match_step . coerce_type_block is not None has_recurse_root = isinsta... | Lower CoerceType blocks into Filter blocks within Recurse steps . |
38,931 | def main ( ) : query = ' ' . join ( sys . stdin . readlines ( ) ) sys . stdout . write ( pretty_print_graphql ( query ) ) | Read a GraphQL query from standard input and output it pretty - printed to standard output . |
38,932 | def _safe_gremlin_string ( value ) : if not isinstance ( value , six . string_types ) : if isinstance ( value , bytes ) : value = value . decode ( 'utf-8' ) else : raise GraphQLInvalidArgumentError ( u'Attempting to convert a non-string into a string: ' u'{}' . format ( value ) ) escaped_and_quoted = json . dumps ( val... | Sanitize and represent a string argument in Gremlin . |
38,933 | def _safe_gremlin_list ( inner_type , argument_value ) : if not isinstance ( argument_value , list ) : raise GraphQLInvalidArgumentError ( u'Attempting to represent a non-list as a list: ' u'{}' . format ( argument_value ) ) stripped_type = strip_non_null_from_type ( inner_type ) components = ( _safe_gremlin_argument (... | Represent the list of inner_type objects in Gremlin form . |
38,934 | def _safe_gremlin_argument ( expected_type , argument_value ) : if GraphQLString . is_same_type ( expected_type ) : return _safe_gremlin_string ( argument_value ) elif GraphQLID . is_same_type ( expected_type ) : if not isinstance ( argument_value , six . string_types ) : if isinstance ( argument_value , bytes ) : argu... | Return a Gremlin string representing the given argument value . |
38,935 | def insert_arguments_into_gremlin_query ( compilation_result , arguments ) : if compilation_result . language != GREMLIN_LANGUAGE : raise AssertionError ( u'Unexpected query output language: {}' . format ( compilation_result ) ) base_query = compilation_result . query argument_types = compilation_result . input_metadat... | Insert the arguments into the compiled Gremlin query to form a complete query . |
38,936 | def _get_vertex_location_name ( location ) : mark_name , field_name = location . get_location_name ( ) if field_name is not None : raise AssertionError ( u'Location unexpectedly pointed to a field: {}' . format ( location ) ) return mark_name | Get the location name from a location that is expected to point to a vertex . |
38,937 | def _first_step_to_match ( match_step ) : parts = [ ] if match_step . root_block is not None : if not isinstance ( match_step . root_block , QueryRoot ) : raise AssertionError ( u'Expected None or QueryRoot root block, received: ' u'{} {}' . format ( match_step . root_block , match_step ) ) match_step . root_block . va... | Transform the very first MATCH step into a MATCH query string . |
38,938 | def _represent_match_traversal ( match_traversal ) : output = [ ] output . append ( _first_step_to_match ( match_traversal [ 0 ] ) ) for step in match_traversal [ 1 : ] : output . append ( _subsequent_step_to_match ( step ) ) return u'' . join ( output ) | Emit MATCH query code for an entire MATCH traversal sequence . |
38,939 | def _represent_fold ( fold_location , fold_ir_blocks ) : start_let_template = u'$%(mark_name)s = %(base_location)s' traverse_edge_template = u'.%(direction)s("%(edge_name)s")' base_template = start_let_template + traverse_edge_template edge_direction , edge_name = fold_location . get_first_folded_edge ( ) mark_name , _... | Emit a LET clause corresponding to the IR blocks for a |
38,940 | def _construct_output_to_match ( output_block ) : output_block . validate ( ) selections = ( u'%s AS `%s`' % ( output_block . fields [ key ] . to_match ( ) , key ) for key in sorted ( output_block . fields . keys ( ) ) ) return u'SELECT %s FROM' % ( u', ' . join ( selections ) , ) | Transform a ConstructResult block into a MATCH query string . |
38,941 | def _construct_where_to_match ( where_block ) : if where_block . predicate == TrueLiteral : raise AssertionError ( u'Received WHERE block with TrueLiteral predicate: {}' . format ( where_block ) ) return u'WHERE ' + where_block . predicate . to_match ( ) | Transform a Filter block into a MATCH query string . |
38,942 | def emit_code_from_multiple_match_queries ( match_queries ) : optional_variable_base_name = '$optional__' union_variable_name = '$result' query_data = deque ( [ u'SELECT EXPAND(' , union_variable_name , u')' , u' LET ' ] ) optional_variables = [ ] sub_queries = [ emit_code_from_single_match_query ( match_query ) for ma... | Return a MATCH query string from a list of MatchQuery namedtuples . |
38,943 | def emit_code_from_ir ( compound_match_query , compiler_metadata ) : match_queries = compound_match_query . match_queries if len ( match_queries ) == 1 : query_string = emit_code_from_single_match_query ( match_queries [ 0 ] ) elif len ( match_queries ) > 1 : query_string = emit_code_from_multiple_match_queries ( match... | Return a MATCH query string from a CompoundMatchQuery . |
38,944 | def _serialize_date ( value ) : if not isinstance ( value , date ) : raise ValueError ( u'The received object was not a date: ' u'{} {}' . format ( type ( value ) , value ) ) return value . isoformat ( ) | Serialize a Date object to its proper ISO - 8601 representation . |
38,945 | def _serialize_datetime ( value ) : if not isinstance ( value , ( datetime , arrow . Arrow ) ) : raise ValueError ( u'The received object was not a datetime: ' u'{} {}' . format ( type ( value ) , value ) ) return value . isoformat ( ) | Serialize a DateTime object to its proper ISO - 8601 representation . |
38,946 | def _parse_datetime_value ( value ) : if value . endswith ( 'Z' ) : value = value [ : - 1 ] + '+00:00' return arrow . get ( value , 'YYYY-MM-DDTHH:mm:ssZ' ) . datetime | Deserialize a DateTime object from its proper ISO - 8601 representation . |
38,947 | def insert_meta_fields_into_existing_schema ( graphql_schema ) : root_type_name = graphql_schema . get_query_type ( ) . name for type_name , type_obj in six . iteritems ( graphql_schema . get_type_map ( ) ) : if type_name . startswith ( '__' ) or type_name == root_type_name : continue if not isinstance ( type_obj , ( G... | Add compiler - specific meta - fields into all interfaces and types of the specified schema . |
38,948 | def validate_context_for_visiting_vertex_field ( parent_location , vertex_field_name , context ) : if is_in_fold_innermost_scope ( context ) : raise GraphQLCompilationError ( u'Traversing inside a @fold block after filtering on {} or outputting fields ' u'is not supported! Parent location: {}, vertex field name: {}' . ... | Ensure that the current context allows for visiting a vertex field . |
38,949 | def pretty_print_graphql ( query , use_four_spaces = True ) : output = visit ( parse ( query ) , CustomPrintingVisitor ( ) ) if use_four_spaces : return fix_indentation_depth ( output ) return output | Take a GraphQL query pretty print it and return it . |
38,950 | def fix_indentation_depth ( query ) : lines = query . split ( '\n' ) final_lines = [ ] for line in lines : consecutive_spaces = 0 for char in line : if char == ' ' : consecutive_spaces += 1 else : break if consecutive_spaces % 2 != 0 : raise AssertionError ( u'Indentation was not a multiple of two: ' u'{}' . format ( c... | Make indentation use 4 spaces rather than the 2 spaces GraphQL normally uses . |
38,951 | def leave_Directive ( self , node , * args ) : name_to_arg_value = { arg . split ( ':' , 1 ) [ 0 ] : arg for arg in node . arguments } ordered_args = node . arguments directive = DIRECTIVES_BY_NAME . get ( node . name ) if directive : sorted_args = [ ] encountered_argument_names = set ( ) for defined_arg_name in six . ... | Call when exiting a directive node in the ast . |
38,952 | def lower_ir ( ir_blocks , query_metadata_table , type_equivalence_hints = None ) : sanity_check_ir_blocks_from_frontend ( ir_blocks , query_metadata_table ) location_types = { location : location_info . type for location , location_info in query_metadata_table . registered_locations } coerced_locations = { location fo... | Lower the IR into an IR form that can be represented in MATCH queries . |
38,953 | def toposort_classes ( classes ) : def get_class_topolist ( class_name , name_to_class , processed_classes , current_trace ) : if class_name in processed_classes : return [ ] if class_name in current_trace : raise AssertionError ( 'Encountered self-reference in dependency chain of {}' . format ( class_name ) ) cls = na... | Sort class metadatas so that a superclass is always before the subclass |
38,954 | def _list_superclasses ( class_def ) : superclasses = class_def . get ( 'superClasses' , [ ] ) if superclasses : return list ( superclasses ) sup = class_def . get ( 'superClass' , None ) if sup : return [ sup ] else : return [ ] | Return a list of the superclasses of the given class |
38,955 | def _construct_location_stack_entry ( location , num_traverses ) : if not isinstance ( num_traverses , int ) or num_traverses < 0 : raise AssertionError ( u'Attempted to create a LocationStackEntry namedtuple with an invalid ' u'value for "num_traverses" {}. This is not allowed.' . format ( num_traverses ) ) if not isi... | Return a LocationStackEntry namedtuple with the specified parameters . |
38,956 | def _get_fields ( ast ) : if not ast . selection_set : return [ ] , [ ] property_fields = [ ] vertex_fields = [ ] seen_field_names = set ( ) switched_to_vertices = False for field_ast in ast . selection_set . selections : if not isinstance ( field_ast , Field ) : continue name = get_ast_field_name ( field_ast ) if name... | Return a list of vertex fields and a list of property fields for the given AST node . |
38,957 | def _get_inline_fragment ( ast ) : if not ast . selection_set : return None fragments = [ ast_node for ast_node in ast . selection_set . selections if isinstance ( ast_node , InlineFragment ) ] if not fragments : return None if len ( fragments ) > 1 : raise GraphQLCompilationError ( u'Cannot compile GraphQL with more t... | Return the inline fragment at the current AST node or None if no fragment exists . |
38,958 | def _process_output_source_directive ( schema , current_schema_type , ast , location , context , local_unique_directives ) : output_source_directive = local_unique_directives . get ( 'output_source' , None ) if output_source_directive : if has_encountered_output_source ( context ) : raise GraphQLCompilationError ( u'Ca... | Process the output_source directive modifying the context as appropriate . |
38,959 | def _compile_property_ast ( schema , current_schema_type , ast , location , context , unique_local_directives ) : validate_property_directives ( unique_local_directives ) if location . field == COUNT_META_FIELD_NAME : if not is_in_fold_scope ( context ) : raise GraphQLCompilationError ( u'Cannot use the "{}" meta field... | Process property directives at this AST node updating the query context as appropriate . |
38,960 | def _get_recurse_directive_depth ( field_name , field_directives ) : recurse_directive = field_directives [ 'recurse' ] optional_directive = field_directives . get ( 'optional' , None ) if optional_directive : raise GraphQLCompilationError ( u'Found both @optional and @recurse on ' u'the same vertex field: {}' . format... | Validate and return the depth parameter of the recurse directive . |
38,961 | def _validate_recurse_directive_types ( current_schema_type , field_schema_type , context ) : type_hints = context [ 'type_equivalence_hints' ] . get ( field_schema_type ) type_hints_inverse = context [ 'type_equivalence_hints_inverse' ] . get ( field_schema_type ) allowed_current_types = { field_schema_type } if type_... | Perform type checks on the enclosing type and the recursed type for a recurse directive . |
38,962 | def _compile_fragment_ast ( schema , current_schema_type , ast , location , context ) : query_metadata_table = context [ 'metadata' ] coerces_to_type_name = ast . type_condition . name . value coerces_to_type_obj = schema . get_type ( coerces_to_type_name ) basic_blocks = [ ] is_same_type_as_scope = current_schema_type... | Return a list of basic blocks corresponding to the inline fragment at this AST node . |
38,963 | def _compile_ast_node_to_ir ( schema , current_schema_type , ast , location , context ) : basic_blocks = [ ] local_unique_directives = get_unique_directives ( ast ) fields = _get_fields ( ast ) vertex_fields , property_fields = fields fragment = _get_inline_fragment ( ast ) filter_operations = get_local_filter_directiv... | Compile the given GraphQL AST node into a list of basic blocks . |
38,964 | def _validate_all_tags_are_used ( metadata ) : tag_names = set ( [ tag_name for tag_name , _ in metadata . tags ] ) filter_arg_names = set ( ) for location , _ in metadata . registered_locations : for filter_info in metadata . get_filter_infos ( location ) : for filter_arg in filter_info . args : if is_tag_argument ( f... | Ensure all tags are used in some filter . |
38,965 | def _compile_output_step ( outputs ) : if not outputs : raise GraphQLCompilationError ( u'No fields were selected for output! Please mark at least ' u'one field with the @output directive.' ) output_fields = { } for output_name , output_context in six . iteritems ( outputs ) : location = output_context [ 'location' ] o... | Construct the final ConstructResult basic block that defines the output format of the query . |
38,966 | def _validate_schema_and_ast ( schema , ast ) : core_graphql_errors = validate ( schema , ast ) unsupported_default_directives = frozenset ( [ frozenset ( [ 'include' , frozenset ( [ 'FIELD' , 'FRAGMENT_SPREAD' , 'INLINE_FRAGMENT' ] ) , frozenset ( [ 'if' ] ) ] ) , frozenset ( [ 'skip' , frozenset ( [ 'FIELD' , 'FRAGME... | Validate the supplied graphql schema and ast . |
38,967 | def graphql_to_ir ( schema , graphql_string , type_equivalence_hints = None ) : graphql_string = _preprocess_graphql_string ( graphql_string ) try : ast = parse ( graphql_string ) except GraphQLSyntaxError as e : raise GraphQLParsingError ( e ) validation_errors = _validate_schema_and_ast ( schema , ast ) if validation... | Convert the given GraphQL string into compiler IR using the given schema object . |
38,968 | def pretty_print_gremlin ( gremlin ) : gremlin = remove_custom_formatting ( gremlin ) too_many_parts = re . split ( r'([)}]|scatter)[ ]?\.' , gremlin ) parts = [ too_many_parts [ i ] + too_many_parts [ i + 1 ] for i in six . moves . xrange ( 0 , len ( too_many_parts ) - 1 , 2 ) ] parts . append ( too_many_parts [ - 1 ]... | Return a human - readable representation of a gremlin command string . |
38,969 | def pretty_print_match ( match , parameterized = True ) : left_curly = '{{' if parameterized else '{' right_curly = '}}' if parameterized else '}' match = remove_custom_formatting ( match ) parts = re . split ( '({}|{})' . format ( left_curly , right_curly ) , match ) inside_braces = False indent_size = 4 indent = ' ' ... | Return a human - readable representation of a parameterized MATCH query string . |
38,970 | def represent_float_as_str ( value ) : if not isinstance ( value , float ) : raise GraphQLInvalidArgumentError ( u'Attempting to represent a non-float as a float: ' u'{}' . format ( value ) ) with decimal . localcontext ( ) as ctx : ctx . prec = 20 return u'{:f}' . format ( decimal . Decimal ( value ) ) | Represent a float as a string without losing precision . |
38,971 | def coerce_to_decimal ( value ) : if isinstance ( value , decimal . Decimal ) : return value else : try : return decimal . Decimal ( value ) except decimal . InvalidOperation as e : raise GraphQLInvalidArgumentError ( e ) | Attempt to coerce the value to a Decimal or raise an error if unable to do so . |
38,972 | def make_replacement_visitor ( find_expression , replace_expression ) : def visitor_fn ( expression ) : if expression == find_expression : return replace_expression else : return expression return visitor_fn | Return a visitor function that replaces every instance of one expression with another one . |
38,973 | def make_type_replacement_visitor ( find_types , replacement_func ) : def visitor_fn ( expression ) : if isinstance ( expression , find_types ) : return replacement_func ( expression ) else : return expression return visitor_fn | Return a visitor function that replaces expressions of a given type with new expressions . |
38,974 | def _validate_operator_name ( operator , supported_operators ) : if not isinstance ( operator , six . text_type ) : raise TypeError ( u'Expected operator as unicode string, got: {} {}' . format ( type ( operator ) . __name__ , operator ) ) if operator not in supported_operators : raise GraphQLCompilationError ( u'Unrec... | Ensure the named operator is valid and supported . |
38,975 | def validate ( self ) : if self . value is None or self . value is True or self . value is False : return if isinstance ( self . value , six . string_types ) : validate_safe_string ( self . value ) return if isinstance ( self . value , int ) : return if isinstance ( self . value , list ) : if len ( self . value ) > 0 :... | Validate that the Literal is correctly representable . |
38,976 | def validate ( self ) : if not self . variable_name . startswith ( u'$' ) : raise GraphQLCompilationError ( u'Expected variable name to start with $, but was: ' u'{}' . format ( self . variable_name ) ) if self . variable_name in RESERVED_MATCH_KEYWORDS : raise GraphQLCompilationError ( u'Cannot use reserved MATCH keyw... | Validate that the Variable is correctly representable . |
38,977 | def to_match ( self ) : self . validate ( ) variable_with_no_dollar_sign = self . variable_name [ 1 : ] match_variable_name = '{%s}' % ( six . text_type ( variable_with_no_dollar_sign ) , ) if GraphQLDate . is_same_type ( self . inferred_type ) : return u'date(%s, "%s")' % ( match_variable_name , STANDARD_DATE_FORMAT )... | Return a unicode object with the MATCH representation of this Variable . |
38,978 | def validate ( self ) : if not isinstance ( self . location , Location ) : raise TypeError ( u'Expected Location location, got: {} {}' . format ( type ( self . location ) . __name__ , self . location ) ) if self . location . field is None : raise AssertionError ( u'Received Location without a field: {}' . format ( self... | Validate that the GlobalContextField is correctly representable . |
38,979 | def to_match ( self ) : self . validate ( ) mark_name , field_name = self . location . get_location_name ( ) validate_safe_string ( mark_name ) validate_safe_string ( field_name ) return u'%s.%s' % ( mark_name , field_name ) | Return a unicode object with the MATCH representation of this GlobalContextField . |
38,980 | def to_match ( self ) : self . validate ( ) mark_name , field_name = self . location . get_location_name ( ) validate_safe_string ( mark_name ) if field_name is None : return u'$matched.%s' % ( mark_name , ) else : validate_safe_string ( field_name ) return u'$matched.%s.%s' % ( mark_name , field_name ) | Return a unicode object with the MATCH representation of this ContextField . |
38,981 | def validate ( self ) : if not isinstance ( self . location , Location ) : raise TypeError ( u'Expected Location location, got: {} {}' . format ( type ( self . location ) . __name__ , self . location ) ) if not self . location . field : raise ValueError ( u'Expected Location object that points to a field, got: ' u'{}' ... | Validate that the OutputContextField is correctly representable . |
38,982 | def validate ( self ) : if not isinstance ( self . fold_scope_location , FoldScopeLocation ) : raise TypeError ( u'Expected FoldScopeLocation fold_scope_location, got: {} {}' . format ( type ( self . fold_scope_location ) , self . fold_scope_location ) ) if self . fold_scope_location . field is None : raise ValueError ... | Validate that the FoldedContextField is correctly representable . |
38,983 | def validate ( self ) : if not isinstance ( self . fold_scope_location , FoldScopeLocation ) : raise TypeError ( u'Expected FoldScopeLocation fold_scope_location, got: {} {}' . format ( type ( self . fold_scope_location ) , self . fold_scope_location ) ) if self . fold_scope_location . field != COUNT_META_FIELD_NAME : ... | Validate that the FoldCountContextField is correctly representable . |
38,984 | def validate ( self ) : if not isinstance ( self . location , Location ) : raise TypeError ( u'Expected Location location, got: {} {}' . format ( type ( self . location ) . __name__ , self . location ) ) if self . location . field : raise ValueError ( u'Expected location to point to a vertex, ' u'but found a field: {}'... | Validate that the ContextFieldExistence is correctly representable . |
38,985 | def validate ( self ) : _validate_operator_name ( self . operator , UnaryTransformation . SUPPORTED_OPERATORS ) if not isinstance ( self . inner_expression , Expression ) : raise TypeError ( u'Expected Expression inner_expression, got {} {}' . format ( type ( self . inner_expression ) . __name__ , self . inner_expressi... | Validate that the UnaryTransformation is correctly representable . |
38,986 | def to_match ( self ) : self . validate ( ) translation_table = { u'size' : u'size()' , } match_operator = translation_table . get ( self . operator ) if not match_operator : raise AssertionError ( u'Unrecognized operator used: ' u'{} {}' . format ( self . operator , self ) ) template = u'%(inner)s.%(operator)s' args =... | Return a unicode object with the MATCH representation of this UnaryTransformation . |
38,987 | def validate ( self ) : _validate_operator_name ( self . operator , BinaryComposition . SUPPORTED_OPERATORS ) if not isinstance ( self . left , Expression ) : raise TypeError ( u'Expected Expression left, got: {} {} {}' . format ( type ( self . left ) . __name__ , self . left , self ) ) if not isinstance ( self . right... | Validate that the BinaryComposition is correctly representable . |
38,988 | def to_match ( self ) : self . validate ( ) regular_operator_format = '(%(left)s %(operator)s %(right)s)' inverted_operator_format = '(%(right)s %(operator)s %(left)s)' intersects_operator_format = '(%(operator)s(%(left)s, %(right)s).asList().size() > 0)' if any ( ( isinstance ( self . left , Literal ) and self . left ... | Return a unicode object with the MATCH representation of this BinaryComposition . |
38,989 | def validate ( self ) : if not isinstance ( self . predicate , Expression ) : raise TypeError ( u'Expected Expression predicate, got: {} {}' . format ( type ( self . predicate ) . __name__ , self . predicate ) ) if not isinstance ( self . if_true , Expression ) : raise TypeError ( u'Expected Expression if_true, got: {}... | Validate that the TernaryConditional is correctly representable . |
38,990 | def to_match ( self ) : self . validate ( ) def visitor_fn ( expression ) : if isinstance ( expression , TernaryConditional ) : raise ValueError ( u'Cannot emit MATCH code for TernaryConditional that contains ' u'in its predicate another TernaryConditional: ' u'{} {}' . format ( expression , self ) ) return expression ... | Return a unicode object with the MATCH representation of this TernaryConditional . |
38,991 | def sanity_check_ir_blocks_from_frontend ( ir_blocks , query_metadata_table ) : if not ir_blocks : raise AssertionError ( u'Received no ir_blocks: {}' . format ( ir_blocks ) ) _sanity_check_fold_scope_locations_are_unique ( ir_blocks ) _sanity_check_no_nested_folds ( ir_blocks ) _sanity_check_query_root_block ( ir_bloc... | Assert that IR blocks originating from the frontend do not have nonsensical structure . |
38,992 | def _sanity_check_registered_locations_parent_locations ( query_metadata_table ) : for location , location_info in query_metadata_table . registered_locations : if ( location != query_metadata_table . root_location and not query_metadata_table . root_location . is_revisited_at ( location ) ) : if location_info . parent... | Assert that all registered locations parent locations are also registered . |
38,993 | def _sanity_check_all_marked_locations_are_registered ( ir_blocks , query_metadata_table ) : registered_locations = { location for location , _ in query_metadata_table . registered_locations } ir_encountered_locations = { block . location for block in ir_blocks if isinstance ( block , MarkLocation ) } unregistered_loca... | Assert that all locations in MarkLocation blocks have registered and valid metadata . |
38,994 | def _sanity_check_fold_scope_locations_are_unique ( ir_blocks ) : observed_locations = dict ( ) for block in ir_blocks : if isinstance ( block , Fold ) : alternate = observed_locations . get ( block . fold_scope_location , None ) if alternate is not None : raise AssertionError ( u'Found two Fold blocks with identical F... | Assert that every FoldScopeLocation that exists on a Fold block is unique . |
38,995 | def _sanity_check_no_nested_folds ( ir_blocks ) : fold_seen = False for block in ir_blocks : if isinstance ( block , Fold ) : if fold_seen : raise AssertionError ( u'Found a nested Fold contexts: {}' . format ( ir_blocks ) ) else : fold_seen = True elif isinstance ( block , Unfold ) : if not fold_seen : raise Assertion... | Assert that there are no nested Fold contexts and that every Fold has a matching Unfold . |
38,996 | def _sanity_check_query_root_block ( ir_blocks ) : if not isinstance ( ir_blocks [ 0 ] , QueryRoot ) : raise AssertionError ( u'The first block was not QueryRoot: {}' . format ( ir_blocks ) ) for block in ir_blocks [ 1 : ] : if isinstance ( block , QueryRoot ) : raise AssertionError ( u'Found QueryRoot after the first ... | Assert that QueryRoot is always the first block and only the first block . |
38,997 | def _sanity_check_construct_result_block ( ir_blocks ) : if not isinstance ( ir_blocks [ - 1 ] , ConstructResult ) : raise AssertionError ( u'The last block was not ConstructResult: {}' . format ( ir_blocks ) ) for block in ir_blocks [ : - 1 ] : if isinstance ( block , ConstructResult ) : raise AssertionError ( u'Found... | Assert that ConstructResult is always the last block and only the last block . |
38,998 | def _sanity_check_block_pairwise_constraints ( ir_blocks ) : for first_block , second_block in pairwise ( ir_blocks ) : if isinstance ( first_block , MarkLocation ) and isinstance ( second_block , Filter ) : raise AssertionError ( u'Found Filter after MarkLocation block: {}' . format ( ir_blocks ) ) if isinstance ( fir... | Assert that adjacent blocks obey all invariants . |
38,999 | def _sanity_check_mark_location_preceding_optional_traverse ( ir_blocks ) : _ , new_ir_blocks = extract_folds_from_ir_blocks ( ir_blocks ) for first_block , second_block in pairwise ( new_ir_blocks ) : if isinstance ( second_block , Traverse ) and second_block . optional : if not isinstance ( first_block , MarkLocation... | Assert that optional Traverse blocks are preceded by a MarkLocation . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.