'Apollo / GraphQL Mutation Won't Connect Models
I have a simple One-To-Many relationship set up between Driver
models and WeeklyReport
models. This relationship, however, perpetually refuses to exist or even get acknowledged, as no errors are hit and the new Model created, the WeeklyReport
returns in full, minus any connection to a driver. The mutation file looks like this...
import db from "../../../../utils/generatePrisma.js";
import checkOwnerAuth from "../../../../utils/checkAuthorization/check-owner-auth.js";
import checkManagerAuth from "../../../../utils/checkAuthorization/check-manager-auth.js";
export default {
Mutation: {
scorecardToolCreateWeeklyReports: async (_, {
token,
dspId,
role,
transporterId,
date,
feedbackStatus,
feedbackMessage,
feedbackMessageSent,
rank,
tier,
delivered,
keyFocusArea,
fico,
seatbeltOffRate,
speedingEventRate,
distractionsRate,
followingDistanceRate,
signalViolationsRate,
deliveryCompletionRate,
deliveredAndRecieved,
photoOnDelivery,
attendedDeliveryAccuracy,
dnr,
podOpps,
ccOpps
}, context) => {
let owner;
let manager;
if (role === 'OWNER') {
owner = await checkOwnerAuth(token)
}
if (role === 'MANAGER') {
manager = await checkManagerAuth(token)
}
const foundDriver = await db.driver.findFirst({
where: {
transporterId: transporterId,
dspId: dspId
}
})
if (!foundDriver) {
throw new Error('Driver does not exist')
}
try {
const weeklyReport = await db.weeklyReport.create({
data: {
driver: {
connect: {
id: foundDriver.id
}
},
date: date,
feedbackStatus: feedbackStatus,
feedbackMessage: feedbackMessage,
feedbackMessageSent: feedbackMessageSent,
rank: rank,
tier: tier,
delivered: delivered,
keyFocusArea: keyFocusArea,
fico: fico,
seatbeltOffRate: seatbeltOffRate,
speedingEventRate: speedingEventRate,
distractionsRate: distractionsRate,
followingDistanceRate: followingDistanceRate,
signalViolationsRate: signalViolationsRate,
deliveryCompletionRate: deliveryCompletionRate,
deliveredAndRecieved: deliveredAndRecieved,
photoOnDelivery: photoOnDelivery,
attendedDeliveryAccuracy: attendedDeliveryAccuracy,
dnr: dnr,
podOpps: podOpps,
ccOpps: ccOpps
}
})
return await db.weeklyReport.findUnique({
where: {
id: weeklyReport.id
},
include: {
driver: true
}
})
} catch (error) {
console.log("\n---------------\n Error in WeeklyReportCreation")
console.log(error)
throw new Error(error)
}
}
}
}
And I get a return printed out on the frontend, (as well as if I Inspect
and switch to the network tabs and look at the response from the mutation attempt) That return, like I said, is exactly what its supposed to be, minus the driver. Take a look at the response:
{rank: 1, firstname: 'Kenneth', lastname: 'Williford', employeeId: 'AZRK4Y9JFA263', tier: 'Fantastic', …}
adminEmail: "TESTOWNER"
attendedDeliveryAccuracy: 0
ccOpps: 0
delivered: 116
deliveredAndRecieved: "100"
deliveryCompletionRate: "100"
distractionsRate: "Coming Soon"
dnr: 0
email: "otV7CTbbEw5X"
employeeId: "AZRK4Y9JFA263"
fico: "850"
firstname: "Kenneth"
followingDistanceRate: "Coming Soon"
keyFocusArea: "null"
lastname: "Williford"
password: "AZRK4Y9JFA263"
phoneNumber: "null"
photoOnDelivery: "100"
podOpps: 54
rank: 1
seatbeltOffRate: "Coming Soon"
signalViolationsRate: "Coming Soon"
speedingEventRate: "Coming Soon"
tier: "Fantastic"
}
And before you ask "is it finding the driver?" Yes, it's finding the driver. I cannot use console.logs to prove this since it is deployed on CI/CD EC2 from AWS, thus the console it would log to is on AWS's side of things, but using throw new Error (foundDriver.id)
I was able to see that the driver IS in fact being found.
So, I sincerely have no idea what's going on here, as everything looks exactly how it's supposed to. Does anyone see what the issue could be?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|