I’m facing an issue with the useQuery hook in Apollo Client when fetching data based on dynamic filters. Here’s the query I’m using:
export const GET_EBOOKS_BY_PARAMS = gql(/* GraphQL */ `
query GetEbooksByParams(
$input: EbookParamsInput!
$pagination: PaginationInput
) {
getEbooksByParams(input: $input, pagination: $pagination) {
_id
nombre
indice {
...IndiceEbookFragmentBasic
}
versiones {
...VersionFragment
}
portada {
...RecursoFragment
}
}
}
`);
And this is the custom hook:
import {
GetEbooksByParamsQuery,
GetEbooksByParamsQueryVariables,
} from '@/graphql/generated/graphql';
import { GET_EBOOKS_BY_PARAMS } from '@/graphql/query/ebook.query';
import { QueryHookOptions, useQuery } from '@apollo/client';
export const useGetEbooksByParams = (
options?: QueryHookOptions<
GetEbooksByParamsQuery,
GetEbooksByParamsQueryVariables
>,
) => {
const { data, ...rest } = useQuery(GET_EBOOKS_BY_PARAMS, options);
return {
ebooks: data?.getEbooksByParams ?? null,
...rest,
};
};
The problem arises when I change the filter, resulting in the following data being logged inside the hook/component:
{
"versiones": [
{
"__typename": "Version",
"_id": "",
"nombre": "PROFESOR",
"status": true
},
{
"__typename": "Version",
"_id": "",
"nombre": "ALUMNO",
"status": false
}
]
}
However, the network response presents different values for the status
field when the main query is executed. It returns a mix of true and false values, which is inconsistent with what’s logged.
I’m using a component for filtering and refetching data, and the filters can be as follows: {semestre: 1}
.
Could you please assist in understanding why the status
field values differ between the useQuery
log and the actual network response after changing filters?
Thank you for your help!