'How to pass sessionStorage via headers using async await with graphql mutations

I need to pass the sessionStorage dynamically through apollo client via graphql Mutations but we use async/await to use graphql mutations, can anyone help me?



Solution 1:[1]

you can take sessionStorage and assign it to a variable then use Mutations to call the API with the variables passed in

Ex:

const [sendEmail] = useMutation(SEND_EMAIL);

const sendMail = await sendEmail({ variables: { to, subject, body } });

don't forget to import :

import { useMutation } from "@apollo/client";

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HuÂn