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

fix: bad name on shared types #955

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

fix: bad name on shared types #955

wants to merge 4 commits into from

Conversation

michael-0acf4
Copy link
Contributor

@michael-0acf4 michael-0acf4 commented Jan 7, 2025

Since types can be shared, prefixing the name with the first function/path encountered would be confusing for the other types that also refers to it.

This patch disables prefixing for types with more than one referrer.

Migration notes

None

  • The change comes with new or modified tests
  • Hard-to-understand functions have explanatory comments
  • End-user documentation is updated to reflect the change

Summary by CodeRabbit

  • Improvements
    • Enhanced type naming logic with advanced reference counting mechanism.
    • Improved name generation for types with multiple references.
    • Refined handling of type naming for complex scenarios like function inputs and outputs.
  • Type Updates
    • Standardized naming convention for scalar types across various modules.
    • Updated argument and return types for multiple functions to reflect new scalar types.
    • Adjusted JSON schema to align with new type definitions and naming conventions.
  • Version Update
    • Incremented version string to "0.5.0-rc.9" for compatibility checks.

Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

📝 Walkthrough

Walkthrough

The changes in the naming.rs file focus on enhancing the type naming processor by incorporating reference counting mechanisms. A new TypeRefCount struct is introduced, and the VisitCollector is updated to track type references across different contexts. The implementation now supports more sophisticated naming strategies by understanding how many times a specific type is referenced, which allows for more nuanced name generation based on type usage patterns. Other files reflect a systematic renaming of type aliases across various modules to standardize naming conventions.

Changes

File Change Summary
src/typegraph/core/src/utils/postprocess/naming.rs - Added IndexSet import from indexmap crate
- Introduced TypeRefCount struct with reference counting logic
- Updated VisitCollector with counts and name_occurences fields
- Modified postprocess method to initialize reference counters
- Added collect_ref_info function for recursive reference tracking
- Enhanced gen_name function with reference-aware naming strategy
examples/typegraphs/metagen/rs/fdk.rs - Updated version string from "0.5.0-rc.8" to "0.5.0-rc.9"
- Renamed type aliases: Idv3TitleString to ScalarString1, Idv3ReleaseTimeStringDatetime to ScalarStringDatetime1, Idv3Mp3UrlStringUri to ScalarStringUri1
src/typegate/src/typegraphs/introspection.json - Updated titles for string types and optional fields for clarity and consistency
src/typegate/src/typegraphs/typegate.json - Renamed object titles to reflect a standardized naming convention
- Updated input and output structures for several functions to include new properties
tests/metagen/typegraphs/identities/rs/fdk.rs - Renamed type aliases to follow new scalar naming convention
- Updated struct fields to use new scalar types
tests/metagen/typegraphs/identities/ts/fdk.ts - Renamed exported types to new scalar naming convention
- Updated Primitives and other composite types to reference new scalar types
tests/metagen/typegraphs/sample/py/client.py - Updated argument and return types in NodeDescs class to use new scalar types
tests/metagen/typegraphs/sample/py_upload/client.py - Modified argument types and return types for file upload functions to reflect new scalar types
tests/metagen/typegraphs/sample/rs/client.rs - Renamed type aliases and updated their usage in function signatures and struct fields
tests/metagen/typegraphs/sample/rs/main.rs - Updated function calls to use new scalar types instead of previous types
tests/metagen/typegraphs/sample/rs_upload/client.rs - Modified argument types for upload functions and updated return types to reflect new scalar types
tests/metagen/typegraphs/sample/ts/client.ts - Updated argument types and return types in various functions to use new scalar types
tests/metagen/typegraphs/sample/ts_upload/client.ts - Changed argument types and return types for upload functions to reflect new scalar types
tests/runtimes/wasm_wire/rust/fdk.rs - Updated version string and renamed type aliases to new scalar naming convention
- Modified struct fields and method signatures to use new scalar types

Sequence Diagram

sequenceDiagram
    participant NP as NamingProcessor
    participant TRC as TypeRefCount
    participant VC as VisitCollector
    
    NP->>TRC: Initialize reference counters
    NP->>TRC: Collect reference info for each property
    TRC-->>NP: Populate reference counts
    
    NP->>VC: Create VisitCollector with reference counts
    VC->>NP: Track type references
    
    NP->>NP: Generate names based on reference counts
Loading

The sequence diagram illustrates the new workflow of reference counting and name generation, showing how the NamingProcessor now tracks and uses type reference information to inform its naming strategy.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/typegraph/core/src/utils/postprocess/naming.rs (1)

306-322: Optimize naming logic in gen_name to prevent excessively long names.

