Prisma1: Prisma client mutations do not get executed without await or callback

Created on 9 Jan 2019  路  5Comments  路  Source: prisma/prisma1

The bug
Prisma client mutations do not get executed without await or callback.

To Reproduce
Using Prisma JS client:
index.js

const { prisma } = require('./generated/prisma')

const foo = async () => {
  await prisma.updateManyLoans({ data: { isCanceled: true } }) // Gets executed
}
foo()

const bar = () => {
  prisma.updateManyLoans({ data: { isCanceled: true } }) // Doesn't get executed
}
bar()

prisma.updateManyLoans({ data: { isCanceled: true } }).then() // Gets executed
prisma.updateManyLoans({ data: { isCanceled: true } }) // Doesn't get executed

Expected behavior
Expect prisma.updateManyPosts({ data: { isCanceled: true } }) to get executed and be reflected in the DB.

Versions:

  • OS: Windows 10
  • prisma CLI: prisma/1.19.0 (windows-x64) node-v8.11.2
  • Prisma Server: 1.19.0
  • graphql-cli: 2.16.5

    • prisma-client-lib: 1.19.0

Additional context
I need to create a job task to be executed every day, for that I want to run a prisma client mutation.

kinquestion areclienjs areclient

All 5 comments

Hey @Elfayer ,

is it a problem for you that you need to await it? The prisma client is intentionally designed in a lazy way so that queries are executed only when the developer consumes the promise.

Hi @mavilein , thanks for the quick answer!

I was hopping to be able to run multiple parallel commands at the same time. It is also confusing that nothing happens, since it is described to work as a Promise.
Is this meant to avoid consistency issues?

It is mostly used to allow for chaining in queries, e.g. the example from the homepage:

await prisma
  .post({ id: "cjl4srkaqqxa30b46pqcyzpyo" })
  .comments()

This results in one query being sent to the backend. If the evaluation would be eager we would have two roundtrips to the server.

@Elfayer you can execute multiple queries in parallel like this in JS/TS:

const q1 = prisma.posts() // no await here
const q2 = prisma.users() // no await here
const [posts, users] = await Promise.all([q1, q2])

Does that answer your question?

@mavilein @schickling Makes sense thanks to you two! ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sorenbs picture sorenbs  路  3Comments

sedubois picture sedubois  路  3Comments

jannone picture jannone  路  3Comments

thomaswright picture thomaswright  路  3Comments

marktani picture marktani  路  3Comments