Jameson Brown
04/27/2019, 12:48 AMconst getPackage = async (parent, args, context) => {
const package = await context.prisma.package({ date: args.date });
// If package exist return it, else, create new package
if (package) {
return package;
} else {
let pack = await context.prisma.createPackage({
date: args.date,
// Request Advice(error here - returns undefined/null)
advice: getAdvice(),
// Request Picture(pending - will use a third party API)
picture: `pic_${args.date}.jpg`,
// defaults empty array
comments: { set: [] }
});
return pack;
}
};
Here is my getAdvice() function from `Helper.js`:
const getAdvice = () => {
// Get advice
axios
.get('<https://api.adviceslip.com/advice>')
.then(res => {
return res.data.slip.advice;
})
.catch(err => {
console.log(err);
return null;
});
};
module.exports = {
getAdvice
};
Here is my error:
{
"data": null,
"errors": [
{
"message": "Variable '$data' expected value of type 'PackageCreateInput!' but got: {\"date\":\"2019-4-24\",\"picture\":\"pic_2019-4-24.jpg\",\"comments\":{\"set\":[]}}. Reason: 'advice' Expected non-null value, found null. (line 1, column 11):\nmutation ($data: PackageCreateInput!) {\n ^",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"getPackage"
]
}
]
}
Any help would be great. I feel like I cant be to far off.bkstorm
04/27/2019, 1:09 AMgetAdvice() return null? If so, the error is expected because advice is required, it can't be null,
- I think it should be
advice: await getAdvice()Jameson Brown
04/27/2019, 2:35 AMgetAdvice() returns null only if there is an error but it should also console log the error, which its not happening. its supposed to return a string which is the advice.Jameson Brown
04/27/2019, 2:36 AMJameson Brown
04/27/2019, 2:37 AMaxios.then it prints out the advice so I know its going to the .then not the .catch so it shouldn’t be returning null.bkstorm
04/27/2019, 2:43 AMgetAdvice(), so the function return nothing. Just add return before axios, then add await before getAdvice()Jameson Brown
04/27/2019, 2:49 AM