0

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}
        />
    )
}
Marco Daniel
  • 5,467
  • 5
  • 28
  • 36
Stefano
  • 293
  • 1
  • 4
  • 22
  • Can you show the rendering of your parent component and how the `selectedDocs` are passed – Treycos Feb 14 '19 at 09:43
  • I pass the `selectedDocs` as props. I updated the question – Stefano Feb 14 '19 at 09:48
  • Does `console.log(selectedDocs)` fire every time you change the prop? – Rango Feb 14 '19 at 09:49
  • Yes and it has the correct content! – Stefano Feb 14 '19 at 09:52
  • 1
    @Stefano that's good, so then do you see network request in Network panel of DevTools every time you change the prop? (fetchPolicy must stay "network-only") – Rango Feb 14 '19 at 09:54
  • No, the problem is that I don't see the request in Network panel every time I change the prop – Stefano Feb 14 '19 at 10:06
  • Do you see doc list after the first query? or maybe that query hangs with any error? – Rango Feb 14 '19 at 10:16
  • Yes the first time it runs the query exactly. And also other times that changes the prop it runs the query but not every time. – Stefano Feb 14 '19 at 10:18
  • Sorry, my ideas are over. Not sure what the problem can be... If only the client is some way misconfigured. Never had the problem like yours. – Rango Feb 14 '19 at 10:29

0 Answers0