Skip to content

H-4204: Remove @local/hash-subgraph package #6812

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

Merged
merged 13 commits into from
Apr 16, 2025

Conversation

CiaranMn
Copy link
Member

@CiaranMn CiaranMn commented Mar 28, 2025

🌟 What is the purpose of this PR?

The @local/hash-subgraph package was used to redefine certain things in @blockprotocol/graph, when the latter was in a different repository and for ease of development.

Now that they're both in the same repo, it makes sense to consolidate them, so that there aren't multiple places exporting types with the same name, which removes the chance of importing the 'wrong' one. This PR does that.

As @blockprotocol/graph (and @blockprotocol/type-system) are intended to be usable in non-HASH applications, the general principle of changes is that anything which is very HASH-specific goes into the @local/hash-graph-sdk ("the SDK"), and anything which is generalizable into one of the @blockprotocol packages (graph for working with a sub-graph, type-system for defining types and entities).

Notably:

  • @blockprotocol/type-system defines a generic interface for an Entity (e.g. for property and metadata access), which is then implemented by HashEntity in the SDK (adding instance methods such as .patch).
  • Some types are renamed to avoid clashes, e.g. Subgraph in the GraphQL typedefs is renamed to GqlSubgraph.
  • Functions and types which were added over time to @local/hash-subgraph but not to @blockprotocol/graph are ported over.

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

🐾 Next steps

There is scope for further package consolidation / rationalisation work (H-4205).

For example:

  1. @local/hash-graph-types contains very few types and could probably be consolidated into @local/hash-graph-sdk on the basis that it contains types which are specific to working with the HASH Graph API, related to e.g. embeddings and entity validation. The equivalent Rust crate could stay where it is for now, and @local/hash-graph-types import it.
  2. There are some other types related to 'working with the Graph API' which are somewhat arbitrary located in other packages, such as @local/hash-isomorphic-tools. They could all be moved into @local/hash-graph-sdk
  3. Because @local/hash-graph-client still exports

🛡 What tests cover this?

  • The changes are across the TS apps and there is some coverage of key areas via there, although they're mostly type-related.

❓ How to test this?

  1. Check 'everything still works'

@github-actions github-actions bot added area/deps Relates to third-party dependencies (area) area/apps > hash* Affects HASH (a `hash-*` app) area/infra Relates to version control, CI, CD or IaC (area) area/apps > hash-api Affects the HASH API (app) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team type/eng > backend Owned by the @backend team area/tests New or updated tests area/tests > integration New or updated integration tests area/tests > playwright New or updated Playwright tests area/apps type/legal Owned by the @legal team labels Mar 28, 2025
Copy link

codecov bot commented Mar 28, 2025

Codecov Report

Attention: Patch coverage is 4.00000% with 72 lines in your changes missing coverage. Please review.

Project coverage is 31.06%. Comparing base (b42ecac) to head (0a075d8).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...s/hash-api/src/graph/knowledge/primitive/entity.ts 0.00% 8 Missing ⚠️
...ctivities/flow-activities/persist-entity-action.ts 0.00% 4 Missing ⚠️
...raph-is-initialized/migrate-ontology-types/util.ts 0.00% 4 Missing ⚠️
...h-api/src/graph/knowledge/primitive/link-entity.ts 0.00% 4 Missing ⚠️
apps/hash-ai-worker-ts/src/activities/graph.ts 0.00% 3 Missing ⚠️
...orker-ts/src/activities/shared/get-flow-context.ts 0.00% 3 Missing ⚠️
...sh-api/src/graph/ontology/primitive/entity-type.ts 0.00% 3 Missing ⚠️
...nt-action/generate-proposed-entities-and-claims.ts 0.00% 2 Missing ⚠️
...ivities/flow-activities/persist-entities-action.ts 0.00% 2 Missing ⚠️
...es-from-claims/propose-entity-from-claims-agent.ts 0.00% 2 Missing ⚠️
... and 30 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6812      +/-   ##
==========================================
+ Coverage   30.73%   31.06%   +0.32%     
==========================================
  Files         606      607       +1     
  Lines       23272    23408     +136     
  Branches     2965     2968       +3     
