How to use the @magento/peregrine.useApolloContext function in @magento/peregrine

To help you get started, we’ve selected a few @magento/peregrine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adobe / aem-core-cif-components / ui.apps / src / main / javascript / minicart / src / utils / useMutation.js View on Github external
export const useMutation = (mutation, toRefetch) => {
    const apolloClient = useApolloContext();
    const [queryResultState, queryResultApi] = useQueryResult();
    const { receiveResponse } = queryResultApi;

    /**
     * A callback function that performs a query either as an effect or in response to user interaction.
     *
     * @function API.runQuery
     *
     * @param {DocumentNode} query A GraphQL document
     */
    const runMutation = useCallback(
        async ({ variables }) => {
            let payload;
            try {
                console.log(`Do we have variables? `, variables);
                payload = await apolloClient.mutate({ mutation, variables, refetchQueries: toRefetch });