def can_convert_a_path_to_a_list_of_its_keys(): root = Path(None, 0, "Root") assert root.as_list() == [0] first = root.add_key("one", "First") assert first.as_list() == [0, "one"] second = first.add_key(2, "Second") assert second.as_list() == [0, "one", 2]
def add_path(): path = Path(None, 0, None) assert path.prev is None assert path.key == 0 prev, path = path, Path(path, 1, None) assert path.prev is prev assert path.key == 1 prev, path = path, Path(path, "two", None) assert path.prev is prev assert path.key == "two"
def create_resolve_info(schema, request_string, variables=None, return_type=None): exe_context = create_execution_context(schema, request_string, variables) parent_type = get_operation_root_type(schema, exe_context.operation) field_asts = get_field_asts_from_execution_context(exe_context) field_ast = field_asts[0] field_name = field_ast.name.value if return_type is None: field_def = get_field_def(schema, parent_type, field_name) if not field_def: return Undefined return_type = field_def.type # The resolve function's optional third argument is a context value that # is provided to every resolve function within an execution. It is commonly # used to represent an authenticated user, or request-specific caches. return GraphQLResolveInfo( field_name, field_asts, return_type, parent_type, Path(None, 0, None), schema, exe_context.fragments, exe_context.root_value, exe_context.operation, exe_context.variable_values, exe_context.context_value, exe_context.is_awaitable, )
def as_list(): path = Path(None, 1, None) assert path.as_list() == [1] path = path.add_key("two") assert path.as_list() == [1, "two"] path = path.add_key(3) assert path.as_list() == [1, "two", 3]
def _create_resolve_info(self, field_name, field_asts, return_type, parent_type): return GraphQLResolveInfo( field_name, field_asts, return_type, parent_type, Path(None, 0, None), schema=self.root_info.schema, fragments=self.root_info.fragments, root_value=self.root_info.root_value, operation=self.root_info.operation, variable_values=self.root_info.variable_values, context=self.root_info.context, is_awaitable=self.root_info.is_awaitable, )
def _new_node(self, path: Path): node = Trace.Node() path_list = path.as_list() id = path_list[-1] if isinstance(id, int): node.index = id else: node.response_name = cast(str, id) self.nodes[response_path_as_string(path_list)] = node parent_node = self._ensure_parent_node(path) n = parent_node.child.add() n.MergeFrom(node) self.nodes[response_path_as_string(path_list)] = n return n
def can_create_a_path(): first = Path(None, 1, "First") assert first.prev is None assert first.key == 1 assert first.typename == "First"
def can_add_a_new_key_to_an_existing_path(): first = Path(None, 1, "First") second = first.add_key("two", "Second") assert second.prev is first assert second.key == "two" assert second.typename == "Second"
def add_key(): prev = Path(None, 0, None) path = prev.add_key("one") assert path.prev is prev assert path.key == "one"