0

这可能会有点长,但有很多奇怪的问题需要解释。

运行查询时收到的错误消息是:

"stacktrace": [
        "SyntaxError: Arg string terminates parameters early",
        "    at new Function (<anonymous>)",
        "    at Function.createFunction (/Users/zacktidwell/repos/services/graphql/node_modules/@mikro-orm/core/utils/Utils.js:611:52)",
        "    at ObjectHydrator.getEntityHydrator (/Users/zacktidwell/repos/services/graphql/node_modules/@mikro-orm/core/hydration/ObjectHydrator.js:221:40)",
        "    at ObjectHydrator.hydrate (/Users/zacktidwell/repos/services/graphql/node_modules/@mikro-orm/core/hydration/ObjectHydrator.js:23:30)",
        "    at EntityFactory.hydrate (/Users/zacktidwell/repos/services/graphql/node_modules/@mikro-orm/core/entity/EntityFactory.js:82:27)",
        "    at EntityFactory.create (/Users/zacktidwell/repos/services/graphql/node_modules/@mikro-orm/core/entity/EntityFactory.js:36:14)",
        "    at MongoEntityManager.find (/Users/zacktidwell/repos/services/graphql/node_modules/@mikro-orm/core/EntityManager.js:100:52)",
        "    at runMicrotasks (<anonymous>)",
        "    at processTicksAndRejections (internal/process/task_queues.js:94:5)",
        "    at async EntityLoader.populateMany (/Users/zacktidwell/repos/services/graphql/node_modules/@mikro-orm/core/entity/EntityLoader.js:127:22)",
        "    at async EntityLoader.populateField (/Users/zacktidwell/repos/services/graphql/node_modules/@mikro-orm/core/entity/EntityLoader.js:187:9)",
        "    at async EntityLoader.populate (/Users/zacktidwell/repos/services/graphql/node_modules/@mikro-orm/core/entity/EntityLoader.js:37:13)",
        "    at async MongoEntityManager.lockAndPopulate (/Users/zacktidwell/repos/services/graphql/node_modules/@mikro-orm/core/EntityManager.js:630:9)",
        "    at async MongoEntityManager.findOne (/Users/zacktidwell/repos/services/graphql/node_modules/@mikro-orm/core/EntityManager.js:244:9)",
        "    at async queryName
      ]

我 95% 确定这个错误是由我设置的嵌入式对象引起的。这是一个实体的示例:

    export class Properties extends BaseEntity {
        @Embedded({ entity: () => Address, object: true })
        address = new Address();
    
        @Property()
        market: string;
  
        @Embedded({
          entity: () => Metadata,
          array: true,
          object: true,
          nullable: true,
         })
         details: Metadata[] = [];

        @Embedded({
          entity: () => Metadata,
          array: true,
          object: true,
          nullable: true,
         })
         features: Metadata[] = [];

         constructor({address, market }) {
           super();
           this.address = address;
           this.market = market;
         }
      }

以及数组的 Embeddable:

@Embeddable()
export class Metadata {
  @Property()
  id?: string;

  @Property()
  metaKey?: string;

  @Property()
  metaValue?: string;

  @Property()
  createdAt?: string;
}

我绞尽脑汁的奇怪的事情:

  • 这个错误是不一致的,有时它发生在我查询的第一个关系上,有时发生在第三个关系上,即使它是完全相同的查询。

  • 这种情况最常发生在人际关系上。如果它是查询中的主要实体,则很少发生错误。我可以查询一个实体,它会正常工作,但如果我查询另一个实体与原始实体作为关系,它不会。

  • 它似乎打破了其他查询。我可以运行一个查询,它会工作,然后运行一个不同的查询,它不会。反过来做,同样的事情会发生,第一个查询有效,第二个无效。

  • 删除一些可嵌入物将“修复它”,但哪些可嵌入物并不重要。似乎更多的嵌入对象会破坏它,而不一定是任何特定的对象。(我有十个不同的嵌入式,一个实体将有多达八个嵌入式嵌入式和多达五个相同的嵌入式与不同的领域)

  • 我尝试了各种不同的方法来编写或初始化嵌入对象:

       @Embedded({
          entity: () => Metadata,
           array: true,
           object: true,
           nullable: true,
          })
          details = new Metadata();
    
        @Embedded({
          entity: () => Metadata,
           array: true,
           object: true,
           nullable: true,
          })
          details?: Metadata;
    
        @Embedded({
          entity: () => Metadata)
          details?: Metadata[];
    
       // and various combinations of {array: true} and {object: true}
    

感谢您的任何建议

4

1 回答 1

1

对于遇到此问题的任何人来说,这实际上是 Mikro ORM 方面的一个问题。正则表达式拼写错误阻止实体拥有超过 10 个可嵌入项。此后已修复;因此,如果您遇到此问题,请更新您的包裹。

于 2021-08-10T22:59:03.107 回答