I'm working on a react app. I want to use this query :
const Newss = gql`
query getNewssData {
newss(ordered: true) {
id
title
content
event{
id
title
}
}
}
`;
executed by this react code :
<Query query={Newss}>
{({ loading, error, data }) => {
if (loading) return LoadingNews();
if (error) return `Error! ${error.message}`;
return data.newss.map(news => newssToRender(news));
}}
</Query>
But it return Error! because there are some news without event. How to permit to do this query sometimes even if event could be null ?
Thank you very much for your help !
Izaya
Note :
function newssToRender(news) {
if (news.event === null) {
return newssToRenderWithoutEvent(news);
}
return (
<div>
<News
title={news.title}
content={news.content}
eventid={news.event.id}
eventTitle={news.event.title}
pictureSrc={news.picture}
/>
</div>
);
}