<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build( cls, schema: GraphQLSchema, document: DocumentNode, root_value: Any = None, context_value: Any = None, raw_variable_values: Dict[str, Any] = None, operation_name: str = None, field_resolver: GraphQLFieldResolver = None, type_resolver: GraphQLTypeResolver = None, middleware: Middleware = None, ) -> Union[List[GraphQLError], "ExecutionContext"]: """Build an execution context Constructs a ExecutionContext object from the arguments passed to execute, which we will pass throughout the other execution methods. Throws a GraphQLError if a valid execution context cannot be created. """

        errors: List[GraphQLError] = []
        operation: Optional[OperationDefinitionNode] = None
        has_multiple_assumed_operations = False
        fragments: Dict[str, FragmentDefinitionNode] = {}
        middleware_manager: Optional[MiddlewareManager] = None
        if middleware is not None:
            if isinstance(middleware, (list, tuple)):
                middleware_manager = MiddlewareManager(*middleware)
            elif isinstance(middleware, MiddlewareManager):
                middleware_manager = middleware
            else:
                raise TypeError(
                    "Middleware must be passed as a list or tuple of functions"
                    " or objects, or as a single MiddlewareManager object."
                    f" Got {inspect(middleware)} instead."
                )

        for definition in document.definitions:
            if isinstance(definition, OperationDefinitionNode):
                if not operation_name and operation:
                    has_multiple_assumed_operations = True
                elif not operation_name or (
                    definition.name and definition.name.value == operation_name
                ):
                    operation = definition
            elif isinstance(definition, FragmentDefinitionNode):
                fragments[definition.name.value] = definition

        if not operation:
            if operation_name:
                errors.append(
                    GraphQLError(f"Unknown operation named '{operation_name}'.")
                )
            else:
                errors.append(GraphQLError("Must provide an operation."))
        elif has_multiple_assumed_operations:
            errors.append(
                GraphQLError(
                    "Must provide operation name"
                    " if query contains multiple operations."
                )
            )

        variable_values = None
        if operation:
            coerced_variable_values = get_variable_values(
                schema, operation.variable_definitions or [], raw_variable_values or {}
            )

            if coerced_variable_values.errors:
                errors.extend(coerced_variable_values.errors)
            else:
                variable_values = coerced_variable_values.coerced

        if errors:
            return errors

        if operation is None:
            raise TypeError("Has operation if no errors.")
        if variable_values is None:
            raise TypeError("Has variables if no errors.")

        return cls(
            schema,
            fragments,
            root_value,
            context_value,
            operation,
            variable_values,
            field_resolver or default_field_resolver,
            type_resolver or default_type_resolver,
            middleware_manager,
            errors,
        )