'Graphql Mutation error - errors: [{message: "Variable "$firstName" of required type "String!" was not provided.",…}]
I'm trying to mutate a query in Graphql but for some reason, I can't grasp the syntax, I've tried multiple ways but maybe I'm having aye fatigue by this stage, would love if someone could point me in the right direction.
Here's my FormData:
const formData = {
firstName: 'Jonny',
lastName: 'Doe',
IGHandle: {
account: "xxx",
number: 1
},
};
Here's my query:
const REGISTER = gql`
mutation RegisterMutation($firstName: String!, $lastName: String!, $account: String!, $number: Number!) {
register(input: { firstName: $firstName, lastName: $lastName, account: $account, number: $number }) {
firstName,
lastName,
IGHandle: {
account:
number:
}
}
}
`;
Here's my axios request:
axios({
url: 'URL_HERE',
method: 'post',
data: { query: print(REGISTER) },
variables: { ...formData },
headers: { 'Content-Type': 'application/json' },
}).then((result) => {
console.log(result.data);
});
};
Solution 1:[1]
Try removing the input as below
mutation RegisterMutation($firstName: String!, $lastName: String!, $account: String!, $number: Number!) {
register(firstName: $firstName, lastName: $lastName, account: $account, number: $number) {
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 | Sajeetharan |
