Skip to content

Commit 0cda242

Browse files
Eliminated GQL modeling drift around ResourceView: accounts should be under headers, not at the top
1 parent ffce998 commit 0cda242

13 files changed

Lines changed: 93 additions & 59 deletions

File tree

resources/schema.gql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3857,6 +3857,11 @@ type Resource {
38573857
status: JSON
38583858
}
38593859

3860+
type ResourceAccount {
3861+
id: AccountID!
3862+
name: AccountName
3863+
}
3864+
38603865
input ResourceAccountSelectorInput {
38613866
byId: AccountID
38623867
byName: AccountName
@@ -4000,8 +4005,7 @@ enum ResourceHeaderValidationProblemCode {
40004005

40014006
type ResourceHeaders {
40024007
id: ResourceID!
4003-
accountId: AccountID!
4004-
accountName: AccountName
4008+
account: ResourceAccount!
40054009
name: String!
40064010
description: String
40074011
labels: JSON!

src/adapter/graphql/src/queries/resources/models.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,7 @@ impl From<BatchGetResourceProblem> for BatchResourceProblem {
617617
#[derive(SimpleObject, Debug, Clone)]
618618
pub struct ResourceHeaders {
619619
pub id: ResourceID,
620-
pub account_id: AccountID<'static>,
621-
pub account_name: Option<AccountName<'static>>,
620+
pub account: ResourceAccount,
622621
pub name: String,
623622
pub description: Option<String>,
624623
pub labels: serde_json::Value,
@@ -630,15 +629,23 @@ pub struct ResourceHeaders {
630629
pub last_reconciled_at: Option<DateTime<Utc>>,
631630
}
632631

632+
#[derive(SimpleObject, Debug, Clone)]
633+
pub struct ResourceAccount {
634+
pub id: AccountID<'static>,
635+
pub name: Option<AccountName<'static>>,
636+
}
637+
633638
impl From<kamu_resources::ResourceView> for ResourceHeaders {
634639
fn from(value: kamu_resources::ResourceView) -> Self {
635640
let labels = serde_json::to_value(value.headers.labels).unwrap();
636641
let annotations = serde_json::to_value(value.headers.annotations).unwrap();
637642

638643
Self {
639644
id: value.headers.id.into(),
640-
account_id: value.account.id.into(),
641-
account_name: value.account.name.map(Into::into),
645+
account: ResourceAccount {
646+
id: value.headers.account.id.into(),
647+
name: value.headers.account.name.map(Into::into),
648+
},
642649
name: value.headers.name.clone(),
643650
description: value.headers.description,
644651
labels,

src/app/cli/src/commands/apply_command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ impl ApplyPrinter<'_> {
675675
fn new(resource: &'a ResourceView) -> Self {
676676
Self {
677677
id: &resource.headers.id,
678-
account: &resource.account,
678+
account: &resource.headers.account,
679679
name: &resource.headers.name,
680680
description: &resource.headers.description,
681681
labels: &resource.headers.labels,

src/app/cli/src/commands/get_resource_command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl GetResourceCommand {
130130
fn new(resource: &'a kamu_resources::ResourceView) -> Self {
131131
Self {
132132
id: &resource.headers.id,
133-
account: &resource.account,
133+
account: &resource.headers.account,
134134
name: &resource.headers.name,
135135
description: &resource.headers.description,
136136
labels: &resource.headers.labels,

src/domain/resources/domain/src/views/resource_view.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub struct ResourceIdentityView {
2929
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3030
pub struct ResourceView {
3131
pub schema: String,
32-
pub account: ResourceViewAccount,
3332
pub headers: ResourceViewHeaders,
3433
pub last_reconciled_at: Option<DateTime<Utc>>,
3534
pub spec: serde_json::Value,
@@ -49,6 +48,7 @@ pub struct ResourceViewAccount {
4948
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5049
pub struct ResourceViewHeaders {
5150
pub id: ResourceID,
51+
pub account: ResourceViewAccount,
5252
pub name: ResourceName,
5353
pub description: Option<String>,
5454
pub labels: BTreeMap<String, String>,
@@ -62,9 +62,15 @@ pub struct ResourceViewHeaders {
6262
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
6363

6464
impl ResourceViewHeaders {
65-
pub fn simple(now: DateTime<Utc>, id: ResourceID, name: impl Into<ResourceName>) -> Self {
65+
pub fn simple(
66+
now: DateTime<Utc>,
67+
id: ResourceID,
68+
account: ResourceViewAccount,
69+
name: impl Into<ResourceName>,
70+
) -> Self {
6671
Self {
6772
id,
73+
account,
6874
name: name.into(),
6975
description: None,
7076
labels: BTreeMap::new(),
@@ -77,8 +83,14 @@ impl ResourceViewHeaders {
7783
}
7884

7985
pub fn from_owned(id: ResourceID, headers: ResourceHeaders) -> Self {
86+
let account = ResourceViewAccount {
87+
id: headers.account.clone(),
88+
name: None,
89+
};
90+
8091
Self {
8192
id,
93+
account,
8294
name: headers.name,
8395
description: headers.description,
8496
labels: headers.labels,
@@ -89,6 +101,11 @@ impl ResourceViewHeaders {
89101
deleted_at: headers.deleted_at,
90102
}
91103
}
104+
105+
pub fn with_account(mut self, account: ResourceViewAccount) -> Self {
106+
self.account = account;
107+
self
108+
}
92109
}
93110

94111
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

src/domain/resources/facade-tests/tests/contract/account_scoping.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ pub async fn test_default_account_selector_resolves_current_account(
171171
.await
172172
.unwrap();
173173

174-
assert_eq!(view.account.id, h.account_id(TestAccount::Alice));
175-
assert_eq!(view.account.name, Some(h.account_name(TestAccount::Alice)));
174+
assert_eq!(view.headers.account.id, h.account_id(TestAccount::Alice));
175+
assert_eq!(
176+
view.headers.account.name,
177+
Some(h.account_name(TestAccount::Alice))
178+
);
176179
}
177180

178181
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -205,7 +208,7 @@ pub async fn test_account_by_name_resolves_correctly(h: &impl FacadeContractHarn
205208
.await
206209
.unwrap();
207210

208-
assert_eq!(view.account.id, h.account_id(TestAccount::Alice));
211+
assert_eq!(view.headers.account.id, h.account_id(TestAccount::Alice));
209212
}
210213

211214
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -237,7 +240,7 @@ pub async fn test_account_by_id_resolves_correctly(h: &impl FacadeContractHarnes
237240
.await
238241
.unwrap();
239242

240-
assert_eq!(view.account.id, h.account_id(TestAccount::Alice));
243+
assert_eq!(view.headers.account.id, h.account_id(TestAccount::Alice));
241244
}
242245

243246
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

src/domain/resources/facade/src/facade/graphql/cynic_api/conversions.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ impl TryFrom<fragments::Resource> for domain::ResourceView {
5050

5151
Ok(Self {
5252
schema: value.schema,
53-
account: domain::ResourceViewAccount {
54-
id: value.headers.account_id,
55-
name: value
56-
.headers
57-
.account_name
58-
.map(|name| odf::AccountName::new_unchecked(&name.0)),
59-
},
6053
headers: domain::ResourceViewHeaders {
6154
id: value.headers.id,
55+
account: domain::ResourceViewAccount {
56+
id: value.headers.account.id,
57+
name: value
58+
.headers
59+
.account
60+
.name
61+
.map(|name| odf::AccountName::new_unchecked(&name.0)),
62+
},
6263
name: value.headers.name,
6364
description: value.headers.description,
6465
labels,

src/domain/resources/facade/src/facade/graphql/cynic_api/fragments.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ pub(crate) struct Resource {
216216
#[derive(cynic::QueryFragment, Debug, Clone)]
217217
pub(crate) struct ResourceHeaders {
218218
pub id: kamu_resources::ResourceID,
219-
pub account_id: odf::AccountID,
220-
pub account_name: Option<AccountName>,
219+
pub account: ResourceAccount,
221220
pub name: String,
222221
pub description: Option<String>,
223222
pub labels: serde_json::Value,
@@ -231,6 +230,14 @@ pub(crate) struct ResourceHeaders {
231230

232231
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
233232

233+
#[derive(cynic::QueryFragment, Debug, Clone)]
234+
pub(crate) struct ResourceAccount {
235+
pub id: odf::AccountID,
236+
pub name: Option<AccountName>,
237+
}
238+
239+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
240+
234241
#[derive(cynic::QueryFragment, Debug, Clone)]
235242
pub(crate) struct ResourceIdentity {
236243
pub id: kamu_resources::ResourceID,

src/domain/resources/facade/src/facade/local/helpers/manifest_support.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ pub(crate) fn resource_view_to_manifest(
8787
) -> Result<ResourceManifest, InternalError> {
8888
let ResourceView {
8989
schema,
90-
account,
9190
headers,
9291
spec,
9392
..
@@ -103,8 +102,8 @@ pub(crate) fn resource_view_to_manifest(
103102
headers: kamu_resources::ResourceManifestHeaders {
104103
id: None,
105104
account: Some(kamu_resources::ResourceAccountRef {
106-
id: Some(account.id),
107-
name: account.name.map(|name| name.to_string()),
105+
id: Some(headers.account.id),
106+
name: headers.account.name.map(|name| name.to_string()),
108107
}),
109108
name: headers.name,
110109
description: headers.description,

src/domain/resources/facade/src/facade/local/local_resource_facade_impl.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl ResourceFacade for LocalResourceFacadeImpl {
394394
Ok(match plan {
395395
ApplyManifestPlanningDecision::Planned(mut plan) => {
396396
plan.warnings.splice(0..0, prepared.header_warnings);
397-
plan.resource.account = ResourceViewAccount {
397+
plan.resource.headers.account = ResourceViewAccount {
398398
id: prepared.target_account.id,
399399
name: Some(prepared.target_account.name),
400400
};
@@ -425,7 +425,7 @@ impl ResourceFacade for LocalResourceFacadeImpl {
425425
Ok(match result {
426426
ApplyManifestApplicationDecision::Applied(mut result) => {
427427
result.warnings.splice(0..0, prepared.header_warnings);
428-
result.resource.account = ResourceViewAccount {
428+
result.resource.headers.account = ResourceViewAccount {
429429
id: prepared.target_account.id,
430430
name: Some(prepared.target_account.name),
431431
};
@@ -641,10 +641,10 @@ impl LocalResourceFacadeImpl {
641641
.await?;
642642

643643
Ok(ResourceView {
644-
account: ResourceViewAccount {
644+
headers: view.headers.with_account(ResourceViewAccount {
645645
id: target_account.id,
646646
name: Some(target_account.name),
647-
},
647+
}),
648648
..view
649649
})
650650
}
@@ -720,11 +720,11 @@ impl LocalResourceFacadeImpl {
720720

721721
let resource = ResourceView {
722722
schema: snapshot.schema,
723-
account: ResourceViewAccount {
724-
id: target_account.id.clone(),
725-
name: Some(target_account.name.clone()),
726-
},
727-
headers: ResourceViewHeaders::from_owned(id, snapshot.headers),
723+
headers: ResourceViewHeaders::from_owned(id, snapshot.headers)
724+
.with_account(ResourceViewAccount {
725+
id: target_account.id.clone(),
726+
name: Some(target_account.name.clone()),
727+
}),
728728
last_reconciled_at: snapshot.last_reconciled_at,
729729
spec: snapshot.spec,
730730
status: snapshot.status,

0 commit comments

Comments
 (0)