Skip to content
This repository has been archived by the owner on May 16, 2019. It is now read-only.

Operations

Paweł Gutkowski edited this page Jul 28, 2017 · 5 revisions

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 2 properties:

name description
name name of operation
resolver Resolver

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). Operations can be deprecated

Subscription is not supported yet.

query { }

query allows to create resolver for query operation.

Example

data class Hero(val name : String, val age : Int)
query("hero"){
    description = "returns formatted name of R2-D2"
    resolver { -> Hero("R2-D2", 40) } 
}

This example adds query with name hero, which returns new instance of R2-D2 Hero. It can be queried with selection set for name or age, example query: {hero{name, age}}

mutation { }

mutation allows to create resolver for mutation operation.

Example

mutation("createHero"){
    description = "Creates hero with specified name"
    resolver { name : String -> name } 
}

This example adds mutation with name createHero, which returns passed name.

subscription { }

subscription operations are not supported yet.