#Using a form to add content to hygraph

7 messages · Page 1 of 1 (latest)

naive fossil
#

Hi,
I made it work to show content from Hygraph, but how can I add content to hygraph using a form in Astro?
This is my current function, but I don't know how to send the info to Hygraph.

const createCategory = async (title: string, categoryType: string) => {
  const response = await fetch(hygraphEndpoint, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      query: `mutation createCategory($title: String!, $categoryType: String!) {
      createCategory(title: $title, categoryType: $categoryType) {
        id
        title
        categoryType
      }
    }`,
      variables: {
        input: {
          title,
          categoryType,
        },
      },
    }),
  });
  const json = await response.json();
  return json.data.createCategory as Category;
};
silk groveBOT
#

Hi @naive fossil. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Hmm, I don't know enough to give you a confident answer yet. The extracts provided do not contain information on how to send data to Hygraph from an Astro form. I recommend checking the Hygraph documentation or their API reference for more details on how to perform mutations or send data.

For Astro related queries, you can refer to the Astro Documentation (https://docs.astro.build).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@naive fossil kapa.ai is still learning and improving, please let us know how it did by reacting below

naive fossil
#

@silk grove , the docs do not provide an answer here...

silk groveBOT
#

Let me check the knowledge base for you. One moment! :books:

#

I'm sorry for the inconvenience. Unfortunately, the information provided in the extracts does not include details on how to send data to Hygraph from an Astro form.

Your function seems to be correctly structured for a GraphQL mutation, assuming that createCategory is a valid mutation on your Hygraph GraphQL API.

However, without specific documentation or examples from Hygraph, it's hard to provide a definitive answer. I would recommend reaching out to Hygraph support or checking their API documentation for more specific guidance.

For handling forms in Astro, you can refer to the Astro Documentation on building forms (https://docs.astro.build/en/recipes/build-forms/).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: