Repository: MystenLabs/sui
File: crates/sui-indexer-alt-graphql/src/api/types/available_range.rs (Rust)

Code before:
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use anyhow::anyhow;
use async_graphql::{
    Context, Object,
    registry::{MetaType, Registry},
};
use std::{collections::BTreeSet, sync::Arc};

use crate::{
    error::{RpcError, bad_user_input, feature_unavailable, upcast},
    scope::Scope,
    task::watermark::Watermarks,
};

use super::checkpoint::Checkpoint;

#[derive(thiserror::Error, Debug)]
pub enum Error {
    #[error("'{0}' is not an Object or Interface.")]
    NotAnObjectOrInterface(String),

    #[error("Type '{0}' not found in schema registry.")]
    TypeNotFound(String),

    #[error("Field '{1}' not found in type '{0}'.")]
    FieldNotFound(String, String),
}

/// Identifies a GraphQL query component that is used to determine the range of checkpoints for which data is available (for data that can be tied to a particular checkpoint).
///
/// Provides retention information for the type and optional field and filters. If field or filters are not provided we fall back to the available range for the type.
#[derive(Debug, Clone, Eq, PartialEq)]
pub(crate) struct AvailableRangeKey {
    /// The GraphQL type to check retention for
    pub(crate) type_: String,

    /// The specific field within the type to check retention for
    pub(crate) field: Option<String>,

    /// Optional filter to check retention for filtered queries
    pub(crate) filters: Option<Vec<String>>,
}

#[derive(Clone)]
pub(crate) struct AvailableRange {
    pub(crate) scope: Scope,
    pub(crate) first: u64,

Review comment (suggestion):
nit: phrase errors in terms of things the client understands (they know about the schema, they don't know about the schema registry).

```suggestion
    #[error("Type '{0}' not found in schema.")]
```

Code after:
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use anyhow::anyhow;
use async_graphql::{
    Context, Object,
    registry::{MetaType, Registry},
};
use std::{collections::BTreeSet, sync::Arc};

use crate::{
    error::{RpcError, bad_user_input, feature_unavailable, upcast},
    scope::Scope,
    task::watermark::Watermarks,
};

use super::checkpoint::Checkpoint;

#[derive(thiserror::Error, Debug)]
pub enum Error {
    #[error("'{0}' is not an Object or Interface.")]
    NotAnObjectOrInterface(String),

    #[error("Type '{0}' not found in schema.")]
    TypeNotFound(String),

    #[error("Field '{1}' not found in type '{0}'.")]
    FieldNotFound(String, String),
}

/// Identifies a GraphQL query component that is used to determine the range of checkpoints for which data is available (for data that can be tied to a particular checkpoint).
///
/// Provides retention information for the type and optional field and filters. If field or filters are not provided we fall back to the available range for the type.
#[derive(Debug, Clone, Eq, PartialEq)]
pub(crate) struct AvailableRangeKey {
    /// The GraphQL type to check retention for
    pub(crate) type_: String,

    /// The specific field within the type to check retention for
    pub(crate) field: Option<String>,

    /// Optional filter to check retention for filtered queries
    pub(crate) filters: Option<Vec<String>>,
}

#[derive(Clone)]
pub(crate) struct AvailableRange {
    pub(crate) scope: Scope,
    pub(crate) first: u64,