Buenas aquí mi solución al reto:
La query para un solo avo:
const query2 = `
query Avo($avoId: ID!) {
avo(id: $avoId) {
id
name
price
image
attributes {
description
shape
hardiness
taste
}
}
}
`
Luego el custom hook quedaría de esta manera:
const useAvocados = () => {
return useQuery(['avocado', avoId], async () => {
const response = await requester.post<{ data: TProduct[] }>('/graphql', {
query: query2,
variables: { avoId },
})
return response.data.data
})
}
Osea le agregamos al método post de axios, la query nueva, y otro atributo “variables” con un objeto con atributo id de nombre igual al especificado en la query de graphql.
Saludos!!!
Want to see more contributions, questions and answers from the community?