    def apply(self, {{ data_class.variable }}: {{ data_class.write_name }} | Sequence[{{ data_class.write_name }}], replace: bool = False) -> dm.InstancesApplyResult:
        """Add or update (upsert) {{data_class.doc_list_name}}.{% if data_class.has_one_to_many_edges %}

        Note: This method iterates through all nodes linked to {{ data_class.variable }} and create them including the edges
        between the nodes. For example, if any of {{ data_class.one_to_many_edges_docs }} are set, then these
        nodes as well as any nodes linked to them, and all the edges linking these nodes will be created.{% endif %}

        Args:
            {{ data_class.variable }}: {{ data_class.doc_name.capitalize() }} or sequence of {{ data_class.doc_list_name }} to upsert.
            replace (bool): How do we behave when a property value exists? Do we replace all matching and existing values with the supplied values (true)?
                Or should we merge in new values for properties together with the existing values (false)? Note: This setting applies for all nodes or edges specified in the ingestion call.
        Returns:
            Created instance(s), i.e., nodes and edges.

        Examples:

            Create a new {{ data_class.variable }}:

                >>> from {{ top_level_package }} import {{ client_name }}
                >>> from {{ top_level_package }}.data_classes import {{ data_class.write_name }}
                >>> client = {{ client_name }}()
                >>> {{ data_class.variable }} = {{ data_class.write_name }}(external_id="my_{{ data_class.variable }}", ...)
                >>> result = client.{{ api_class.client_attribute }}.apply({{ data_class.variable }})

        """
        if isinstance({{ data_class.variable }}, {{ data_class.write_name }}):
            instances = {{ data_class.variable }}.to_instances_apply(self._view_by_write_class)
        else:
            instances = {{ data_class.write_list_name }}({{ data_class.variable }}).to_instances_apply(self._view_by_write_class)
        return self._client.data_modeling.instances.apply(
            nodes=instances.nodes,
            edges=instances.edges,
            auto_create_start_nodes=True,
            auto_create_end_nodes=True,
            replace=replace,
        )
