scalagraphqlsangria

How to perform Mutation in sangria-graphql?


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?


Solution

  • 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:

    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