2

Currently, I'm learning sangria-graphql from here. However, I could not find any documentation for Mutation (Add, Update, Delete). Also, google won't help me much. So, can you guys provide me with any good resources?

Ra Ka
  • 2,995
  • 3
  • 23
  • 31

1 Answers1

6

Mutations in GraphQL are modeled as an object type, just like the Query type. GraphQL schema has 3 top-level entry points which are modeled as object types:

  • Query type - the root for the queries
  • Mutation type - the root for the mutations
  • Subscription type - the root for the subscriptions

When you created the scheme, you can provide all 3 of them:

Schema(QueryType, Some(MutationType), Some(SubscriptionType))

Otherwise, mutations work very similar to queries, except that the mutation top-level fields are executed sequentially (guaranteed not to execute in parallel).

For further info and examples, I would recommend you to check sangria-subscriptions-example which demonstrates mutation and subscriptions in addition to normal queries. I would suggest you to start at schema definition:

https://github.com/sangria-graphql/sangria-subscriptions-example/blob/master/src/main/scala/schema.scala#L87

tenshi
  • 26,268
  • 8
  • 76
  • 90
  • I found the example in the following link much more useful than the one quoted in this answer: https://www.howtographql.com/graphql-scala/8-mutations/ – Tobi Sep 28 '20 at 07:21