【发布时间】:2021-08-25 19:00:45
【问题描述】:
这可能会有点长,但有很多奇怪的问题需要解释。
我在运行查询时收到的错误消息是:
"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;
}
我绞尽脑汁想的奇怪的事情:
-
此错误不一致,有时会在第一次发生 我查询的关系,有时是第三个,即使它完全相同 查询。
-
这种情况最常发生在人际关系上。如果它是查询中的主要实体, 该错误很少发生。我可以查询一个实体,它会正常工作,但如果我 查询与原始实体不同的实体作为关系,它不会。
-
它似乎破坏了其他查询。我可以运行一个查询,它会工作,然后运行 不同的查询,它不会。反过来做同样的事情, 第一个查询有效,第二个无效。
-
删除一些可嵌入内容将“修复它”,但哪个并不重要 嵌入物。似乎更多的嵌入对象破坏了它, 不一定是任何特定的。 (我有十个不同的嵌入, 一个实体将有多达 8 个嵌入式嵌入式和多达 5 个 相同的嵌入与不同的领域)
-
我尝试了各种不同的方法来编写或初始化嵌入对象:
@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}
感谢您的任何建议
【问题讨论】:
-
也许您使用的是一些过时的版本? github.com/mikro-orm/mikro-orm/issues/1585
-
我也这么认为,但今天早些时候更新了它,仍然遇到同样的问题。对不起,我应该把它包括在内。
标签: mongodb orm graphql mikro-orm