<https://prisma.slack.com/archives/CA491RJH0/p1644...
# orm-help
m
https://prisma.slack.com/archives/CA491RJH0/p1644377499536349 I should be more clear here. I am using prisma-nexus and am working on a new project. Everything seems normal and is similar to an existing code base. When I issue a mutation and implicitly make a connection to the user model it seems to create two records for some reason. I have no clue how to debug this.
n
Hey Michael 👋 Hmm, that sounds strange. did you already try to set the
query
logging option to see what kind of SQL is being generated:
Copy code
const prisma = new PrismaClient({
  log: ['query'],
})
Maybe that would already provide some more insights. Can you maybe share the entire resolver? Also, you could try adding a
console.log
statement in the mutation resolver to see if it somehow gets invoked twice?
m
Thanks for your response, let me gather some details. I added a console.log in the resolver and it was called once. Let me share some schema.
schema.prisma
Copy code
generator client {
  provider        = "prisma-client-js"
  binaryTargets   = ["native"]
  previewFeatures = ["dataProxy"]
}

generator nexusPrisma {
  provider = "nexus-prisma"
}

datasource db {
  provider          = "postgresql"
  url               = env("PG_URL")
  shadowDatabaseUrl = env("SHADOW_PG_URL")
}

model Media {
  id        String    @id @default(cuid())
  createdat DateTime? @default(now())
  updatedat DateTime? @default(now())
  duration  Float?
  loading   Boolean?
  mediaurl  String?
  name      String?
  type      String?
  userId    String
  user      User      @relation(fields: [userId], references: [id])
}

model User {
  id               String    @id @default(cuid())
  createdat        DateTime? @default(now())
  updatedat        DateTime? @default(now())
  confirmed        Boolean?
  email            String?   @unique
  googleuserid     String?   @unique
  name             String?
  password         String?
  picture          String?
  stripecustomerid String?
  stripelifetimeid String?
  admin            Boolean?
  emailPrefs       Json?
  media            Media[]
}
schema.ts
Copy code
export const schema = makeSchema({
  types: [Query, Mutation, UserType, MediaType, AuthenticateUserPayload],
  outputs: {
    schema: __dirname + "/../schema.graphql",
    typegen: __dirname + "/generated/nexus.ts",
  },
  contextType: {
    module: require.resolve("./context"),
    export: "Context",
  },
  sourceTypes: {
    modules: [
      {
        module: "@prisma/client",
        alias: "prisma",
      },
    ],
  },
});
Model Definition
Copy code
import { Media } from "nexus-prisma";
import { objectType } from "nexus";

export const MediaType = objectType({
  name: Media.$name,
  definition(t) {
    t.field(Media.id);
    t.field(Media.type);
    t.field(Media.duration);
    t.field(Media.mediaurl);
    t.field(Media.name);
  },
});
Ill try the logging options, thanks for the suggestion 🙂
It definitely is acting weird, maybe there is something up on my end, here is the log result
Copy code
[1] prisma:query SELECT "public"."User"."id", "public"."User"."createdat", "public"."User"."updatedat", "public"."User"."confirmed", "public"."User"."email", "public"."User"."googleuserid", "public"."User"."name", "public"."User"."password", "public"."User"."picture", "public"."User"."stripecustomerid", "public"."User"."stripelifetimeid", "public"."User"."admin", "public"."User"."emailPrefs" FROM "public"."User" WHERE "public"."User"."id" = $1 LIMIT $2 OFFSET $3
[0] wait  - compiling /_error (client and server)...
[1] prisma:query BEGIN
[0] event - compiled client and server successfully in 93 ms (128 modules)
[1] prisma:query SELECT "public"."User"."id" FROM "public"."User" WHERE "public"."User"."id" = $1 OFFSET $2
[1] prisma:query INSERT INTO "public"."Media" ("id","createdat","updatedat","loading","type","userId") VALUES ($1,$2,$3,$4,$5,$6) RETURNING "public"."Media"."id"
[1] prisma:query SELECT "public"."Media"."id", "public"."Media"."createdat", "public"."Media"."updatedat", "public"."Media"."duration", "public"."Media"."loading", "public"."Media"."mediaurl", "public"."Media"."name", "public"."Media"."type", "public"."Media"."userId" FROM "public"."Media" WHERE "public"."Media"."id" = $1 LIMIT $2 OFFSET $3
[1] prisma:query COMMIT
[1] prisma:query BEGIN
[1] prisma:query SELECT "public"."User"."id" FROM "public"."User" WHERE "public"."User"."id" = $1 OFFSET $2
[1] prisma:query INSERT INTO "public"."Media" ("id","createdat","updatedat","loading","type","userId") VALUES ($1,$2,$3,$4,$5,$6) RETURNING "public"."Media"."id"
[1] prisma:query SELECT "public"."Media"."id", "public"."Media"."createdat", "public"."Media"."updatedat", "public"."Media"."duration", "public"."Media"."loading", "public"."Media"."mediaurl", "public"."Media"."name", "public"."Media"."type", "public"."Media"."userId" FROM "public"."Media" WHERE "public"."Media"."id" = $1 LIMIT $2 OFFSET $3
[1] prisma:query COMMIT
You can see it runs twice ☝️