Skip to content

useMutation refetchQueries not working when passing a GQL DocumentNode #1427

@xorinzor

Description

@xorinzor

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions