We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Ajay Patil • 1 year ago

Really the information and the course you provide is good and helpful, but my question is like if I want to perform mutations in .astro with graphql then how can i do that, i dont want to add any other library like react, vanilla or simple js. I want every thing in .astro only.
Please suggest me the best solution for this, I am trying hard to get the solution

Rob Kendal • 1 year ago

Hey Ajay, thanks for the kind words. In a nutshell, you'd have to first add the mutation to the GraphQL schema (we do this for queries in the section of the article with the title 'Defining the GraphQL schema and creating the GraphQL endpoint'), in this part of the schema:

resolvers: {
Query: {
cart: () => ShoppingCart,
},
Mutations: {
myMutation: () => { // your logic here }
}
},

The mutation would accept parameters, do some work (e.g. updating data in a database) and return, say, a message or updated/added object. Then you'd call the mutation just as you did with the query: call on the Apollo client to do the mutation, passing in whatever values you need.

There's some great documentation and a tutorial over on the GraphQL Yoga docs here -> https://the-guild.dev/graph...