Skip to content

Commit

Permalink
H-3537: Add interface to read resolved entity type schemas (#5594)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann authored Nov 7, 2024
1 parent ec5df4d commit d95917a
Show file tree
Hide file tree
Showing 39 changed files with 801 additions and 249 deletions.
31 changes: 23 additions & 8 deletions apps/hash-api/src/graph/ontology/primitive/entity-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
EntityType,
EntityTypePermission,
GetClosedMultiEntityTypeParams,
GetClosedMultiEntityTypeResponse as GetClosedMultiEntityTypeResponseGraphApi,
GetEntityTypesParams,
GetEntityTypeSubgraphParams,
ModifyRelationshipOperation,
Expand All @@ -22,6 +23,7 @@ import type {
import type {
ClosedEntityTypeWithMetadata,
EntityTypeMetadata,
EntityTypeResolveDefinitions,
EntityTypeWithMetadata,
OntologyTypeRecordId,
} from "@local/hash-graph-types/ontology";
Expand All @@ -31,6 +33,7 @@ import { generateTypeId } from "@local/hash-isomorphic-utils/ontology-types";
import {
mapGraphApiClosedEntityTypesToClosedEntityTypes,
mapGraphApiClosedMultiEntityTypeToClosedMultiEntityType,
mapGraphApiEntityTypeResolveDefinitionsToEntityTypeResolveDefinitions,
mapGraphApiEntityTypesToEntityTypes,
mapGraphApiSubgraphToSubgraph,
} from "@local/hash-isomorphic-utils/subgraph-mapping";
Expand Down Expand Up @@ -207,7 +210,7 @@ export const getEntityTypeSubgraph: ImpureGraphFunction<
};

export const getEntityTypes: ImpureGraphFunction<
Omit<GetEntityTypesParams, "includeDrafts" | "includeClosed"> & {
Omit<GetEntityTypesParams, "includeDrafts" | "includeEntityTypes"> & {
temporalClient?: TemporalClient;
},
Promise<EntityTypeWithMetadata[]>
Expand All @@ -217,7 +220,6 @@ export const getEntityTypes: ImpureGraphFunction<
return await graphApi
.getEntityTypes(actorId, {
includeDrafts: false,
includeClosed: false,
...request,
})
.then(({ data: response }) =>
Expand All @@ -226,7 +228,7 @@ export const getEntityTypes: ImpureGraphFunction<
};

export const getClosedEntityTypes: ImpureGraphFunction<
Omit<GetEntityTypesParams, "includeDrafts" | "includeClosed"> & {
Omit<GetEntityTypesParams, "includeDrafts" | "includeEntityTypes"> & {
temporalClient?: TemporalClient;
},
Promise<ClosedEntityTypeWithMetadata[]>
Expand All @@ -235,7 +237,7 @@ export const getClosedEntityTypes: ImpureGraphFunction<

const { data: response } = await graphApi.getEntityTypes(actorId, {
includeDrafts: false,
includeClosed: true,
includeEntityTypes: "closed",
...request,
});
const entityTypes = mapGraphApiEntityTypesToEntityTypes(response.entityTypes);
Expand All @@ -248,19 +250,32 @@ export const getClosedEntityTypes: ImpureGraphFunction<
}));
};

export type GetClosedMultiEntityTypeResponse = Omit<
GetClosedMultiEntityTypeResponseGraphApi,
"entityType" | "definitions"
> & {
entityType: ClosedMultiEntityType;
definitions?: EntityTypeResolveDefinitions;
};

export const getClosedMultiEntityType: ImpureGraphFunction<
GetClosedMultiEntityTypeParams & {
temporalClient?: TemporalClient;
},
Promise<ClosedMultiEntityType>
Promise<GetClosedMultiEntityTypeResponse>
> = async ({ graphApi }, { actorId }, { temporalClient: _, ...request }) =>
graphApi
.getClosedMultiEntityType(actorId, request)
.then(({ data: response }) =>
mapGraphApiClosedMultiEntityTypeToClosedMultiEntityType(
.then(({ data: response }) => ({
entityType: mapGraphApiClosedMultiEntityTypeToClosedMultiEntityType(
response.entityType,
),
);
definitions: response.definitions
? mapGraphApiEntityTypeResolveDefinitionsToEntityTypeResolveDefinitions(
response.definitions,
)
: undefined,
}));

/**
* Get an entity type by its versioned URL.
Expand Down
32 changes: 32 additions & 0 deletions apps/hash-graph/libs/api/openapi/models/closed_data_type.json

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

21 changes: 21 additions & 0 deletions apps/hash-graph/libs/api/openapi/models/partial_entity_type.json

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

Loading

0 comments on commit d95917a

Please sign in to comment.