Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H-3371, H-3722: Overhaul return behavior for entity validation #5820

Merged
merged 11 commits into from
Dec 7, 2024
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 0 additions & 21 deletions apps/hash-api/src/graph/knowledge/primitive/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
GraphResolveDepths,
ModifyRelationshipOperation,
} from "@local/hash-graph-client";
import type { ValidateEntityParamsComponents } from "@local/hash-graph-client/api";
import type { CreateEntityParameters } from "@local/hash-graph-sdk/entity";
import { Entity, LinkEntity } from "@local/hash-graph-sdk/entity";
import type {
Expand All @@ -25,7 +24,6 @@ import type {
EntityProperties,
LinkData,
PropertyObject,
PropertyObjectWithMetadata,
PropertyPatchOperation,
} from "@local/hash-graph-types/entity";
import type { BaseUrl } from "@local/hash-graph-types/ontology";
Expand Down Expand Up @@ -595,25 +593,6 @@ export const updateEntity = async <Properties extends EntityProperties>(
return updatedEntity;
};

export const validateEntity: ImpureGraphFunction<
{
components: ValidateEntityParamsComponents;
entityTypes: VersionedUrl[];
properties: PropertyObjectWithMetadata;
},
Promise<void>
> = async (context, authentication, params) => {
const { components, entityTypes, properties } = params;

return await context.graphApi
.validateEntity(authentication.actorId, {
components,
entityTypes,
properties,
})
.then(({ data }) => data);
};

/**
* Get the incoming links of an entity.
*
Expand Down
12 changes: 6 additions & 6 deletions apps/hash-api/src/graphql/resolvers/knowledge/entity/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
Filter,
QueryTemporalAxesUnresolved,
} from "@local/hash-graph-client";
import type { Entity } from "@local/hash-graph-sdk/entity";
import { Entity } from "@local/hash-graph-sdk/entity";
import type {
AccountGroupId,
AccountId,
Expand Down Expand Up @@ -39,7 +39,6 @@ import {
removeEntityAdministrator,
removeEntityEditor,
updateEntity,
validateEntity,
} from "../../../../graph/knowledge/primitive/entity";
import {
createLinkEntity,
Expand Down Expand Up @@ -404,17 +403,18 @@ export const updateEntitiesResolver: ResolverFn<
};

export const validateEntityResolver: ResolverFn<
Promise<true>,
Promise<boolean>,
Record<string, never>,
LoggedInGraphQLContext,
QueryValidateEntityArgs
> = async (_, params, graphQLContext) => {
const { authentication } = graphQLContext;
const context = graphQLContextToImpureGraphContext(graphQLContext);

await validateEntity(context, authentication, params);

return true;
return (
(await Entity.validate(context.graphApi, authentication, params)) ===
undefined
);
};

export const archiveEntityResolver: ResolverFn<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ pub struct ClosedEntityTypeMetadata {
pub inverse: InverseEntityTypeMetadata,
}

impl ClosedEntityTypeMetadata {
#[must_use]
pub fn is_link(&self) -> bool {
self.all_of.iter().any(|entity_type| {
entity_type.id.base_url.as_str()
== "https://blockprotocol.org/@blockprotocol/types/entity-type/link/"
})
}
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[cfg_attr(target_arch = "wasm32", derive(tsify::Tsify))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
Expand Down Expand Up @@ -160,6 +170,10 @@ impl ClosedMultiEntityType {
}
}

pub fn is_link(&self) -> bool {
self.all_of.iter().any(ClosedEntityTypeMetadata::is_link)
}

/// Creates a closed entity type from multiple closed entity types.
///
/// This results in a closed entity type which is used for entities with multiple types.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub use self::{
closed::{
ClosedEntityType, ClosedEntityTypeMetadata, ClosedMultiEntityType, EntityTypeResolveData,
ResolveClosedEntityTypeError,
},
constraints::EntityConstraints,
reference::EntityTypeReference,
Expand Down Expand Up @@ -81,12 +82,6 @@ pub struct EntityTypeDisplayMetadata {
pub icon: Option<String>,
}

impl EntityTypeDisplayMetadata {
pub const fn is_empty(&self) -> bool {
self.label_property.is_none() && self.icon.is_none()
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(target_arch = "wasm32", derive(tsify::Tsify))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
Expand Down
1 change: 1 addition & 0 deletions libs/@blockprotocol/type-system/rust/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub use self::{
EntityType, EntityTypeReference, EntityTypeResolveData, EntityTypeSchemaMetadata,
EntityTypeToEntityTypeEdge, EntityTypeToPropertyTypeEdge, EntityTypeValidationError,
EntityTypeValidator, InverseEntityTypeMetadata, PartialEntityType,
ResolveClosedEntityTypeError,
},
identifier::{DataTypeUuid, EntityTypeUuid, OntologyTypeUuid, PropertyTypeUuid},
object::{
Expand Down
1 change: 1 addition & 0 deletions libs/@local/graph/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ harpc-types = { workspace = true }
hash-graph-store = { workspace = true, features = ["utoipa"] }
hash-graph-temporal-versioning = { workspace = true }
hash-graph-type-defs = { workspace = true }
hash-graph-validation = { workspace = true }
hash-status = { workspace = true }
type-system = { workspace = true, features = ["utoipa"] }

Expand Down
9 changes: 9 additions & 0 deletions libs/@local/graph/api/openapi/models/multi_report.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions libs/@local/graph/api/openapi/models/report.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions libs/@local/graph/api/openapi/models/report_context_info.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading