Skip to content

Commit

Permalink
GQL, DatasetMetadata: update dataset's dependencies types
Browse files Browse the repository at this point in the history
  • Loading branch information
s373r committed Dec 26, 2024
1 parent ac122df commit 5308147
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
6 changes: 3 additions & 3 deletions resources/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -853,13 +853,13 @@ interface DependencyDatasetResult {
message: String!
}

type DependencyDatasetResultFound implements DependencyDatasetResult {
type DependencyDatasetResultAccessible implements DependencyDatasetResult {
dataset: Dataset!
message: String!
}

type DependencyDatasetResultNotFound implements DependencyDatasetResult {
datasetId: DatasetID!
type DependencyDatasetResultNotAccessible implements DependencyDatasetResult {
id: DatasetID!
message: String!
}

Expand Down
44 changes: 24 additions & 20 deletions src/adapter/graphql/src/queries/datasets/dataset_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ impl DatasetMetadata {
.await?;

upstream_dependencies.extend(unauthorized_ids_with_errors.into_iter().map(
|(not_found_dataset_id, _)| DependencyDatasetResult::not_found(not_found_dataset_id),
|(unauthorized_dataset_id, _)| {
DependencyDatasetResult::not_accessible(unauthorized_dataset_id)
},
));

let DatasetEntriesResolution {
Expand All @@ -137,7 +139,7 @@ impl DatasetMetadata {
upstream_dependencies.extend(
unresolved_entries
.into_iter()
.map(DependencyDatasetResult::not_found),
.map(DependencyDatasetResult::not_accessible),
);

let owner_ids = resolved_entries
Expand All @@ -164,13 +166,14 @@ impl DatasetMetadata {
};
let dataset = Dataset::new(Account::from_account(account.clone()), dataset_handle);

upstream_dependencies.push(DependencyDatasetResult::found(dataset));
upstream_dependencies.push(DependencyDatasetResult::accessible(dataset));
} else {
tracing::warn!(
"Upstream owner's account not found for dataset: {:?}",
&dataset_entry
);
upstream_dependencies.push(DependencyDatasetResult::not_found(dataset_entry.id));
upstream_dependencies
.push(DependencyDatasetResult::not_accessible(dataset_entry.id));
}
}

Expand Down Expand Up @@ -226,7 +229,7 @@ impl DatasetMetadata {
downstream_dependencies.extend(
unresolved_entries
.into_iter()
.map(DependencyDatasetResult::not_found),
.map(DependencyDatasetResult::not_accessible),
);

let owner_ids = resolved_entries
Expand All @@ -253,13 +256,14 @@ impl DatasetMetadata {
};
let dataset = Dataset::new(Account::from_account(account.clone()), dataset_handle);

downstream_dependencies.push(DependencyDatasetResult::found(dataset));
downstream_dependencies.push(DependencyDatasetResult::accessible(dataset));
} else {
tracing::warn!(
"Downstream owner's account not found for dataset: {:?}",
&dataset_entry
);
downstream_dependencies.push(DependencyDatasetResult::not_found(dataset_entry.id));
downstream_dependencies
.push(DependencyDatasetResult::not_accessible(dataset_entry.id));
}
}

Expand Down Expand Up @@ -400,45 +404,45 @@ impl DatasetMetadata {
#[derive(Interface, Debug, Clone)]
#[graphql(field(name = "message", ty = "String"))]
enum DependencyDatasetResult {
Found(DependencyDatasetResultFound),
NotFound(DependencyDatasetResultNotFound),
Accessible(DependencyDatasetResultAccessible),
NotAccessible(DependencyDatasetResultNotAccessible),
}

impl DependencyDatasetResult {
pub fn found(dataset: Dataset) -> Self {
Self::Found(DependencyDatasetResultFound { dataset })
pub fn accessible(dataset: Dataset) -> Self {
Self::Accessible(DependencyDatasetResultAccessible { dataset })
}

pub fn not_found(dataset_id: odf::DatasetID) -> Self {
Self::NotFound(DependencyDatasetResultNotFound {
dataset_id: dataset_id.into(),
pub fn not_accessible(dataset_id: odf::DatasetID) -> Self {
Self::NotAccessible(DependencyDatasetResultNotAccessible {
id: dataset_id.into(),
})
}
}

#[derive(SimpleObject, Debug, Clone)]
#[graphql(complex)]
pub struct DependencyDatasetResultFound {
pub struct DependencyDatasetResultAccessible {
pub dataset: Dataset,
}

#[ComplexObject]
impl DependencyDatasetResultFound {
impl DependencyDatasetResultAccessible {
async fn message(&self) -> String {
"Found".to_string()
}
}

#[derive(SimpleObject, Debug, Clone)]
#[graphql(complex)]
pub struct DependencyDatasetResultNotFound {
pub dataset_id: DatasetID,
pub struct DependencyDatasetResultNotAccessible {
pub id: DatasetID,
}

#[ComplexObject]
impl DependencyDatasetResultNotFound {
impl DependencyDatasetResultNotAccessible {
async fn message(&self) -> String {
"Not found".to_string()
"Not Accessible".to_string()
}
}

Expand Down

0 comments on commit 5308147

Please sign in to comment.