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

[DRAFT] Fix typescript error avoid ID not matching when use @dbType #2658

Closed
wants to merge 3 commits into from

Conversation

jorgecuesta
Copy link
Contributor

@jorgecuesta jorgecuesta commented Jan 30, 2025

Description

Ensure that IDs match correctly even when data types like BigInt, Int, or Float are used in GraphQL schemas. This prevents mismatches and ensures error handling for invalid ID comparisons.

On Models template there are 2 types:

  1. https://github.com/subquery/subql/blob/main/packages/cli/src/template/model.ts.ejs#L19
  2. https://github.com/subquery/subql/blob/main/packages/cli/src/template/model.ts.ejs#L20

They both Omit the id property, but one leave as string, which if we change the ID with @dbType() maybe get an error?
For sure the getByFields has a typescript error due to that because it expect the T to extend Entity which expect id be an string.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • I have tested locally
  • I have performed a self review of my changes
  • Updated any relevant documentation
  • Linked to any relevant issues
  • I have added tests relevant to my changes
  • Any dependent changes have been merged and published in downstream modules
  • My code is up to date with the base branch
  • I have updated relevant changelogs. We suggest using chan

Sorry, something went wrong.

Ensure that IDs match correctly even when data types like BigInt, Int, or Float are used in GraphQL schemas. This prevents mismatches and ensures error handling for invalid ID comparisons.
The added `@ts-ignore` directive resolves a TypeScript error when calling `store.getByField` in the generated model template.
This mostly to achieve a quick fix which should not be the final solution.
The root problem is that Entity and BaseEntity does not allow other types than string for id, so the Compact and CompactEntity are an Omit from Entity with an override of the id field.
Suppresses a TypeScript warning in the `getByFields` method by adding a `@ts-ignore` comment.
@stwiname stwiname mentioned this pull request Feb 4, 2025
12 tasks
@jorgecuesta
Copy link
Contributor Author

This was fixed with #2662 by @stwiname

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.

None yet

2 participants