I have a simple app built using React + contentful, I'm using apollo as a client. I have a simple array of objects which I retrieve using query and which I'd like to update directly from UI.
this is my query
export const GET_RADIO = gql`
query getUrl {
allContentfulRadioUrl {
nodes {
url
radioName
}
}
}
`;
it works fine.
Then this is my mutation:
export const NEW_RADIO = gql`
mutation addNewRadio($url: String!, $name: String!) {
newRadio(url: $url, radioName: $name) {
allContentfulRadioUrl {
nodes {
url
radioName
}
}
}
}
`;
I'm passing the data to the mutation in this way:
const [addRadio] = useMutation(NEW_RADIO);
const submit = (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
addRadio({
variables: { url: formState.url, radioName: formState.radioName },
});
};
but I keep having errors in the response:
GraphQLError: Variable "$name" of required type "String!" was not provided."
It's my first time using GraohQL and this stack so I'm sure I'm missing something. what do I did wrong?