ntention:
trying to query from apollo client based on dynamic id. Have successfully checked in server provided interface which is working… and trying to do same from the client.
From the doc it looks like i need to use variables which i did.
Problem:
query using variables looks good but i am getting undefined in client.
Query which is working in graphql API:
query abc {
getCategoryProduct(id:"NzI1NDc1MTM1") {
id
title
description
favorited
published
price_per_day
price_per_week
price_per_month
price_per_weekend
picture
pictures {
id
url
}
createdAt
updatedAt
}
}
Problematic code in client
const GETDETAILS = gql`
query abc($id: String!) {
getCategoryProduct(id: $id) {
id
title
description
favorited
published
price_per_day
price_per_week
price_per_month
price_per_weekend
picture
pictures {
id
url
}
createdAt
updatedAt
}
}
`;
const DetailScreen = () => {
const { loading, error, data } = useQuery(GETDETAILS, {
variables: { id: "NzI1NDc1MTM1" },
});
useEffect(() => {
if (loading == false) {
console.log("=====data=====", data); // DATA IS EMPTY DO NOT NOT WHY??
}
}, [data]);