Cannot return null for non-nullable field.
I have a graphQL resolver going through exerciseEntry, and it hits the user ID, where I then try to find the user info if you query it. playgound show the error above.
I've tried the setting the object results to match the user data but it's still not getting returned.
Resolvers:
Query: {
getExerciseEntries: async (root, args, ctx) => {
const entries = await ExerciseEntry.getAll();
console.log(entries);
return entries;
},
getExerciseEntryBy: async (root, args, ctx) => {
const entry = await ExerciseEntry.findBy(args.filter);
return entry;
},
getExerciseEntryById: async (root, args, ctx) => {
const entry = await ExerciseEntry.findById(args.id);
return entry;
}
},
ExerciseEntry: {
user: async (root, args, ctx, info) => {
const user = await Users.findBy({id: root.exercise_entry_user_id})
console.log("seeing users", user)
return user
}
}
TypeDefs:
type Query {
getExerciseEntries: [ExerciseEntry!]!
getExerciseEntryBy(filter: String!): ExerciseEntry!
getExerciseEntryById(id: ID!): ExerciseEntry!
}
type ExerciseEntry {
id: ID!
date: String!
name: String!
caloriesBurned: Int!
user: User!
}
type User {
id: ID!
firstName: String!
lastName: String!
username: String!
email: String!
userType: String!
calorieGoal: Int!
weight: Int
foodEntries: [FoodEntry!]!
exerciseEntries: [ExerciseEntry!]!
}
I expect the query to work where data is shown as such:
{
"data": {
"getExerciseEntries": [
{
"id": "1",
"caloriesBurned": 100
"user": {
"id": 1,
"calorieGoal": 2000
}
}
]
}
}
or something similar.