==========================================
+ Hits         7152     7271     +119     
- Misses      16063    16080      +17     
  Partials       57       57              
Flag Coverage Δ
apps.hash-api 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@CiaranMn CiaranMn marked this pull request as ready for review April 15, 2025 17:32
@CiaranMn CiaranMn requested a review from a team as a code owner April 15, 2025 17:32
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 405 out of 406 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • apps/hash-ai-worker-ts/package.json: Language not supported
Comments suppressed due to low confidence (2)

apps/hash-ai-worker-ts/src/activities/graph.ts:257

  • The addition of the 'false' parameter to the getEntities call changes its behavior. Please add a comment explaining its purpose to ensure future maintainers understand that this behavior is intentional.
return getEntities(deserializeSubgraph(params.subgraph), false).map((entity) => entity.toJSON()),

apps/hash-ai-worker-ts/src/activities/flow-activities/write-google-sheet-action/get-subgraph-from-filter.ts:43

  • Parameterizing EntityRootType with HashEntity suggests a change in type expectations. Verify that the generic usage aligns with the intended design and update related documentation if necessary.
return mapGraphApiSubgraphToSubgraph<EntityRootType<HashEntity>>(

Copy link
Contributor

Benchmark results

@rust/hash-graph-benches – Integrations

representative_read_entity

Function Value Mean Flame graphs
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/playlist/v/1 $$17.2 \mathrm{ms} \pm 223 \mathrm{μs}\left({\color{red}5.29 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/person/v/1 $$16.3 \mathrm{ms} \pm 165 \mathrm{μs}\left({\color{gray}-2.986 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/book/v/1 $$16.5 \mathrm{ms} \pm 189 \mathrm{μs}\left({\color{lightgreen}-29.499 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1 $$15.8 \mathrm{ms} \pm 211 \mathrm{μs}\left({\color{lightgreen}-7.483 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/song/v/1 $$17.8 \mathrm{ms} \pm 195 \mathrm{μs}\left({\color{gray}-2.426 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/building/v/1 $$15.9 \mathrm{ms} \pm 170 \mathrm{μs}\left({\color{lightgreen}-31.803 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/organization/v/1 $$16.6 \mathrm{ms} \pm 217 \mathrm{μs}\left({\color{gray}-1.763 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/page/v/2 $$16.6 \mathrm{ms} \pm 185 \mathrm{μs}\left({\color{gray}-3.070 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/block/v/1 $$16.3 \mathrm{ms} \pm 201 \mathrm{μs}\left({\color{gray}-1.751 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_complete_zero_depth

Function Value Mean Flame graphs
entity_by_id 10 entities $$2.24 \mathrm{ms} \pm 12.2 \mathrm{μs}\left({\color{gray}-0.629 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 5 entities $$2.04 \mathrm{ms} \pm 15.7 \mathrm{μs}\left({\color{gray}-1.119 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 50 entities $$4.18 \mathrm{ms} \pm 23.2 \mathrm{μs}\left({\color{gray}-1.206 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 25 entities $$3.40 \mathrm{ms} \pm 18.3 \mathrm{μs}\left({\color{red}17.8 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$1.99 \mathrm{ms} \pm 8.47 \mathrm{μs}\left({\color{gray}-2.300 \mathrm{\%}}\right) $$ Flame Graph

representative_read_entity_type

Function Value Mean Flame graphs
get_entity_type_by_id Account ID: d4e16033-c281-4cde-aa35-9085bf2e7579 $$2.15 \mathrm{ms} \pm 8.08 \mathrm{μs}\left({\color{gray}-1.846 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_linkless

Function Value Mean Flame graphs
entity_by_id 10000 entities $$13.6 \mathrm{ms} \pm 83.8 \mathrm{μs}\left({\color{red}45.9 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 100 entities $$2.21 \mathrm{ms} \pm 11.3 \mathrm{μs}\left({\color{gray}-2.061 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10 entities $$2.04 \mathrm{ms} \pm 10.3 \mathrm{μs}\left({\color{gray}-0.843 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1000 entities $$3.05 \mathrm{ms} \pm 18.2 \mathrm{μs}\left({\color{lightgreen}-5.075 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$2.02 \mathrm{ms} \pm 9.77 \mathrm{μs}\left({\color{gray}-1.277 \mathrm{\%}}\right) $$ Flame Graph

representative_read_multiple_entities

Function Value Mean Flame graphs
entity_by_property depths: DT=0, PT=2, ET=2, E=2 $$53.6 \mathrm{ms} \pm 225 \mathrm{μs}\left({\color{gray}-1.155 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=0, E=0 $$37.8 \mathrm{ms} \pm 286 \mathrm{μs}\left({\color{gray}-4.013 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=0, E=2 $$42.5 \mathrm{ms} \pm 331 \mathrm{μs}\left({\color{gray}-2.693 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=2, PT=2, ET=2, E=2 $$57.6 \mathrm{ms} \pm 322 \mathrm{μs}\left({\color{gray}0.196 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=255, PT=255, ET=255, E=255 $$67.0 \mathrm{ms} \pm 514 \mathrm{μs}\left({\color{gray}-0.487 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=2, E=2 $$50.5 \mathrm{ms} \pm 397 \mathrm{μs}\left({\color{gray}3.12 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=2, ET=2, E=2 $$87.8 \mathrm{ms} \pm 432 \mathrm{μs}\left({\color{gray}-0.210 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=0, E=0 $$39.7 \mathrm{ms} \pm 472 \mathrm{μs}\left({\color{gray}2.71 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=0, E=2 $$74.3 \mathrm{ms} \pm 491 \mathrm{μs}\left({\color{gray}-0.701 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=2, PT=2, ET=2, E=2 $$91.5 \mathrm{ms} \pm 587 \mathrm{μs}\left({\color{gray}-1.345 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=255, PT=255, ET=255, E=255 $$101 \mathrm{ms} \pm 737 \mathrm{μs}\left({\color{gray}-3.908 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=2, E=2 $$84.5 \mathrm{ms} \pm 945 \mathrm{μs}\left({\color{gray}1.42 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_complete_one_depth

Function Value Mean Flame graphs
entity_by_id 10 entities $$50.1 \mathrm{ms} \pm 3.64 \mathrm{ms}\left({\color{red}54.3 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 5 entities $$27.6 \mathrm{ms} \pm 243 \mathrm{μs}\left({\color{gray}-0.522 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 50 entities $$269 \mathrm{ms} \pm 2.51 \mathrm{ms}\left({\color{lightgreen}-95.016 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 25 entities $$182 \mathrm{ms} \pm 730 \mathrm{μs}\left({\color{gray}-0.308 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$21.0 \mathrm{ms} \pm 112 \mathrm{μs}\left({\color{gray}-2.206 \mathrm{\%}}\right) $$ Flame Graph

@CiaranMn CiaranMn enabled auto-merge April 15, 2025 18:20
@CiaranMn CiaranMn added this pull request to the merge queue Apr 16, 2025
Merged via the queue into main with commit dfe9577 Apr 16, 2025
157 of 158 checks passed
@CiaranMn CiaranMn deleted the cm/remove-hash-subgraph-package branch April 16, 2025 07:30
@CiaranMn CiaranMn changed the title H-2404: Remove @local/hash-subgraph package H-4204: Remove @local/hash-subgraph package Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/apps > hash* Affects HASH (a `hash-*` app) area/apps > hash-api Affects the HASH API (app) area/apps area/deps Relates to third-party dependencies (area) area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) area/tests > integration New or updated integration tests area/tests > playwright New or updated Playwright tests area/tests New or updated tests type/eng > backend Owned by the @backend team type/eng > frontend Owned by the @frontend team type/legal Owned by the @legal team
Development

Successfully merging this pull request may close these issues.

3 participants