如何在 prisma、graphql nexus 框架中使用 JSON 类型?
How to use JSON type in prisma, graphql nexus framework?
请举个例子如何使用JSON类型
generator prisma_client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model t {
id Int @default(autoincrement()) @id
val Json?
}
我需要突变代码
我使用了来自
的答案
由
启用crud
import { use } from 'nexus'
import { prisma } from 'nexus-plugin-prisma'
use(prisma({features:{crud:true}}))
并发送这个突变:
mutation {
createOnet(data: {
val: "{ \"name\": \"michael\" }"
}) {
id
val
}
}
但我有回复:
{
"error": [
{
"message": "Expected type Json, found \"{ \\"name\\": \\"michael\\" }\"; Cannot read property 'forEach' of undefined",
"locations": [
{
"line": 2,
"column": 26
}
]
}
]
}
应该是这样的:
mutation {
createOnet(data: {
val: { name: "michael" }
}) {
id
val
}
}
不需要转义,因为 Nexus 会自动为您处理。
请举个例子如何使用JSON类型
generator prisma_client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model t {
id Int @default(autoincrement()) @id
val Json?
}
我需要突变代码
我使用了来自
的答案由
启用crud
import { use } from 'nexus'
import { prisma } from 'nexus-plugin-prisma'
use(prisma({features:{crud:true}}))
并发送这个突变:
mutation {
createOnet(data: {
val: "{ \"name\": \"michael\" }"
}) {
id
val
}
}
但我有回复:
{
"error": [
{
"message": "Expected type Json, found \"{ \\"name\\": \\"michael\\" }\"; Cannot read property 'forEach' of undefined",
"locations": [
{
"line": 2,
"column": 26
}
]
}
]
}
应该是这样的:
mutation {
createOnet(data: {
val: { name: "michael" }
}) {
id
val
}
}
不需要转义,因为 Nexus 会自动为您处理。