question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when using Photon to create new item with 2 relation connections

See original GitHub issue

To give a bit of background, this is my data model (or at least part of it):

model User {
  // Meta
  id        String   @default(cuid()) @id @unique
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  // Data
  auth0Id        String          @unique
  email          String          @unique
  firstName      String
  lastName       String
  picture        String
  private        Boolean         @default(false)
  userChallenges UserChallenge[] @relation(onDelete: CASCADE)
  following      Following[]     @relation(name: "UserFollowing", onDelete: CASCADE)
  followedBy     Following[]     @relation(name: "UserFollowed", onDelete: CASCADE)
  comments       Comment[]       @relation(onDelete: CASCADE)
  likes          Like[]          @relation(onDelete: CASCADE)
  tags           Tag[]           @relation(onDelete: CASCADE)
  challenging    Challenging[]   @relation(name: "UserChallenging", onDelete: CASCADE)
  challengedBy   Challenging[]   @relation(name: "UserChallenged", onDelete: CASCADE)
  reports        Flag[]          @relation(onDelete: NONE)
}

model Update {
  // Meta
  id        String   @default(cuid()) @id @unique
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  //  Data
  text          String
  type          UpdateType
  secret        String        @unique
  userChallenge UserChallenge @relation(onDelete: NONE)
  comments      Comment[]     @relation(onDelete: CASCADE)
  likes         Like[]        @relation(onDelete: CASCADE)
  tags          Tag[]         @relation(onDelete: CASCADE)
}

model Like {
  // Meta
  id        String   @default(cuid()) @id @unique
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  // Data
  user   User   @relation(onDelete: NONE)
  update Update @relation(onDelete: NONE)
}

The resolver I have trouble with is the one where I am trying to create a like:

export const likeMutations = extendType({
  type: 'Mutation',
  definition(t) {
    t.field('createLike', {
      type: 'Like',
      args: { updateId: idArg({ required: true }) },
      async resolve(parent, args, context) {
        return context.photon.likes.create({
          data: {
            update: { connect: { id: args.updateId } },
            user: { connect: { id: context.userId } },
          },
        });
      },
    });
  },
});

Whenever I try to call that resolver with the right arguments, I get the following error:

Screenshot 2019-08-04 at 11 31 09

I tried the same thing with creating a comment and I got the same error.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mavileincommented, Aug 13, 2019

Fixed with: https://github.com/prisma/prisma/commit/b0df6842459f018a2178867ec728399cfcf47b25

The fix is available in a few minutes on alpha.

Just FYI: The bug had nothing to do with relations. The problem were the fields createdAt and updatedAt in this case. The arguments for the scalar fields in createLike were empty. We had a line that was not setting the default values for those fields in this case. Then the insert failed because the columns have to be not null.

0reactions
reinvanimschootcommented, Aug 22, 2019

I had to do the migration again as well, it works now, though I found another bug. But this can be closed!

Read more comments on GitHub >

github_iconTop Results From Across the Web

MonoBehaviourPunCallbacks ... - Photon Unity Networking 2
This callback is only called on the client which created a room (see OpCreateRoom). As any client might close (or drop connection) anytime,...
Read more >
Connection Problems with Photon 2 in Unity - Info Gamer Hub
This problem is not caused by any errors. Instead, it is only due to both games connecting to different region servers.
Read more >
[HELP] Photon Pun 2 Hashtable Error - Multiplayer - Unity Forum
Server: 'ns.exitgames.com' ErrorCode: 10054 SocketErrorCode: ConnectionReset Message: An existing connection was forcibly closed by the remote ...
Read more >
Connection Problems with PUN 2 in Unity - YouTube
For this video, I will explain how to fix the problem in Photon where your editor and your standalone create new rooms instead...
Read more >
Spring boot JPA OneToMany relationship - create related ...
I found the fix. Remove cascade attribute for Job member variable of Person Entity. JPA is combining both and also reusing the existing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found