让我们考虑使用以下数据模型与MongoDB
连接的prisma实例
type User {
id: ID! @id
name: String! @unique
balances: [Balance!]!
}
type Balance @embedded {
currency: String!
platform: String!
amount: Float!
}
我们也有这样的单个用户
{
name: 'user',
balances: [
{
platform: "OnlineWallet",
currency: "BTC",
amount: 1
},
{
platform: "PaperWallet",
currency: "BTC",
amount: 1
},
{
platform: "PaperWallet",
currency: "ETH",
amount: 1
}
]
}
我想删除平台PaperWallet
和货币BTC
的余额,但同时保留其他两个余额。
但是我的查询:
mutation {
updateUser(
data: { balances: { deleteMany: { AND: [{ platform: "PaperWallet" }, { currency: "BTC" }] } } }
where: { name: "user" }
) {
id
name
balances {
platform
currency
amount
}
}
}
删除两个给予答复的钱包
{
"data": {
"updateUser": {
"id": "5d3ed575be077700070f3c6d",
"name": "user",
"balances": [
{
"platform": "OnlineWallet",
"currency": "BTC",
"amount": 1
}
]
}
}
}
所有
PaperWallet
已删除
我第二次尝试的方法
mutation {
updateUser(
data: { balances: { deleteMany: { platform: "PaperWallet", currency: "BTC" } } }
where: { name: "user" }
) {
id
name
balances {
platform
currency
amount
}
}
}
除其他余额外还导致其他余额的领导者
{
"data": {
"updateUser": {
"id": "5d3ed60abe077700070f3c71",
"name": "user",
"balances": [
{
"platform": "PaperWallet",
"currency": "ETH",
"amount": 1
}
]
}
}
}
所有
BTC
已删除
我也尝试OR
怀疑它应该删除所有余额
mutation {
updateUser(
data: { balances: { deleteMany: { OR: [ {platform: "PaperWallet"}, {currency: "BTC"} ] } } }
where: { name: "user" }
) {
id
name
balances {
platform
currency
amount
}
}
}
结果也与预期不同
{
"data": {
"updateUser": null
},
"errors": [
{
"message": "Whoops. Looks like an internal server error. Search your server logs for request ID: local:cjyob5al900k00788500ibq44",
"path": [
"updateUser"
],
"locations": [
{
"line": 2,
"column": 3
}
],
"requestId": "local:cjyob5al900k00788500ibq44"
}
]
}
未处理的日志异常:
{
"key":"error/unhandled",
"requestId":"local:cjyob5al900k00788500ibq44",
"clientId":"default_default",
"payload":{
"exception":"java.lang.RuntimeException: These should not be hit ",
"query":"mutation {\n updateUser(data: {balances: {deleteMany: {OR: [{platform: \"PaperWallet\"}, {currency: \"BTC\"}]}}}, where: {name: \"user\"}) {\n id\n name\n balances {\n platform\n currency\n amount\n }\n }\n}\n",
"variables":"{}",
"code":"0",
"stack_trace":"scala.sys.package$.error(package.scala:26)\\n com.prisma.api.connector.mongo.database.FilterConditionBuilder.buildConditionForFilter(FilterConditionBuilder.scala:36)\\n com.prisma.api.connector.mongo.database.FilterConditionBuilder.$anonfun$nonEmptyConditions$1(FilterConditionBuilder.scala:80)\\n scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:233)\\n scala.collection.Iterator.foreach(Iterator.scala:937)\\n scala.collection.Iterator.foreach$(Iterator.scala:937)\\n scala.collection.AbstractIterator.foreach(Iterator.scala:1425)\\n scala.collection.IterableLike.foreach(IterableLike.scala:70)\\n scala.collection.IterableLike.foreach$(IterableLike.scala:69)\\n scala.collection.AbstractIterable.foreach(Iterable.scala:54)\\n scala.collection.TraversableLike.map(TraversableLike.scala:233)\\n scala.collection.TraversableLike.map$(TraversableLike.scala:226)\\n scala.collection.AbstractTraversable.map(Traversable.scala:104)\\n com.prisma.api.connector.mongo.database.FilterConditionBuilder.nonEmptyConditions(FilterConditionBuilder.scala:80)\\n com.prisma.api.connector.mongo.database.FilterConditionBuilder.buildConditionForFilter(FilterConditionBuilder.scala:35)\\n com.prisma.api.connector.mongo.database.FilterConditionBuilder.buildConditionForScalarFilter(FilterConditionBuilder.scala:26)\\n com.prisma.api.connector.mongo.database.FilterConditionBuilder.buildConditionForScalarFilter$(FilterConditionBuilder.scala:25)\\n com.prisma.api.connector.mongo.database.MongoActionsBuilder.buildConditionForScalarFilter(MongoActionsBuilder.scala:18)\\n com.prisma.api.connector.mongo.database.NodeActions$$anonfun$6.applyOrElse(NodeActions.scala:264)\\n com.prisma.api.connector.mongo.database.NodeActions$$anonfun$6.applyOrElse(NodeActions.scala:262)\\n scala.PartialFunction.$anonfun$runWith$1$adapted(PartialFunction.scala:141)\\n scala.collection.Iterator.foreach(Iterator.scala:937)\\n scala.collection.Iterator.foreach$(Iterator.scala:937)\\n scala.collection.AbstractIterator.foreach(Iterator.scala:1425)\\n scala.collection.IterableLike.foreach(IterableLike.scala:70)\\n scala.collection.IterableLike.foreach$(IterableLike.scala:69)\\n scala.collection.AbstractIterable.foreach(Iterable.scala:54)\\n scala.collection.TraversableLike.collect(TraversableLike.scala:270)\\n scala.collection.TraversableLike.collect$(TraversableLike.scala:268)\\n scala.collection.AbstractTraversable.collect(Traversable.scala:104)\\n com.prisma.api.connector.mongo.database.NodeActions.embeddedNestedDeleteManyDocsAndResults(NodeActions.scala:262)\\n com.prisma.api.connector.mongo.database.NodeActions.$anonfun$updateHelper$1(NodeActions.scala:64)\\n com.prisma.api.connector.mongo.extensions.SlickReplacement$.run(SlickReplacement.scala:19)\\n com.prisma.api.connector.mongo.extensions.SlickReplacement$.run(SlickReplacement.scala:29)\\n com.prisma.api.connector.mongo.extensions.SlickReplacement$.$anonfun$run$1(SlickReplacement.scala:24)\\n scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:303)\\n scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)\\n scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)\\n java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)\\n java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)\\n java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)\\n java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)\\n java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)",
"message":"These should not be hit "
}
}
版本:
具有可重现此行为的源代码的存储库
https://github.com/gustawdaniel/javascript_training/tree/master/prisma/hello-world
可能引发异常的文件的源代码