subsquid / squid-sdk

The main repo of the squid SDK
Apache License 2.0
1.23k stars 151 forks source link

Invalid generation of TypeORM model for entity with nullable relation. #249

Closed deuszx closed 4 months ago

deuszx commented 8 months ago

Describe the bug Given an entity spec:

type Account @entity {
  id: ID!
  nativeTokenBalance: NativeTokenBalance @derivedFrom(field: "account")
}

it generates an object:

import { NativeTokenBalance } from "./nativeTokenBalance.model";

@Entity_()
export class Account {
  constructor(props?: Partial<Account>) {
    Object.assign(this, props);
  }

  /**
   * Account ss58 address
   */
  @PrimaryColumn_()
  id!: string;

}

As you can see, it tries to import NativeTokenBalance but does not use it at all.

To Reproduce Steps to reproduce the behavior:

  1. Modify the schema.graphl
  2. Run npx squid-typeorm-codegen
  3. Check the generated model.

Expected behavior It is expected that the Account model includes the nullable field of nativeTokenBalance.

Environment (please complete the following information):

"dependencies": {
    "@polkadot/util": "^10.1.9",
    "@polkadot/util-crypto": "^10.1.9",
    "@subsquid/archive-registry": "3.3.0",
    "@subsquid/cli": "2.8.6",
    "@subsquid/graphql-server": "4.5.0",
    "@subsquid/ink-abi": "^3.0.2",
    "@subsquid/logger": "^1.3.2",
    "@subsquid/ss58": "^2.0.2",
    "@subsquid/substrate-processor": "8.2.0",
    "@subsquid/typeorm-migration": "1.3.0",
    "@subsquid/typeorm-store": "1.2.6",
    "dotenv": "^16.0.3",
    "pg": "8.8.0",
    "typeorm": "^0.3.11"
  },
  "devDependencies": {
    "@subsquid/ink-typegen": "^3.0.3",
    "@subsquid/substrate-metadata-explorer": "^3.1.2",
    "@subsquid/typeorm-codegen": "^1.3.3",
    "@types/node": "^20.9.0",
    "prettier": "^2.8.8",
    "typescript": "~5.2.2"
  }
belopash commented 8 months ago

https://github.com/subsquid/squid-sdk/pull/190 Should be fixed when this PR will be merged @eldargab

deuszx commented 8 months ago

This PR has been opened since July last year.

belopash commented 8 months ago

I know, just anyone hasn't asked for this before, but if you need it, we can merge it.

deuszx commented 8 months ago

I don't know if that PR solves the issue I'm facing, if it does - great. Also, I'm not very familiar with TypeORM so I was open to some discussions if needed, whether it makes sense at all.