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 Jun 14, 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 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 { }

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 { }

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.