Hi, I have a quick question about updating records...
# orm-help
d
Hi, I have a quick question about updating records sequentially. Let's say I have a record that's related to another record as a child record of a parent record. How do I get the ID of the parent to feed into the child relationally in a single query?
r
@Daniel Sieradski ๐Ÿ‘‹ Nested writes should help you in this case.
d
I'm trying that but I keep getting errors like this:
Copy code
PrismaClientValidationError:
Invalid `prisma.utterances.create()` invocation:

{
  data: {
    uid: 'eebb1696-667f-4523-9e72-7356a6df367c',
    name: 'hello',
    description: 'say hello!',
    keyword: 'hello',
    variants: [
      {
        uid: 'f8f0243b-3a49-4deb-b041-ebefecafe407',
        dialog: 'Hello and welcome to Zombo com',
        variant_type: 1,
        parent: 0,
        priority: 0,
        status: 'LIVE',
        variant_channels: [
          {
            channel_id: 1
          }
        ]
      }
    ]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  }
}

Argument variants: Got invalid value
[
  {
    uid: 'f8f0243b-3a49-4deb-b041-ebefecafe407',
    dialog: 'Hello and welcome to Zombo com',
    variant_type: 1,
    parent: 0,
    priority: 0,
    status: 'LIVE',
    variant_channels: [
      {
        channel_id: 1
      }
    ]
  }
]
on prisma.createOneutterances. Provided List<Json>, expected variantsCreateNestedManyWithoutUtterancesInput:
type variantsCreateNestedManyWithoutUtterancesInput {
  create?: variantsCreateWithoutUtterancesInput | List<variantsCreateWithoutUtterancesInput> | variantsUncheckedCreateWithoutUtterancesInput | List<variantsUncheckedCreateWithoutUtterancesInput>
  connectOrCreate?: variantsCreateOrConnectWithoutUtterancesInput | List<variantsCreateOrConnectWithoutUtterancesInput>
  createMany?: variantsCreateManyUtterancesInputEnvelope
  connect?: variantsWhereUniqueInput | List<variantsWhereUniqueInput>
}


    at Document.validate (/home/dsieradski/code/dialog-api-mock-server/node_modules/@prisma/client/runtime/index.js:33530:19)
    at NewPrismaClient._executeRequest (/home/dsieradski/code/dialog-api-mock-server/node_modules/@prisma/client/runtime/index.js:35637:17)
    at consumer (/home/dsieradski/code/dialog-api-mock-server/node_modules/@prisma/client/runtime/index.js:35582:23)
    at /home/dsieradski/code/dialog-api-mock-server/node_modules/@prisma/client/runtime/index.js:35584:47
    at AsyncResource.runInAsyncScope (async_hooks.js:197:9)
    at NewPrismaClient._request (/home/dsieradski/code/dialog-api-mock-server/node_modules/@prisma/client/runtime/index.js:35584:25)
    at Object.then (/home/dsieradski/code/dialog-api-mock-server/node_modules/@prisma/client/runtime/index.js:35692:39)
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  clientVersion: '2.27.0'
}
That's a nested record
my query:
Copy code
mutation CreateUtterance($utterance: UtteranceIn) {
  utteranceCreate(utterance: $utterance) {
    uid
    name
    description
    keyword
    variants {
      uid
      dialog
      priority
      status
      parent
      variant_channels {
        channel_id
      }
    }
  }
}
vars:
Copy code
{
  "utterance": {
    "uid": "eebb1696-667f-4523-9e72-7356a6df367c",
    "name": "hello",
    "description": "say hello!",
    "keyword": "hello",
    "variants": [
      {
        "uid": "f8f0243b-3a49-4deb-b041-ebefecafe407",
        "dialog": "Hello and welcome to Zombo com",
        "variant_type": 1,
        "priority": 0,
        "status": "LIVE",
        "parent": 0,
        "variant_channels": {
          "channel_id": 1
        }
      }
    ]
  }
}
r
Youโ€™re missing
create
if you want to create a variant. Check the doc I sent you above for the example.
d
does create need to be in the graphql query?
or in the prisma?
this is my mutation
Copy code
import { utterances as Utterance, PrismaClient, Prisma } from '.prisma/client/index.d'

export default (prisma: PrismaClient) =>
  async (parent: undefined, args: Prisma.utterancesCreateInput): Promise<Utterance | null | undefined> => {
    try {
      const { utterance } = args
      return await prisma.utterances.create({ data: utterance })
    } catch (error) {
      console.error(error)
    }
  }
are you saying i need to add a second create for the subclass into the statement
r
Could you share your models from
schema.prisma
then I can point you to the exact query to be made.
d
actually i think i figured it out
thanks for your help
r
@Daniel Sieradski ๐Ÿ‘‹ We also have introduced long running transactions that you can check out for dependent writes ๐Ÿ™‚ https://github.com/prisma/prisma/releases/tag/2.29.0