_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q228300 | pretty_print_graphql | train | def pretty_print_graphql(query, use_four_spaces=True):
"""Take a GraphQL query, pretty print it, and return it."""
# Use our custom visitor, which fixes directive argument order
# to get the canonical representation
output = visit(parse(query), CustomPrintingVisitor())
# Using four spaces for inden... | python | {
"resource": ""
} |
q228301 | fix_indentation_depth | train | def fix_indentation_depth(query):
"""Make indentation use 4 spaces, rather than the 2 spaces GraphQL normally uses."""
lines = query.split('\n')
final_lines = []
for line in lines:
consecutive_spaces = 0
for char in line:
if char == ' ':
consecutive_spaces +=... | python | {
"resource": ""
} |
q228302 | CustomPrintingVisitor.leave_Directive | train | def leave_Directive(self, node, *args):
"""Call when exiting a directive node in the ast."""
name_to_arg_value = {
# Taking [0] is ok here because the GraphQL parser checks for the
# existence of ':' in directive arguments.
arg.split(':', 1)[0]: arg
for ar... | python | {
"resource": ""
} |
q228303 | lower_ir | train | def lower_ir(ir_blocks, query_metadata_table, type_equivalence_hints=None):
"""Lower the IR into an IR form that can be represented in MATCH queries.
Args:
ir_blocks: list of IR blocks to lower into MATCH-compatible form
query_metadata_table: QueryMetadataTable object containing all metadata co... | python | {
"resource": ""
} |
q228304 | toposort_classes | train | def toposort_classes(classes):
"""Sort class metadatas so that a superclass is always before the subclass"""
def get_class_topolist(class_name, name_to_class, processed_classes, current_trace):
"""Return a topologically sorted list of this class's dependencies and class itself
Args:
... | python | {
"resource": ""
} |
q228305 | _list_superclasses | train | def _list_superclasses(class_def):
"""Return a list of the superclasses of the given class"""
superclasses = class_def.get('superClasses', [])
if superclasses:
# Make sure to duplicate the list
return list(superclasses)
sup = class_def.get('superClass', None)
if sup:
return ... | python | {
"resource": ""
} |
q228306 | _construct_location_stack_entry | train | def _construct_location_stack_entry(location, num_traverses):
"""Return a LocationStackEntry namedtuple with the specified parameters."""
if not isinstance(num_traverses, int) or num_traverses < 0:
raise AssertionError(u'Attempted to create a LocationStackEntry namedtuple with an invalid '
... | python | {
"resource": ""
} |
q228307 | _get_fields | train | def _get_fields(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, obtaine... | python | {
"resource": ""
} |
q228308 | _get_inline_fragment | train | def _get_inline_fragment(ast):
"""Return the inline fragment at the current AST node, or None if no fragment exists."""
if not ast.selection_set:
# There is nothing selected here, so no fragment.
return None
fragments = [
ast_node
for ast_node in ast.selection_set.selections... | python | {
"resource": ""
} |
q228309 | _process_output_source_directive | train | def _process_output_source_directive(schema, current_schema_type, ast,
location, context, local_unique_directives):
"""Process the output_source directive, modifying the context as appropriate.
Args:
schema: GraphQL schema object, obtained from the graphql library
... | python | {
"resource": ""
} |
q228310 | _compile_property_ast | train | def _compile_property_ast(schema, current_schema_type, ast, location,
context, unique_local_directives):
"""Process property directives at this AST node, updating the query context as appropriate.
Args:
schema: GraphQL schema object, obtained from the graphql library
c... | python | {
"resource": ""
} |
q228311 | _get_recurse_directive_depth | train | def _get_recurse_directive_depth(field_name, field_directives):
"""Validate and return the depth parameter of the recurse directive."""
recurse_directive = field_directives['recurse']
optional_directive = field_directives.get('optional', None)
if optional_directive:
raise GraphQLCompilationErro... | python | {
"resource": ""
} |
q228312 | _validate_recurse_directive_types | train | def _validate_recurse_directive_types(current_schema_type, field_schema_type, context):
"""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... | python | {
"resource": ""
} |
q228313 | _compile_fragment_ast | train | def _compile_fragment_ast(schema, current_schema_type, ast, location, context):
"""Return a list of basic blocks corresponding to the inline fragment at this AST node.
Args:
schema: GraphQL schema object, obtained from the graphql library
current_schema_type: GraphQLType, the schema type at the... | python | {
"resource": ""
} |
q228314 | _compile_ast_node_to_ir | train | def _compile_ast_node_to_ir(schema, current_schema_type, ast, location, context):
"""Compile the given GraphQL AST node into a list of basic blocks.
Args:
schema: GraphQL schema object, obtained from the graphql library
current_schema_type: GraphQLType, the schema type at the current location
... | python | {
"resource": ""
} |
q228315 | _validate_all_tags_are_used | train | def _validate_all_tags_are_used(metadata):
"""Ensure all tags are used in some filter."""
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):
fo... | python | {
"resource": ""
} |
q228316 | _compile_output_step | train | def _compile_output_step(outputs):
"""Construct the final ConstructResult basic block that defines the output format of the query.
Args:
outputs: dict, output name (string) -> output data dict, specifying the location
from where to get the data, and whether the data is optional (and th... | python | {
"resource": ""
} |
q228317 | _validate_schema_and_ast | train | def _validate_schema_and_ast(schema, ast):
"""Validate the supplied graphql schema and ast.
This method wraps around graphql-core's validation to enforce a stricter requirement of the
schema -- all directives supported by the compiler must be declared by the schema, regardless of
whether each directive... | python | {
"resource": ""
} |
q228318 | graphql_to_ir | train | def graphql_to_ir(schema, graphql_string, type_equivalence_hints=None):
"""Convert the given GraphQL string into compiler IR, using the given schema object.
Args:
schema: GraphQL schema object, created using the GraphQL library
graphql_string: string containing the GraphQL to compile to compile... | python | {
"resource": ""
} |
q228319 | pretty_print_gremlin | train | def pretty_print_gremlin(gremlin):
"""Return a human-readable representation of a gremlin command string."""
gremlin = remove_custom_formatting(gremlin)
too_many_parts = re.split(r'([)}]|scatter)[ ]?\.', gremlin)
# Put the ) and } back on.
parts = [
too_many_parts[i] + too_many_parts[i + 1]... | python | {
"resource": ""
} |
q228320 | pretty_print_match | train | def pretty_print_match(match, parameterized=True):
"""Return a human-readable representation of a parameterized MATCH query string."""
left_curly = '{{' if parameterized else '{'
right_curly = '}}' if parameterized else '}'
match = remove_custom_formatting(match)
parts = re.split('({}|{})'.format(le... | python | {
"resource": ""
} |
q228321 | represent_float_as_str | train | def represent_float_as_str(value):
"""Represent a float as a string without losing precision."""
# In Python 2, calling str() on a float object loses precision:
#
# In [1]: 1.23456789012345678
# Out[1]: 1.2345678901234567
#
# In [2]: 1.2345678901234567
# Out[2]: 1.2345678901234567
#
... | python | {
"resource": ""
} |
q228322 | coerce_to_decimal | train | def coerce_to_decimal(value):
"""Attempt to coerce the value to a Decimal, or raise an error if unable to do so."""
if isinstance(value, decimal.Decimal):
return value
else:
try:
return decimal.Decimal(value)
except decimal.InvalidOperation as e:
raise GraphQL... | python | {
"resource": ""
} |
q228323 | make_replacement_visitor | train | def make_replacement_visitor(find_expression, replace_expression):
"""Return a visitor function that replaces every instance of one expression with another one."""
def visitor_fn(expression):
"""Return the replacement if this expression matches the expression we're looking for."""
if expression ... | python | {
"resource": ""
} |
q228324 | make_type_replacement_visitor | train | def make_type_replacement_visitor(find_types, replacement_func):
"""Return a visitor function that replaces expressions of a given type with new expressions."""
def visitor_fn(expression):
"""Return a replacement expression if the original expression is of the correct type."""
if isinstance(expr... | python | {
"resource": ""
} |
q228325 | _validate_operator_name | train | def _validate_operator_name(operator, supported_operators):
"""Ensure the named operator is valid and supported."""
if not isinstance(operator, six.text_type):
raise TypeError(u'Expected operator as unicode string, got: {} {}'.format(
type(operator).__name__, operator))
if operator not ... | python | {
"resource": ""
} |
q228326 | Literal.validate | train | def validate(self):
"""Validate that the Literal is correctly representable."""
# Literals representing boolean values or None are correctly representable and supported.
if self.value is None or self.value is True or self.value is False:
return
# Literal safe strings are cor... | python | {
"resource": ""
} |
q228327 | Variable.validate | train | def validate(self):
"""Validate that the Variable is correctly representable."""
# Get the first letter, or empty string if it doesn't exist.
if not self.variable_name.startswith(u'$'):
raise GraphQLCompilationError(u'Expected variable name to start with $, but was: '
... | python | {
"resource": ""
} |
q228328 | Variable.to_match | train | def to_match(self):
"""Return a unicode object with the MATCH representation of this Variable."""
self.validate()
# We don't want the dollar sign as part of the variable name.
variable_with_no_dollar_sign = self.variable_name[1:]
match_variable_name = '{%s}' % (six.text_type(va... | python | {
"resource": ""
} |
q228329 | GlobalContextField.validate | train | def validate(self):
"""Validate that the GlobalContextField is correctly representable."""
if not isinstance(self.location, Location):
raise TypeError(u'Expected Location location, got: {} {}'
.format(type(self.location).__name__, self.location))
if self.... | python | {
"resource": ""
} |
q228330 | GlobalContextField.to_match | train | def to_match(self):
"""Return a unicode object with the MATCH representation of this GlobalContextField."""
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... | python | {
"resource": ""
} |
q228331 | ContextField.to_match | train | def to_match(self):
"""Return a unicode object with the MATCH representation of this ContextField."""
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,... | python | {
"resource": ""
} |
q228332 | OutputContextField.validate | train | def validate(self):
"""Validate that the OutputContextField is correctly representable."""
if not isinstance(self.location, Location):
raise TypeError(u'Expected Location location, got: {} {}'.format(
type(self.location).__name__, self.location))
if not self.location... | python | {
"resource": ""
} |
q228333 | FoldedContextField.validate | train | def validate(self):
"""Validate that the FoldedContextField is correctly representable."""
if not isinstance(self.fold_scope_location, FoldScopeLocation):
raise TypeError(u'Expected FoldScopeLocation fold_scope_location, got: {} {}'.format(
type(self.fold_scope_location), sel... | python | {
"resource": ""
} |
q228334 | FoldCountContextField.validate | train | def validate(self):
"""Validate that the FoldCountContextField is correctly representable."""
if not isinstance(self.fold_scope_location, FoldScopeLocation):
raise TypeError(u'Expected FoldScopeLocation fold_scope_location, got: {} {}'.format(
type(self.fold_scope_location), ... | python | {
"resource": ""
} |
q228335 | ContextFieldExistence.validate | train | def validate(self):
"""Validate that the ContextFieldExistence is correctly representable."""
if not isinstance(self.location, Location):
raise TypeError(u'Expected Location location, got: {} {}'.format(
type(self.location).__name__, self.location))
if self.location.... | python | {
"resource": ""
} |
q228336 | UnaryTransformation.validate | train | def validate(self):
"""Validate that the UnaryTransformation is correctly representable."""
_validate_operator_name(self.operator, UnaryTransformation.SUPPORTED_OPERATORS)
if not isinstance(self.inner_expression, Expression):
raise TypeError(u'Expected Expression inner_expression, g... | python | {
"resource": ""
} |
q228337 | UnaryTransformation.to_match | train | def to_match(self):
"""Return a unicode object with the MATCH representation of this UnaryTransformation."""
self.validate()
translation_table = {
u'size': u'size()',
}
match_operator = translation_table.get(self.operator)
if not match_operator:
r... | python | {
"resource": ""
} |
q228338 | BinaryComposition.validate | train | def validate(self):
"""Validate that the BinaryComposition is correctly representable."""
_validate_operator_name(self.operator, BinaryComposition.SUPPORTED_OPERATORS)
if not isinstance(self.left, Expression):
raise TypeError(u'Expected Expression left, got: {} {} {}'.format(
... | python | {
"resource": ""
} |
q228339 | BinaryComposition.to_match | train | def to_match(self):
"""Return a unicode object with the MATCH representation of this BinaryComposition."""
self.validate()
# The MATCH versions of some operators require an inverted order of arguments.
# pylint: disable=unused-variable
regular_operator_format = '(%(left)s %(oper... | python | {
"resource": ""
} |
q228340 | TernaryConditional.validate | train | def validate(self):
"""Validate that the TernaryConditional is correctly representable."""
if not isinstance(self.predicate, Expression):
raise TypeError(u'Expected Expression predicate, got: {} {}'.format(
type(self.predicate).__name__, self.predicate))
if not isinst... | python | {
"resource": ""
} |
q228341 | TernaryConditional.to_match | train | def to_match(self):
"""Return a unicode object with the MATCH representation of this TernaryConditional."""
self.validate()
# For MATCH, an additional validation step is needed -- we currently do not support
# emitting MATCH code for TernaryConditional that contains another TernaryCondi... | python | {
"resource": ""
} |
q228342 | sanity_check_ir_blocks_from_frontend | train | def sanity_check_ir_blocks_from_frontend(ir_blocks, query_metadata_table):
"""Assert that IR blocks originating from the frontend do not have nonsensical structure.
Args:
ir_blocks: list of BasicBlocks representing the IR to sanity-check
Raises:
AssertionError, if the IR has unexpected str... | python | {
"resource": ""
} |
q228343 | _sanity_check_registered_locations_parent_locations | train | def _sanity_check_registered_locations_parent_locations(query_metadata_table):
"""Assert that all registered locations' parent locations are also registered."""
for location, location_info in query_metadata_table.registered_locations:
if (location != query_metadata_table.root_location and
... | python | {
"resource": ""
} |
q228344 | _sanity_check_all_marked_locations_are_registered | train | def _sanity_check_all_marked_locations_are_registered(ir_blocks, query_metadata_table):
"""Assert that all locations in MarkLocation blocks have registered and valid metadata."""
# Grab all the registered locations, then make sure that:
# - Any location that appears in a MarkLocation block is also registere... | python | {
"resource": ""
} |
q228345 | _sanity_check_fold_scope_locations_are_unique | train | def _sanity_check_fold_scope_locations_are_unique(ir_blocks):
"""Assert that every FoldScopeLocation that exists on a Fold block is unique."""
observed_locations = dict()
for block in ir_blocks:
if isinstance(block, Fold):
alternate = observed_locations.get(block.fold_scope_location, Non... | python | {
"resource": ""
} |
q228346 | _sanity_check_no_nested_folds | train | def _sanity_check_no_nested_folds(ir_blocks):
"""Assert that there are no nested Fold contexts, and that every Fold has a matching Unfold."""
fold_seen = False
for block in ir_blocks:
if isinstance(block, Fold):
if fold_seen:
raise AssertionError(u'Found a nested Fold con... | python | {
"resource": ""
} |
q228347 | _sanity_check_query_root_block | train | def _sanity_check_query_root_block(ir_blocks):
"""Assert that QueryRoot is always the first block, and only the first block."""
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 isinstan... | python | {
"resource": ""
} |
q228348 | _sanity_check_construct_result_block | train | def _sanity_check_construct_result_block(ir_blocks):
"""Assert that ConstructResult is always the last block, and only the last block."""
if not isinstance(ir_blocks[-1], ConstructResult):
raise AssertionError(u'The last block was not ConstructResult: {}'.format(ir_blocks))
for block in ir_blocks[:-... | python | {
"resource": ""
} |
q228349 | _sanity_check_block_pairwise_constraints | train | def _sanity_check_block_pairwise_constraints(ir_blocks):
"""Assert that adjacent blocks obey all invariants."""
for first_block, second_block in pairwise(ir_blocks):
# Always Filter before MarkLocation, never after.
if isinstance(first_block, MarkLocation) and isinstance(second_block, Filter):
... | python | {
"resource": ""
} |
q228350 | _sanity_check_mark_location_preceding_optional_traverse | train | def _sanity_check_mark_location_preceding_optional_traverse(ir_blocks):
"""Assert that optional Traverse blocks are preceded by a MarkLocation."""
# Once all fold blocks are removed, each optional Traverse must have
# a MarkLocation block immediately before it.
_, new_ir_blocks = extract_folds_from_ir_b... | python | {
"resource": ""
} |
q228351 | _sanity_check_every_location_is_marked | train | def _sanity_check_every_location_is_marked(ir_blocks):
"""Ensure that every new location is marked with a MarkLocation block."""
# Exactly one MarkLocation block is found between any block that starts an interval of blocks
# that all affect the same query position, and the first subsequent block that affect... | python | {
"resource": ""
} |
q228352 | _sanity_check_coerce_type_outside_of_fold | train | def _sanity_check_coerce_type_outside_of_fold(ir_blocks):
"""Ensure that CoerceType not in a @fold are followed by a MarkLocation or Filter block."""
is_in_fold = False
for first_block, second_block in pairwise(ir_blocks):
if isinstance(first_block, Fold):
is_in_fold = True
if n... | python | {
"resource": ""
} |
q228353 | validate_supported_property_type_id | train | def validate_supported_property_type_id(property_name, property_type_id):
"""Ensure that the given property type_id is supported by the graph."""
if property_type_id not in PROPERTY_TYPE_ID_TO_NAME:
raise AssertionError(u'Property "{}" has unsupported property type id: '
u'{... | python | {
"resource": ""
} |
q228354 | _parse_bool_default_value | train | def _parse_bool_default_value(property_name, default_value_string):
"""Parse and return the default value for a boolean property."""
lowercased_value_string = default_value_string.lower()
if lowercased_value_string in {'0', 'false'}:
return False
elif lowercased_value_string in {'1', 'true'}:
... | python | {
"resource": ""
} |
q228355 | _parse_datetime_default_value | train | def _parse_datetime_default_value(property_name, default_value_string):
"""Parse and return the default value for a datetime property."""
# OrientDB doesn't use ISO-8601 datetime format, so we have to parse it manually
# and then turn it into a python datetime object. strptime() will raise an exception
... | python | {
"resource": ""
} |
q228356 | _parse_date_default_value | train | def _parse_date_default_value(property_name, default_value_string):
"""Parse and return the default value for a date property."""
# OrientDB doesn't use ISO-8601 datetime format, so we have to parse it manually
# and then turn it into a python datetime object. strptime() will raise an exception
# if the... | python | {
"resource": ""
} |
q228357 | parse_default_property_value | train | def parse_default_property_value(property_name, property_type_id, default_value_string):
"""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... | python | {
"resource": ""
} |
q228358 | _compile_graphql_generic | train | def _compile_graphql_generic(language, lowering_func, query_emitter_func,
schema, graphql_string, type_equivalence_hints, compiler_metadata):
"""Compile the GraphQL input, lowering and emitting the query using the given functions.
Args:
language: string indicating the targe... | python | {
"resource": ""
} |
q228359 | scalar_leaf_only | train | def scalar_leaf_only(operator):
"""Ensure the filter function is only applied to scalar leaf types."""
def decorator(f):
"""Decorate the supplied function with the "scalar_leaf_only" logic."""
@wraps(f)
def wrapper(filter_operation_info, context, parameters, *args, **kwargs):
... | python | {
"resource": ""
} |
q228360 | vertex_field_only | train | def vertex_field_only(operator):
"""Ensure the filter function is only applied to vertex field types."""
def decorator(f):
"""Decorate the supplied function with the "vertex_field_only" logic."""
@wraps(f)
def wrapper(filter_operation_info, context, parameters, *args, **kwargs):
... | python | {
"resource": ""
} |
q228361 | takes_parameters | train | def takes_parameters(count):
"""Ensure the filter function has "count" parameters specified."""
def decorator(f):
"""Decorate the supplied function with the "takes_parameters" logic."""
@wraps(f)
def wrapper(filter_operation_info, location, context, parameters, *args, **kwargs):
... | python | {
"resource": ""
} |
q228362 | _represent_argument | train | def _represent_argument(directive_location, context, argument, inferred_type):
"""Return a two-element tuple that represents the argument to the directive being processed.
Args:
directive_location: Location where the directive is used.
context: dict, various per-compilation data (e.g. declared ... | python | {
"resource": ""
} |
q228363 | _process_comparison_filter_directive | train | def _process_comparison_filter_directive(filter_operation_info, location,
context, parameters, operator=None):
"""Return a Filter basic block that performs the given comparison against the property field.
Args:
filter_operation_info: FilterOperationInfo object, ... | python | {
"resource": ""
} |
q228364 | _process_has_edge_degree_filter_directive | train | def _process_has_edge_degree_filter_directive(filter_operation_info, location, context, parameters):
"""Return a Filter basic block that checks the degree of the edge to the given vertex field.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
... | python | {
"resource": ""
} |
q228365 | _process_name_or_alias_filter_directive | train | def _process_name_or_alias_filter_directive(filter_operation_info, location, context, parameters):
"""Return a Filter basic block that checks for a match against an Entity's name or alias.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
... | python | {
"resource": ""
} |
q228366 | _process_between_filter_directive | train | def _process_between_filter_directive(filter_operation_info, location, context, parameters):
"""Return a Filter basic block that checks that a field is between two values, inclusive.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
... | python | {
"resource": ""
} |
q228367 | _process_in_collection_filter_directive | train | def _process_in_collection_filter_directive(filter_operation_info, location, context, parameters):
"""Return a Filter basic block that checks for a value's existence in a collection.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
... | python | {
"resource": ""
} |
q228368 | _process_has_substring_filter_directive | train | def _process_has_substring_filter_directive(filter_operation_info, location, context, parameters):
"""Return a Filter basic block that checks if the directive arg is a substring of the field.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
... | python | {
"resource": ""
} |
q228369 | _process_contains_filter_directive | train | def _process_contains_filter_directive(filter_operation_info, location, context, parameters):
"""Return a Filter basic block that checks if the directive arg is contained in the field.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
... | python | {
"resource": ""
} |
q228370 | _process_intersects_filter_directive | train | def _process_intersects_filter_directive(filter_operation_info, location, context, parameters):
"""Return a Filter basic block that checks if the directive arg and the field intersect.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
... | python | {
"resource": ""
} |
q228371 | is_filter_with_outer_scope_vertex_field_operator | train | def is_filter_with_outer_scope_vertex_field_operator(directive):
"""Return True if we have a filter directive whose operator applies to the outer scope."""
if directive.name.value != 'filter':
return False
op_name, _ = _get_filter_op_name_and_values(directive)
return op_name in OUTER_SCOPE_VERT... | python | {
"resource": ""
} |
q228372 | process_filter_directive | train | def process_filter_directive(filter_operation_info, location, context):
"""Return a Filter basic block that corresponds to the filter operation in the directive.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
of the field ... | python | {
"resource": ""
} |
q228373 | get_schema_type_name | train | def get_schema_type_name(node, context):
"""Return the GraphQL type name of a node."""
query_path = node.query_path
if query_path not in context.query_path_to_location_info:
raise AssertionError(
u'Unable to find type name for query path {} with context {}.'.format(
query... | python | {
"resource": ""
} |
q228374 | get_node_at_path | train | def get_node_at_path(query_path, context):
"""Return the SqlNode associated with the query path."""
if query_path not in context.query_path_to_node:
raise AssertionError(
u'Unable to find SqlNode for query path {} with context {}.'.format(
query_path, context))
node = con... | python | {
"resource": ""
} |
q228375 | try_get_column | train | def try_get_column(column_name, node, context):
"""Attempt to get a column by name from the selectable.
Args:
column_name: str, name of the column to retrieve.
node: SqlNode, the node the column is being retrieved for.
context: CompilationContext, compilation specific metadata.
Ret... | python | {
"resource": ""
} |
q228376 | get_column | train | def get_column(column_name, node, context):
"""Get a column by name from the selectable.
Args:
column_name: str, name of the column to retrieve.
node: SqlNode, the node the column is being retrieved for.
context: CompilationContext, compilation specific metadata.
Returns:
c... | python | {
"resource": ""
} |
q228377 | get_unique_directives | train | def get_unique_directives(ast):
"""Return a dict of directive name to directive object for the given AST node.
Any directives that are allowed to exist more than once on any AST node are ignored.
For any directives that can only exist up to once, we verify that they are not duplicated
raising GraphQLCo... | python | {
"resource": ""
} |
q228378 | get_local_filter_directives | train | def get_local_filter_directives(ast, current_schema_type, inner_vertex_fields):
"""Get all filter directives that apply to the current field.
This helper abstracts away the fact that some vertex field filtering operators apply on the
inner scope (the scope of the inner vertex field on which they are applie... | python | {
"resource": ""
} |
q228379 | validate_property_directives | train | def validate_property_directives(directives):
"""Validate the directives that appear at a property field."""
for directive_name in six.iterkeys(directives):
if directive_name in VERTEX_ONLY_DIRECTIVES:
raise GraphQLCompilationError(
u'Found vertex-only directive {} set on pro... | python | {
"resource": ""
} |
q228380 | validate_vertex_directives | train | def validate_vertex_directives(directives):
"""Validate the directives that appear at a vertex field."""
for directive_name in six.iterkeys(directives):
if directive_name in PROPERTY_ONLY_DIRECTIVES:
raise GraphQLCompilationError(
u'Found property-only directive {} set on ver... | python | {
"resource": ""
} |
q228381 | validate_root_vertex_directives | train | def validate_root_vertex_directives(root_ast):
"""Validate the directives that appear at the root vertex field."""
directives_present_at_root = set()
for directive_obj in root_ast.directives:
directive_name = directive_obj.name.value
if is_filter_with_outer_scope_vertex_field_operator(direc... | python | {
"resource": ""
} |
q228382 | validate_vertex_field_directive_interactions | train | def validate_vertex_field_directive_interactions(parent_location, vertex_field_name, directives):
"""Ensure that the specified vertex field directives are not mutually disallowed."""
fold_directive = directives.get('fold', None)
optional_directive = directives.get('optional', None)
output_source_directi... | python | {
"resource": ""
} |
q228383 | validate_vertex_field_directive_in_context | train | def validate_vertex_field_directive_in_context(parent_location, vertex_field_name,
directives, context):
"""Ensure that the specified vertex field directives are allowed in the current context."""
fold_directive = directives.get('fold', None)
optional_directive... | python | {
"resource": ""
} |
q228384 | _safe_match_string | train | def _safe_match_string(value):
"""Sanitize and represent a string argument in MATCH."""
if not isinstance(value, six.string_types):
if isinstance(value, bytes): # should only happen in py3
value = value.decode('utf-8')
else:
raise GraphQLInvalidArgumentError(u'Attempting... | python | {
"resource": ""
} |
q228385 | _safe_match_date_and_datetime | train | def _safe_match_date_and_datetime(graphql_type, expected_python_types, value):
"""Represent date and datetime objects as MATCH strings."""
# Python datetime.datetime is a subclass of datetime.date,
# but in this case, the two are not interchangeable.
# Rather than using isinstance, we will therefore che... | python | {
"resource": ""
} |
q228386 | _safe_match_list | train | def _safe_match_list(inner_type, argument_value):
"""Represent the list of "inner_type" objects in MATCH form."""
stripped_type = strip_non_null_from_type(inner_type)
if isinstance(stripped_type, GraphQLList):
raise GraphQLInvalidArgumentError(u'MATCH does not currently support nested lists, '
... | python | {
"resource": ""
} |
q228387 | insert_arguments_into_match_query | train | def insert_arguments_into_match_query(compilation_result, arguments):
"""Insert the arguments into the compiled MATCH query to form a complete query.
Args:
compilation_result: a CompilationResult object derived from the GraphQL compiler
arguments: dict, mapping argument name to its value, for e... | python | {
"resource": ""
} |
q228388 | SqlMetadata.get_table | train | def get_table(self, schema_type):
"""Retrieve a SQLAlchemy table based on the supplied GraphQL schema type name."""
table_name = schema_type.lower()
if not self.has_table(table_name):
raise exceptions.GraphQLCompilationError(
'No Table found in SQLAlchemy metadata for... | python | {
"resource": ""
} |
q228389 | _per_location_tuple_to_step | train | def _per_location_tuple_to_step(ir_tuple):
"""Construct a MatchStep from a tuple of its constituent blocks."""
root_block = ir_tuple[0]
if not isinstance(root_block, root_block_types):
raise AssertionError(u'Unexpected root block type for MatchStep: '
u'{} {}'.format(roo... | python | {
"resource": ""
} |
q228390 | _split_ir_into_match_steps | train | def _split_ir_into_match_steps(pruned_ir_blocks):
"""Split a list of IR blocks into per-location MATCH steps.
Args:
pruned_ir_blocks: list of IR basic block objects that have gone through a lowering step.
Returns:
list of MatchStep namedtuples, each of which contains all basic blocks that ... | python | {
"resource": ""
} |
q228391 | _split_match_steps_into_match_traversals | train | def _split_match_steps_into_match_traversals(match_steps):
"""Split a list of MatchSteps into multiple lists, each denoting a single MATCH traversal."""
output = []
current_list = None
for step in match_steps:
if isinstance(step.root_block, QueryRoot):
if current_list is not None:
... | python | {
"resource": ""
} |
q228392 | convert_to_match_query | train | def convert_to_match_query(ir_blocks):
"""Convert the list of IR blocks into a MatchQuery object, for easier manipulation."""
output_block = ir_blocks[-1]
if not isinstance(output_block, ConstructResult):
raise AssertionError(u'Expected last IR block to be ConstructResult, found: '
... | python | {
"resource": ""
} |
q228393 | insert_arguments_into_sql_query | train | def insert_arguments_into_sql_query(compilation_result, arguments):
"""Insert the arguments into the compiled SQL query to form a complete query.
Args:
compilation_result: CompilationResult, compilation result from the GraphQL compiler.
arguments: Dict[str, Any], parameter name -> value, for ev... | python | {
"resource": ""
} |
q228394 | convert_coerce_type_to_instanceof_filter | train | def convert_coerce_type_to_instanceof_filter(coerce_type_block):
"""Create an "INSTANCEOF" Filter block from a CoerceType block."""
coerce_type_target = get_only_element_from_collection(coerce_type_block.target_class)
# INSTANCEOF requires the target class to be passed in as a string,
# so we make the ... | python | {
"resource": ""
} |
q228395 | convert_coerce_type_and_add_to_where_block | train | def convert_coerce_type_and_add_to_where_block(coerce_type_block, where_block):
"""Create an "INSTANCEOF" Filter from a CoerceType, adding to an existing Filter if any."""
instanceof_filter = convert_coerce_type_to_instanceof_filter(coerce_type_block)
if where_block:
# There was already a Filter bl... | python | {
"resource": ""
} |
q228396 | expression_list_to_conjunction | train | def expression_list_to_conjunction(expression_list):
"""Convert a list of expressions to an Expression that is the conjunction of all of them."""
if not isinstance(expression_list, list):
raise AssertionError(u'Expected `list`, Received {}.'.format(expression_list))
if len(expression_list) == 0:
... | python | {
"resource": ""
} |
q228397 | construct_where_filter_predicate | train | def construct_where_filter_predicate(query_metadata_table, simple_optional_root_info):
"""Return an Expression that is True if and only if each simple optional filter is True.
Construct filters for each simple optional, that are True if and only if `edge_field` does
not exist in the `simple_optional_root_l... | python | {
"resource": ""
} |
q228398 | construct_optional_traversal_tree | train | def construct_optional_traversal_tree(complex_optional_roots, location_to_optional_roots):
"""Return a tree of complex optional root locations.
Args:
complex_optional_roots: list of @optional locations (location immmediately preceding
an @optional Traverse) that expand v... | python | {
"resource": ""
} |
q228399 | BetweenClause.validate | train | def validate(self):
"""Validate that the Between Expression is correctly representable."""
if not isinstance(self.field, LocalField):
raise TypeError(u'Expected LocalField field, got: {} {}'.format(
type(self.field).__name__, self.field))
if not isinstance(self.lower... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.