vuejs / apollo

🚀 Apollo/GraphQL integration for VueJS
http://apollo.vuejs.org
MIT License
6k stars 519 forks source link

useMutation refetchQueries not working when passing a GQL `DocumentNode` #1427

Open xorinzor opened 1 year ago

xorinzor commented 1 year ago

Describe the bug Passing a DocumentNode to refetchQueries as parameter does not trigger an update for the query, whereas passing the name of the query does. As shown here both should be supported.

To Reproduce

Given the example component below: If you call someMutation(), while passing the query name in refetchQueries, the console will show the useQuery triggered message. Whereas when {query: EXAMPLE_QUERY} is passed the console will not show the message.

Example component:

<script>
const EXAMPLE_QUERY = gql`
    query example_query {
        doSomething {
            id
            name
        }
    }`;

export default {
    name: "test",
    mounted() {
        const { onResult } = useQuery(EXAMPLE_QUERY);
        onResult((result) => { 
            console.log("useQuery triggered"); 
        });
    },
    methods: {
        someMutation() {
            const { mutate: mutationCallback } = useMutation(MUTATION_QUERY, {
                refetchQueries: [
                    // THIS DOES NOT WORK
                    // {query: EXAMPLE_QUERY}

                    // THIS WORKS
                    'example_query'
                ]
            });

            mutationCallback().then(() => {
                console.log("mutation executed");
            });
        }
    }
}
</script>

Expected behavior Both the query name and DocumentNode should trigger useQuery to update.

Versions vue: 3.2.41 @vue/apollo-composable: 4.0.0-beta.1 @apollo/client: 3.7.1

xorinzor commented 1 year ago

After some more searching around I found this issue #1326 Are there any plans on updating the dependency version of apollo ?

eirikeis commented 9 months ago

I have the same issue in my react project:

Versions React: 17.0.2 @apollo/client: 3.8.6