The gen_name function builds type names based on the path and type, which might result in long and unwieldy names for deeply nested structures. Consider simplifying the naming convention or limiting the depth of recursion to improve readability and maintainability of the generated names.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c0022e and 767048e.

📒 Files selected for processing (1)
  • src/typegraph/core/src/utils/postprocess/naming.rs (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test-full
  • GitHub Check: lint-compat (macos-14, aarch64-apple-darwin, false)
  • GitHub Check: lint-compat (macos-13, x86_64-apple-darwin, false)
  • GitHub Check: pre-commit
🔇 Additional comments (4)
src/typegraph/core/src/utils/postprocess/naming.rs (4)

13-13: Appropriate use of IndexSet for tracking referers.

The introduction of IndexSet from the indexmap crate is suitable for maintaining a set of referers with insertion order preserved, which can be beneficial for consistent naming.


37-48: Correct initialization and usage of reference counters.

The creation of ref_counters and the population of reference information using collect_ref_info are properly implemented. Transferring the counts to VisitCollector ensures accurate tracking of type references.


83-91: Efficient implementation of TypeRefCount::new_hit.

The new_hit method effectively updates the counts HashMap by inserting new referers or modifying existing entries. Using IndexSet ensures that referers are unique and order is maintained.


94-101: Effective check in has_more_than_one_referer.

The method has_more_than_one_referer accurately determines if a type has multiple referers by checking the length of the referer set. This is crucial for the naming logic that depends on the number of referers.

src/typegraph/core/src/utils/postprocess/naming.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/typegraph/core/src/utils/postprocess/naming.rs (1)

258-316: Consider simplifying cycle handling based on type system constraints.

According to the domain knowledge, cyclic types can only occur with user-renamed types, which are skipped by the naming processor. This means the cycle detection using visited set might be unnecessary.

You could simplify the function by removing the cycle detection:

-fn collect_ref_info(
-    cx: &VisitContext,
-    acc: &mut TypeRefCount,
-    id: u32,
-    visited: &mut HashSet<u32>,
-) -> anyhow::Result<()> {
-    if !visited.insert(id) {
-        return Ok(());
-    }
+fn collect_ref_info(
+    cx: &VisitContext,
+    acc: &mut TypeRefCount,
+    id: u32,
+) -> anyhow::Result<()> {
+    if cx.user_named.contains(&id) {
+        return Ok(());
+    }

     let node = &cx.tg.types[id as usize];
     match node {
         // ... existing match arms with updated recursive calls ...
     };

-    visited.remove(&id);
     Ok(())
 }

This would make the code simpler while maintaining correctness, as the type system's constraints naturally prevent cycles.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 767048e and 18bc3cc.

📒 Files selected for processing (1)
  • src/typegraph/core/src/utils/postprocess/naming.rs (5 hunks)
🧰 Additional context used
📓 Learnings (1)
src/typegraph/core/src/utils/postprocess/naming.rs (1)
Learnt from: michael-0acf4
PR: metatypedev/metatype#955
File: src/typegraph/core/src/utils/postprocess/naming.rs:258-305
Timestamp: 2025-01-07T20:11:43.287Z
Learning: In the Metatype codebase's type system (src/typegraph/core/src/utils/postprocess/naming.rs), cyclic types can only occur with user-renamed types, as a reference can only exist after a rename happens. These cycles are naturally handled because the naming post-processor skips processing of user-renamed types.
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: lint-compat (macos-14, aarch64-apple-darwin, false)
  • GitHub Check: lint-compat (macos-13, x86_64-apple-darwin, false)
  • GitHub Check: test-full
  • GitHub Check: pre-commit
🔇 Additional comments (5)
src/typegraph/core/src/utils/postprocess/naming.rs (5)

13-13: LGTM! Well-designed data structures for reference tracking.

The choice of IndexSet and the addition of reference counting structures are well-thought-out. The IndexSet provides efficient operations while maintaining insertion order, which is beneficial for consistent type naming.

Also applies to: 74-74, 78-80


36-48: LGTM! Good separation of concerns in the postprocessing logic.

The two-phase approach (collecting references before name generation) is well-structured and maintains clear separation of concerns.


82-91: LGTM! Clean and efficient reference counting implementation.

The new_hit method makes good use of the Entry API for atomic operations, handling both new and existing entries efficiently.


93-101: LGTM! Clear and safe implementation of reference checking.

The has_more_than_one_referrer method is well-named and safely handles the case when a type has no referrers.


325-332: LGTM! Clear strategy for handling shared type names.

The implementation elegantly handles shared types by using a different naming scheme when a type has multiple referrers, preventing confusion that could arise from path-based naming.

Also applies to: 343-345

luckasRanarison
luckasRanarison previously approved these changes Jan 8, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/metagen/typegraphs/sample/rs/client.rs (1)

236-237: Clarify the naming of ScalarStructShared2Partial

The struct ScalarStructShared2Partial is used as an argument type in several functions but has a name that may not clearly convey its purpose. Renaming it to something more descriptive, like IdArgsPartial or CommonArgsPartial, could improve code clarity and maintainability.

Also applies to: 430-475

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18bc3cc and 1516494.

⛔ Files ignored due to path filters (11)
  • src/typegraph/core/src/snapshots/typegraph_core__tests__successful_serialization.snap is excluded by !**/*.snap
  • tests/e2e/typegraph/__snapshots__/typegraph_test.ts.snap is excluded by !**/*.snap
  • tests/metagen/__snapshots__/metagen_test.ts.snap is excluded by !**/*.snap
  • tests/runtimes/graphql/__snapshots__/graphql_test.ts.snap is excluded by !**/*.snap
  • tests/runtimes/grpc/__snapshots__/grpc_test.ts.snap is excluded by !**/*.snap
  • tests/runtimes/kv/__snapshots__/kv_test.ts.snap is excluded by !**/*.snap
  • tests/runtimes/s3/__snapshots__/s3_test.ts.snap is excluded by !**/*.snap
  • tests/runtimes/temporal/__snapshots__/temporal_test.ts.snap is excluded by !**/*.snap
  • tests/runtimes/typegate/__snapshots__/typegate_prisma_test.ts.snap is excluded by !**/*.snap
  • tests/runtimes/typegate/__snapshots__/typegate_runtime_test.ts.snap is excluded by !**/*.snap
  • tests/runtimes/wasm_reflected/rust/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (14)
  • examples/typegraphs/metagen/rs/fdk.rs (2 hunks)
  • src/typegate/src/typegraphs/introspection.json (3 hunks)
  • src/typegate/src/typegraphs/typegate.json (13 hunks)
  • src/typegraph/core/src/utils/postprocess/naming.rs (5 hunks)
  • tests/metagen/typegraphs/identities/rs/fdk.rs (4 hunks)
  • tests/metagen/typegraphs/identities/ts/fdk.ts (3 hunks)
  • tests/metagen/typegraphs/sample/py/client.py (16 hunks)
  • tests/metagen/typegraphs/sample/py_upload/client.py (3 hunks)
  • tests/metagen/typegraphs/sample/rs/client.rs (14 hunks)
  • tests/metagen/typegraphs/sample/rs/main.rs (4 hunks)
  • tests/metagen/typegraphs/sample/rs_upload/client.rs (6 hunks)
  • tests/metagen/typegraphs/sample/ts/client.ts (8 hunks)
  • tests/metagen/typegraphs/sample/ts_upload/client.ts (3 hunks)
  • tests/runtimes/wasm_wire/rust/fdk.rs (3 hunks)
👮 Files not reviewed due to content moderation or server errors (4)
  • tests/metagen/typegraphs/sample/ts_upload/client.ts
  • tests/metagen/typegraphs/sample/py_upload/client.py
  • tests/metagen/typegraphs/sample/ts/client.ts
  • tests/metagen/typegraphs/sample/py/client.py
🧰 Additional context used
📓 Learnings (1)
src/typegraph/core/src/utils/postprocess/naming.rs (1)
Learnt from: michael-0acf4
PR: metatypedev/metatype#955
File: src/typegraph/core/src/utils/postprocess/naming.rs:258-305
Timestamp: 2025-01-07T20:11:43.287Z
Learning: In the Metatype codebase's type system (src/typegraph/core/src/utils/postprocess/naming.rs), cyclic types can only occur with user-renamed types, as a reference can only exist after a rename happens. These cycles are naturally handled because the naming post-processor skips processing of user-renamed types.
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: lint-compat (macos-14, aarch64-apple-darwin, false)
  • GitHub Check: lint-compat (macos-13, x86_64-apple-darwin, false)
  • GitHub Check: bulid-docker (linux/amd64, custom-ubuntu-large)
  • GitHub Check: test-full
  • GitHub Check: pre-commit
🔇 Additional comments (34)
tests/metagen/typegraphs/sample/rs_upload/client.rs (4)

45-48: Updated argument types for RootUploadFn improve consistency

The argument types for RootUploadFn have been updated to use ScalarFileShared1 and RootUploadFnInputPathScalarString1Optional, enhancing naming consistency and better reflecting shared scalar types.


65-69: Consistent use of scalar types in RootUploadManyFn

The argument types for RootUploadManyFn have been updated to RootUploadManyFnInputPrefixScalarString1Optional and RootUploadManyFnInputFilesScalarFileShared1List, improving consistency across the codebase by standardizing the naming convention of shared scalar types.


84-99: Addition of scalar type definitions enhances clarity

The introduction of scalar type definitions such as ScalarFileShared1, ScalarString1, and ScalarBoolean1 provides clearer and more consistent naming for shared types, improving code readability and maintainability.


130-130: Confirm the change in return type to ScalarBoolean1

The return types of the upload and upload_many functions have been changed to MutationNode<ScalarBoolean1>. Please verify that this change is intentional and ensure that all calling code handles the new return type correctly to prevent potential runtime errors.

Also applies to: 148-148

tests/metagen/typegraphs/sample/rs/client.rs (2)

88-90: Updated argument types in RootScalarArgsFn enhance type consistency

The argument types for id, slug, and title have been updated to use ScalarStringUuid1 and ScalarString1, aligning with the new scalar type definitions and improving type consistency across the codebase.


227-233: Consistent scalar type definitions in types module

The types module now uses ScalarStringUuid1 and ScalarString1 for type aliases and struct fields, providing a consistent and clear type system that enhances code readability.

tests/metagen/typegraphs/identities/ts/fdk.ts (4)

36-47: Updated scalar type definitions improve code clarity

Introducing scalar types like ScalarString1, ScalarInteger1, and others standardizes the type definitions, enhancing code clarity and consistency across the codebase.


49-60: Refactoring Primitives to use new scalar types

The Primitives type now relies on the updated scalar types, which improves the consistency of type usage and simplifies understanding of the underlying data structures.


65-85: Consistent naming in composite types

Composite types such as CompositesOptScalarString1Optional and CompositesListScalarString1List now use the new scalar type names, ensuring consistent naming conventions throughout the code.


118-128: Enhanced clarity in cyclic type definitions

The cyclic types like SimpleCycles1, SimpleCycles2, and SimpleCycles3 have been updated to use the new scalar type definitions, which improves readability and helps prevent potential confusion in the cyclic relationships.

examples/typegraphs/metagen/rs/fdk.rs (3)

222-224: LGTM! Type aliases follow the new naming convention.

The renaming from specific prefixes to generic Scalar prefixes aligns with the PR objective to fix naming of shared types.


227-232: LGTM! Struct fields consistently use the new type aliases.

The field types are correctly updated to use the new scalar types while preserving the serde attributes.


112-112: Verify version compatibility.

The version bump from rc.8 to rc.9 aligns with the API changes for type naming. Please ensure all dependent packages are updated accordingly.

✅ Verification successful

Version update is consistently applied

The version bump to 0.5.0-rc.9 has been properly synchronized across all relevant files in the codebase, including package manifests, source files, and tests. The only expected difference is in tools/consts.ts where PUBLISHED_VERSION tracks the previous release.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for version references across the codebase.

# Search for version string references
rg -g '!target' -g '!*.lock' '"0.5.0-rc.[0-9]"'

Length of output: 1565

tests/metagen/typegraphs/sample/rs/main.rs (5)

41-42: LGTM! Type update follows the new naming convention.

The type has been correctly updated to use ScalarStructShared2Partial while preserving the closure logic.


101-104: LGTM! Mutation correctly uses the new type.

The mutation has been updated to use ScalarStructShared2Partial while maintaining the same structure.


110-116: LGTM! Query correctly uses the new type.

The scalar_union query has been updated to use ScalarStructShared2Partial consistently.


123-127: LGTM! Query correctly uses the new type.

The composite_union query has been updated to use ScalarStructShared2Partial while preserving the selection structure.


Line range hint 130-137: LGTM! Query correctly uses the new type.

The mixed_union query has been updated to use ScalarStructShared2Partial while maintaining the selection structure.

tests/runtimes/wasm_wire/rust/fdk.rs (3)

112-112: Version update is consistent.

The version bump matches other files in the codebase.


222-268: LGTM! Comprehensive update to new type naming convention.

The changes consistently apply the new scalar type naming convention across all type aliases and struct fields while preserving serde attributes.


293-293: LGTM! Handler signature updated correctly.

The handler's return type has been updated to use the new scalar type.

tests/metagen/typegraphs/identities/rs/fdk.rs (3)

222-233: LGTM! Basic scalar types follow the new convention.

The type aliases consistently use the "Scalar" prefix and maintain appropriate primitive type mappings.


236-248: LGTM! Struct fields consistently use new scalar types.

The field types have been updated to use the new scalar types while preserving serde attributes and documentation.


Line range hint 254-340: LGTM! Complex types consistently use new naming convention.

The changes maintain type relationships and hierarchy while adopting the new scalar type naming convention throughout complex and nested structures.

src/typegraph/core/src/utils/postprocess/naming.rs (8)

13-13: LGTM: Import of IndexSet for efficient reference tracking.

The IndexSet provides both set operations and indexing, which is ideal for tracking type references.


36-42: LGTM: Reference counting initialization.

The implementation correctly initializes reference counting before processing types, which is essential for tracking shared types.


44-50: LGTM: Enhanced VisitCollector initialization.

The collector now includes reference counting data and name occurrence tracking, which supports the new naming strategy.


77-80: LGTM: New fields in VisitCollector.

The added fields support reference counting and name tracking:

  • counts: Maps type IDs to their referrers
  • name_occurences: Tracks name usage frequency

82-95: LGTM: TypeRefCount implementation.

Clean implementation of reference counting with:

  • Efficient storage using HashMap and IndexSet
  • Clear method for updating references

97-117: LGTM: Helper methods for name generation.

Well-implemented helper methods:

  • has_more_than_one_referrer: Clear check for shared types
  • next_name: Generates unique names with incrementing counters

275-335: LGTM: Comprehensive reference collection implementation.

The collect_ref_info function correctly:

  • Handles all type variants
  • Skips user-named types
  • Uses visited set to prevent redundant processing

Note: Previous concerns about cyclic references are addressed by the codebase's design where cyclic types can only occur with user-renamed types, which are skipped by this processor.


Line range hint 338-374: LGTM: Enhanced name generation logic.

The updated gen_name function now:

  • Preserves user-named types
  • Uses scalar naming for basic types
  • Handles shared types with special naming
src/typegate/src/typegraphs/introspection.json (1)

48-48: LGTM: Consistent scalar type naming.

The renaming follows the new convention for scalar types:

  • Basic string type → scalar_string_1
  • Optional string type → scalar_string_1_optional
  • Boolean type → scalar_boolean_1

Also applies to: 102-102, 130-130, 136-136

src/typegate/src/typegraphs/typegate.json (1)

86-86: LGTM: Consistent scalar and shared type naming.

The renaming follows the established convention:

  • Scalar types: scalar_string_1, scalar_boolean_1, etc.
  • Shared types: scalar_struct_shared_1, scalar_struct_shared_2, etc.
  • Enums: scalar_string_enum_1, scalar_string_enum_2, etc.

Also applies to: 112-112, 116-116, 201-201, 243-243, 299-299, 304-304, 443-443, 480-480, 599-599, 700-700, 706-706, 780-780

tests/metagen/typegraphs/sample/rs/client.rs Show resolved Hide resolved
@Yohe-Am
Copy link
Contributor

Yohe-Am commented Jan 8, 2025

What was that proposal of yours to avoid stability issues around the numbers? The current names would change when you expose new functions that are not placed at the end.

Edit: right, using the reference count? Wouldn't that lead to duplicate names?

@Yohe-Am
Copy link
Contributor

Yohe-Am commented Jan 8, 2025

How about, alternatively, we use "short hashes of the first reference path" in the name? This way, we get stability based on graph location without having to use the path location in the name.

@michael-0acf4
Copy link
Contributor Author

What was that proposal of yours to avoid stability issues around the numbers? The current names would change when you expose new functions that are not placed at the end.

Edit: right, using the reference count? Wouldn't that lead to duplicate names?

No it's not using the ref count, it's just returning the type name and if it's already used it will increase the suffix by 1 (so it's increasing if a dup is encountered). This seemed more natural than keeping the ids.

Also, I was curious of the count at which a scalar type was duplicated on our snapshots.

@michael-0acf4
Copy link
Contributor Author

How about, alternatively, we use "short hashes of the first reference path" in the name? This way, we get stability based on graph location without having to use the path location in the name.

Like taking the first n chars of each path segment? Or directly hash it...?

@Yohe-Am
Copy link
Contributor

Yohe-Am commented Jan 9, 2025

Ah, I see what you mean by dup count. It's stability is much better, but all the numbers will change if you add a new func that has uses the same "kind" before the others, the old types of the same kind will have their reference indices incremented.

Like taking the first n chars of each path segment? Or directly hash it...?

Directly hashing it. So you'd have string_a62bef where a62bef would be the hash of the first path we'd discovered the type at. The hash will only change if you add a new function before the others that references that exact type (not "kind") before the others. This makes it as stable as the current main branch impl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants