-
Notifications
You must be signed in to change notification settings - Fork 81
Operations
There are three types of operations that GraphQL models:
- query – a read‐only fetch.
- mutation – a write followed by a fetch.
- subscription – a long‐lived request that fetches data in response to source events.
Each operation is represented by an operation name and a selection set.
In KGraphQL, operation is declared in SchemaBuilder
block. Every operation has 3 properties:
name | description |
---|---|
name | name of operation |
description | description of operation displayed in documentation |
resolver | function executed to resolve operation result |
Selection set is automatically created based on resolver return type. By default, selection set for specific class contains all its member properties (without extension properties), but it can be customized (TBD Type wiki page).
Subscription is not supported yet.
query
allows to create resolver for query operation. it supports fields:
Example
query("hero"){
description = "returns formatted name of R2-D2"
resolver { -> "R2-D2" }
}
This example adds query with name hero
, which returns string: R2-D2
mutation
allows to create resolver for mutation operation. it supports fields:
Example
mutation("createHero"){
description = "Creates hero with specified name"
resolver { name : String -> name }
}
This example adds mutation with name createHero
, which returns passed name.