1

Please for example how to use JSON type

generator prisma_client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

model t {
  id  Int   @default(autoincrement()) @id
  val Json?
}

I need code of mutation.

I used answer from

GraphQL Mutation with JSON Patch

enabled crud by

import { use } from 'nexus'
import { prisma } from 'nexus-plugin-prisma'

use(prisma({features:{crud:true}}))

and send this mutation:

mutation {
  createOnet(data: {
    val: "{ \"name\": \"michael\" }"
  }) {
    id
    val
  }
}

But I have response:

{
  "error": [
    {
      "message": "Expected type Json, found \"{ \\\"name\\\": \\\"michael\\\" }\"; Cannot read property 'forEach' of undefined",
      "locations": [
        {
          "line": 2,
          "column": 26
        }
      ]
    }
  ]
}
Daniel
  • 7,684
  • 7
  • 52
  • 76

1 Answers1

1

It should be as follows:

mutation {
  createOnet(data: {
    val: { name: "michael" }
  }) {
    id
    val
  }
}

No escaping is required as Nexus automatically handles that for you.

Ryan
  • 5,229
  • 1
  • 20
  • 31