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

Update Entity Type endpoints to return Subgraph #1220

Merged
merged 32 commits into from
Oct 20, 2022
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b77b05f
Return `Subgraph` for `get_entity_type`
Alfred-Mountfield Oct 19, 2022
1c5a4be
Regenerate `api.ts`
Alfred-Mountfield Oct 19, 2022
6f1095c
Update GraphQL typedefs and resolvers
Alfred-Mountfield Oct 19, 2022
6955416
Update all `Subgraph` related GraphQL endpoints to take depth params
Alfred-Mountfield Oct 19, 2022
3990a47
Fix resolvers
Alfred-Mountfield Oct 19, 2022
abdef74
Fix BP hooks
Alfred-Mountfield Oct 19, 2022
c5225ed
Fix `entity-type.model.ts`
Alfred-Mountfield Oct 19, 2022
13dba4c
Add `subgraph` helper functions
Alfred-Mountfield Oct 19, 2022
4eb4107
Fix `generateEntityLabel`
Alfred-Mountfield Oct 19, 2022
490dab1
Fix `property-table.tsx`
Alfred-Mountfield Oct 19, 2022
1529415
Fix `types-section.tsx`
Alfred-Mountfield Oct 19, 2022
351520b
Fix `use-entity-type.tsx`
Alfred-Mountfield Oct 19, 2022
ddd6c77
Fix `entity-editor-page.tsx`
Alfred-Mountfield Oct 19, 2022
6c91714
Driveby: fix dumb mistake
Alfred-Mountfield Oct 19, 2022
fb8ad44
Remove unused function
Alfred-Mountfield Oct 19, 2022
b6020bd
Unused import
Alfred-Mountfield Oct 19, 2022
6dc0054
Add getter methods for `Subgraph`
Alfred-Mountfield Oct 20, 2022
871caba
Use getter methods for `Subgraph`
Alfred-Mountfield Oct 20, 2022
3938e47
Merge branch 'main' into am/subgraph-entity-type
Alfred-Mountfield Oct 20, 2022
9ffa4cd
Migrate changes after merge
Alfred-Mountfield Oct 20, 2022
349dbdf
Unused import
Alfred-Mountfield Oct 20, 2022
9525c6c
Improve ontology types GraphQL query docs
Alfred-Mountfield Oct 20, 2022
7163273
Change query depths on aggregate methods
Oct 20, 2022
b1b81ef
Change remaining depths for BP hooks
Oct 20, 2022
5dd3e18
Improve docs
Oct 20, 2022
a7b47cc
Use destructuring
Alfred-Mountfield Oct 20, 2022
d80fc1e
Temporarily remove usages of `mustBeVersionedUri`
Alfred-Mountfield Oct 20, 2022
b27688d
Merge branch 'main' into am/subgraph-entity-type
Oct 20, 2022
4020340
Temporarily remove one more usage of `mustBeVersionedUri`
Alfred-Mountfield Oct 20, 2022
20e9512
Cleanup
Alfred-Mountfield Oct 20, 2022
ae95899
Add type system loading check
Alfred-Mountfield Oct 20, 2022
d52565a
Cleanup
Alfred-Mountfield Oct 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityType, extractBaseUri } from "@blockprotocol/type-system-web";
import { EntityType } from "@blockprotocol/type-system-web";
import {
useCallback,
useEffect,
Expand All @@ -9,7 +9,7 @@ import {
import { useBlockProtocolAggregateEntityTypes } from "../../../../components/hooks/blockProtocolFunctions/ontology/useBlockProtocolAggregateEntityTypes";
import { useBlockProtocolUpdateEntityType } from "../../../../components/hooks/blockProtocolFunctions/ontology/useBlockProtocolUpdateEntityType";
import { useAdvancedInitTypeSystem } from "../../../../lib/use-init-type-system";
import { mustBeVersionedUri } from "./util";
import { getEntityTypesByBaseUri } from "../../../../lib/subgraph";

export const useEntityType = (
entityTypeBaseUri: string,
Expand All @@ -35,19 +35,23 @@ export const useEntityType = (
entityTypeRef.current = null;

void aggregateEntityTypes({ data: {} }).then(async (res) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @nathggns, just want to check you're happy with these specific changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm happy with this, thanks @Alfred-Mountfield

const relevantEntity =
res.data?.results.find((item) => {
const baseUri = extractBaseUri(mustBeVersionedUri(item.entityTypeId));
return baseUri === entityTypeBaseUri;
})?.entityType ?? null;
const subgraph = res.data;
const relevantEntityTypes = subgraph
? getEntityTypesByBaseUri(subgraph, entityTypeBaseUri)
: [];

/** @todo - pick the latest version? */
const relevantEntityType = relevantEntityTypes
? relevantEntityTypes[0]!.inner
: null;

await loadTypeSystem();

if (!cancelled) {
setEntityType(relevantEntity);
entityTypeRef.current = relevantEntity;
if (relevantEntity) {
onCompletedRef.current?.(relevantEntity);
setEntityType(relevantEntityType);
entityTypeRef.current = relevantEntityType;
if (relevantEntityType) {
onCompletedRef.current?.(relevantEntityType);
}
}
});
Expand Down