0

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?

1 Answer 1

1

I've just found out that the plugin gatsby-source-contentful is only for querying data and not for mutations, so i was trying to do something impossible

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.