I am trying to fetch data from hygraph by this way
export const getCategories = async () => {
const { categories } = await hygraph.request(
`
query GetGategories {
categories {
name
coverImg {
url
}
posts {
titile
slug
coverPhoto {
url
}
}
}
}
`
)
return categories
}
and i call this function from a component using useEffect hook by this way
useEffect(() => {
getCategories().then((result) => {
setRelatedPosts(result);
});
}, []);
but this is showing error this error
i guess we dont call api from a component or is there any bug in my code?