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-345: Fix hash-graph-client class names #2872

Merged
merged 18 commits into from
Aug 8, 2023
Merged

Conversation

indietyp
Copy link
Member

@indietyp indietyp commented Aug 7, 2023

🌟 What is the purpose of this PR?

This fixes the class names generated by hash-graph-client done through a combination of factors.

  1. use the title to generate the name
  2. supply titles to missing things
  3. factor out common definitions into separate files from models

🔗 Related links

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

📹 Demo

@github-actions github-actions bot added area/apps > hash* Affects HASH (a `hash-*` app) area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team labels Aug 7, 2023
@github-actions github-actions bot added area/deps Relates to third-party dependencies (area) area/apps area/apps > hash-graph labels Aug 7, 2023
@indietyp
Copy link
Member Author

indietyp commented Aug 7, 2023

Moved most things into shared (that can be shared). @TimDiekmann please sanity check!

To be able to accommodate these changes I switched from the swagger-cli to redocly/cli. Only problem: Now, propertyNames is no longer resolved.

(turns out that datamodel-code-generator supports them, even tho they are not in the spec, but redocly ignores them).

There are still some left that have numbers in their name, I'll try to remove them in one of the other commits.

@indietyp
Copy link
Member Author

indietyp commented Aug 7, 2023

The issue in question about patternProperties: Redocly/redocly-cli#792

@vilkinsons vilkinsons changed the title Fix hash-graph-client class names H-345: Fix hash-graph-client class names Aug 7, 2023
@linear
Copy link

linear bot commented Aug 7, 2023

H-345

TimDiekmann
TimDiekmann previously approved these changes Aug 8, 2023
Copy link
Member

@TimDiekmann TimDiekmann left a comment

Choose a reason for hiding this comment

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

The names are much much better!



class VersionedUrl(RootModel):
class DataType(BaseModel):
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can use downstream either the custom models I've written (removing this) or use this as base class for the custom model. I think they match?

Copy link
Member Author

Choose a reason for hiding this comment

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

That should be possible indeed, only has the side-effect that we do not have a common Schema base (which is helpful in some circumstances), but using --reuse-model we can probably coerce datamodel-code-generator into creating one^^

Copy link
Member Author

Choose a reason for hiding this comment

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

The types should now have parity with the ones in the hash-graph-types; I'd personally prefer if we keep the "chain," meaning graph-client as the base (as it is the most low level). The only problem I see is that (unlike Rust) Python offers no real way for composing and extending existing classes, except for subclassing.

Copy link
Member

Choose a reason for hiding this comment

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

As this is already a BaseModel this should be fine I guess?

@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Attention: Patch coverage is 0% with 28 lines in your changes missing coverage. Please review.

Project coverage is 51.72%. Comparing base (1cede36) to head (34d236f).
Report is 2618 commits behind head on main.

Files with missing lines Patch % Lines
apps/hash-graph/lib/graph/src/api/rest.rs 0.00% 13 Missing ⚠️
...hash-graph/lib/graph/src/subgraph/temporal_axes.rs 0.00% 10 Missing ⚠️
apps/hash-graph/lib/graph/src/ontology.rs 0.00% 4 Missing ⚠️
apps/hash-graph/lib/graph/src/api/rest/entity.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2872      +/-   ##
==========================================
- Coverage   51.76%   51.72%   -0.05%     
==========================================
  Files         337      337              
  Lines       28901    28916      +15     
  Branches      431      431              
==========================================
- Hits        14960    14956       -4     
- Misses      13939    13958      +19     
  Partials        2        2              
Flag Coverage Δ
backend-integration-tests 7.34% <ø> (ø)
hash-graph 54.40% <0.00%> (-0.08%) ⬇️
unit-tests 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.

@github-actions github-actions bot added the area/infra Relates to version control, CI, CD or IaC (area) label Aug 8, 2023
@indietyp
Copy link
Member Author

indietyp commented Aug 8, 2023

Overview of the typescript changes

screenshot 2023-08-08T15-38-33
screenshot 2023-08-08T15-38-56
screenshot 2023-08-08T15-39-12
screenshot 2023-08-08T15-39-32
screenshot 2023-08-08T15-40-04
screenshot 2023-08-08T15-40-26

Copy link
Member Author

@indietyp indietyp Aug 8, 2023

Choose a reason for hiding this comment

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

I needed to move this out, because openapi-generator doesn't understand nested relative paths properly.

If I am pointing at ./shared.json in models/property_type.json it still searches for shared.json in the openapi directory. Like datamodel-code-generator I switched to @redocly/cli to bundle everything beforehand, but that comes with it's own challenges, for status.json it doesn't remove the definitions, and instead of ignoring it, openapi-generator just errors out, moving this to a separate filed solved the problem.

Although i don't know why the problem wasn't there in the first place... 🤔

Comment on lines 40 to 43
pub trait TemporalAxis {
/// The name of the temporal axis.
fn noun() -> &'static str;
}
Copy link
Member

Choose a reason for hiding this comment

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

Honestly: I really don't like this. This feels like adding reflection to a type where it does not belong to. I see why you did that. If we don't find a better solution or want to implement this manually we should move this trait to utoipa_typedefs.rs as this absolutely does not belong here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I first had this in utoipa_typedefs.rs (under the name TemporalSchema or TemporalAxisInfo), but the schema for the axis isn't located utoipa_typedef, and I didn't want to pub out of api/rest.

(Personally also don't really like this, but it was the only way I found works in a Rust-like way without too much overhead.)

Copy link
Member

Choose a reason for hiding this comment

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

Is it only used in temporal_asxes.rs? Then let's define it there and make it private to that module.

@@ -7,7 +7,7 @@
"main": "index.ts",
"scripts": {
"build": "echo 'no build needed, this is here to orchestrate turborepo'",
"codegen": "openapi-generator-cli generate"
"codegen": "redocly bundle --format=json -o openapi.bundle.json ../../../../apps/hash-graph/openapi/openapi.json && openapi-generator-cli generate && rm openapi.bundle.json"
Copy link
Member

Choose a reason for hiding this comment

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

How does this play together with the caching as this is creating a temporary file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nothing changes; it's simply a buffer, as I had some problems directly piping in stdout. The bundle output is the same if the schema is the same, so no worries.

apps/hash-graph/lib/graph/src/api/rest/utoipa_typedef.rs Outdated Show resolved Hide resolved
Comment on lines 40 to 43
pub trait TemporalAxis {
/// The name of the temporal axis.
fn noun() -> &'static str;
}
Copy link
Member

Choose a reason for hiding this comment

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

Is it only used in temporal_asxes.rs? Then let's define it there and make it private to that module.

@indietyp indietyp added this pull request to the merge queue Aug 8, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 8, 2023
@TimDiekmann TimDiekmann added this pull request to the merge queue Aug 8, 2023
Merged via the queue into main with commit 04eb03a Aug 8, 2023
@TimDiekmann TimDiekmann deleted the bm/graph/name-fix branch August 8, 2023 20:53
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-graph 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) type/eng > backend Owned by the @backend team
Development

Successfully merging this pull request may close these issues.

2 participants