def WriteGraphSeries(graph_series,
                     label,
                     token = None):
  """Writes graph series for a particular client label to the DB.

  Args:
    graph_series: A series of rdf_stats.Graphs containing aggregated data for a
      particular report-type.
    label: Client label by which data in the graph_series was aggregated.
    token: ACL token to use for writing to the legacy (non-relational)
      datastore.

  Raises:
    AFF4AttributeTypeError: If, when writing to the legacy DB, an unexpected
    report-data type is encountered.
  """
  if data_store.RelationalDBEnabled():
    data_store.REL_DB.WriteClientGraphSeries(graph_series, label)

  if _ShouldUseLegacyDatastore():
    # We need to use the __call__() method of the aff4.Attribute class
    # to instantiate Graph and GraphSeries objects, or AFF4Object.AddAttribute()
    # won't work.
    aff4_attr = _GetAFF4AttributeForReportType(graph_series.report_type)()

    if isinstance(aff4_attr, rdf_stats.GraphSeries):
      for graph in graph_series.graphs:
        aff4_attr.Append(graph)
    elif isinstance(aff4_attr, rdf_stats.Graph):
      for sample in graph_series.graphs[0]:
        aff4_attr.Append(x_value=sample.x_value, y_value=sample.y_value)
    else:
      raise AFF4AttributeTypeError(aff4_attr.__class__)

    with aff4.FACTORY.Create(
        GetAFF4ClientReportsURN().Add(label),
        aff4_type=aff4_stats.ClientFleetStats,
        mode="w",
        token=token) as stats_for_label:
      stats_for_label.AddAttribute(aff4_attr)
Writes graph series for a particular client label to the DB.

  Args:
    graph_series: A series of rdf_stats.Graphs containing aggregated data for a
      particular report-type.
    label: Client label by which data in the graph_series was aggregated.
    token: ACL token to use for writing to the legacy (non-relational)
      datastore.

  Raises:
    AFF4AttributeTypeError: If, when writing to the legacy DB, an unexpected
    report-data type is encountered.