Kohki Shiga
09/14/2020, 1:49 AMThe change you are trying to make would violate the required relation 'DrinkingLocationsToUser' between the `DrinkingLocations` and `User` models.
The entities are as follows:
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
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:
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 thisRyan
09/14/2020, 7:57 AMKohki Shiga
09/14/2020, 7:58 AM