Hi. Seems like this channel is the most active. I ...
# orm-help
k
Hi. Seems like this channel is the most active. I have a question regarding graphql nexus and prisma. I'm thinking of using graphql nexus for my personal project. I am stuck with this error for quite a while and I would appreciate if anyone has any idea.
Copy code
The change you are trying to make would violate the required relation 'DrinkingLocationsToUser' between the `DrinkingLocations` and `User` models.
The entities are as follows:
Copy code
model User {
  id               String            @default(cuid()) @id
  username         String
  password         String
  drinkingLocation DrinkingLocations
  profile          Profile
}

model DrinkingLocations {
  id           String   @default(cuid()) @id
  locationName String
  longtitude   Float
  latitude     Float
  createdAt    DateTime @default(now())
  user         User     @relation(fields: [userId], references: [id])
  userId       String
}
For the nexus code I wrote this
Copy code
schema.objectType({
  name: 'User',
  definition(t) {
    t.string('id', { description: 'Id of the user' });
    t.string('username', { description: 'Name of the user' });
    t.string('password', { description: 'Encrypted password' });
    t.field('DrinkingLocations', {
      type: 'DrinkingLocations',
    });
    t.field('Profile', {
      type: 'Profile',
    });
  },
});

schema.objectType({
  name: 'DrinkingLocations',
  definition(t) {
    t.string('id', { description: 'Id of the Drinking location' });
    t.string('locationName', { description: 'Name of the Drinking Location' });
    t.float('longtitude', { description: 'Longtitude of the Drinking ' });
    t.float('latitude', { description: 'Latitude of the Drinking Location' });
    t.date('createdAt', { description: 'Time when the user started drinking' });
    t.string('userId', { description: 'Foreign key to User' });
    t.field('user', {
      type: 'User',
    });
  },
});

schema.mutationType({
  definition(t) {
    t.crud.createOneUser();
    t.crud.createOneDrinkingLocations();
    t.crud.createOneProfile();
  },
});
But when I try to test it out on Graphql Playground I get that error when executing the mutation query:
Copy code
mutation {
  createOneDrinkingLocations(
    data: {
      locationName: "ORCHARD GINZA"
      latitude : 35.672422
      longtitude: 139.763155
      user: {
        connect: {
          id: "ckf0gb3wb0000gfzyoen9psbr"
        }
      }
    }
  ){
    id
    locationName
    latitude
    longtitude
    createdAt
  }
}
I'd really appreciate if someone has any clue about this
r
Replied in your other thread.
k
@Ryan I appreciate it. I'll give it a try with your advice.
👍 1