I need to check if a query is null in my graphql resolver. I dont think knowing graphql matters all that much in this question, when I call a dataSource query it has not response and I get an error that an id doesnt exist.
This is the resolver:
Alarm: {
location: async (alarm, args, { dataSources }) => {
const equipment = await dataSources.api.getEquipment(alarm.equipmentId);
console.log(equipment);
// if (equipment !== null) {
// return dataSources.api.getLocation(equipment.locationId);
// } else {
// return null;
// }
},
},
The equipment is just empty when I log it and I get an error in my graphql playground that the equipment doesnt exist for that equipmentId. I think this may be just basic null checking? Please let me know. Also I cant use ?
operator it has to be &&