I have a query that takes an array of ids as parameter. In the array, I can add or remove ids based on the selected documents.
The problem is that it does not launch the query every time the array of id changes but I don't understand why.
I've also tried changing the query options.fetchPolicy
with network-only
and no-cache
but it doesn't work.
This is my query:
const GET_DATA = gql`
query docs($selectedDocs: [ID]) {
docs(selectedDocs: $selectedDocs) {
_id
name
description
}
}
`;
And this is the render function of the component:
render() {
const { selectedDocs } = this.props;
console.log(selectedDocs)
return (
<Query
query={GET_DATA}
variables={{ selectedDocs }}
fetchPolicy="network-only"
// fetchPolicy="no-cache"
notifyOnNetworkStatusChange
>
{({ loading, error, data, refetch, networkStatus }) => {
if (loading) return "Loading...";
if (error) return "Error!";
console.log(data);
return (
<div>
docs list
</div>
)
}}
</Query>
);
}
This is the parent component render method:
render() {
const { selectedDocs } = this.state;
return (
<Docs
selectedDocs={selectedDocs}
/>
)
}