Library for entity store queries. Selection, creation, modification, deletion of entities, work with transactions are supported.
io.extremum:ground-client:<version>
//and auxiliary libraries
io.extremum:extremum-shared-models:<version>
de.cronn:reflection-util:2.14.0
GraphQL Query Builders
name | description |
---|---|
GraphQlQueryBuilder | For entity samples |
GraphQlGetByIdBuilder | To get an entity by ID |
GraphQlUpdateBuilder | To create an entity and edit by ID |
GraphQlRemoveBuilder | To delete an entity by ID |
GraphQlAddToSublistBuilder | To add an entity to a child entity list with an ID |
GraphQlRemoveFromSublistBuilder | To remove an entity from a child entity list with an ID |
Builders provides methods for creating builders
transaction methods are available for all query builders:
name | description |
---|---|
beginTx() | Start Transaction |
inTx(id) | Execute in a specific transaction |
commit(id) | Commit a specific transaction |
GroundApiClient - client for working with the data store. Supports methods with builders in parameters for the possibility of using their functionality and simplified methods with the minimum necessary parameters.
ApiClientHolder
- service for setting up, creating a customer
Response
- response containing the requested value, response status, transaction ID, if any
You must set the following settings in application.properties
apiBaseUrl=
xAppId=
groundUri=
where
apiBaseUrl
- the main url of the application. For example, “https://api.aj84.y.extremum.io”
xAppId
- App ID
groundUri
- uri ground service. For example, "/v3"
:::info
When using the library in the serverless function, the following parameters will be automatically substituted from the environment variables:
apiBaseUrl
xAppId
:::
All models must be inherited from
io.extremum.sharedmodels.basic.BasicModel<ID extends Serializable>
signature | Description | usage example |
---|---|---|
query(builder: GraphQlQueryBuilder): Response<List |
Query by Entity Type | val builder = query() .setOutputFields( field(Zone::getDescription), field(Zone::getUuid) ) client.query<Zone>(builder) |
query( paging: PagingAndSortingRequest = PagingAndSortingRequest(), filter: String? = null, inTxId: TxId? = null ): List |
Simplified query by entity type | client.query<Compensation>(query(filter = "object.function.eq(\"$searchingValue\")")) |
update(builder: GraphQlUpdateBuilder): Response |
Create/modify an entity. Creation occurs if no id is specified in GraphQlUpdateBuilder | |
create(value: T, inTxId: TxId? = null): T | Simplified Entity Creation | client.create(Compensation().apply { function = searchingValue }) |
createEmpty(inTxId: TxId? = null): T | Creating an Empty Entity | client.createEmpty<Zone>() |
getById(builder: GraphQlGetByIdBuilder): Response |
Getting Entity by Id | val builder = getById(id) .setOutputFields( field(Zone::getDescription), field(Zone::getUuid) ) client.getById<Zone>(builder) |
getById(id: Any, inTxId: TxId? = null): T? | Easy to get entity by id with all fields (except fields with lists) | client.getById<Account>(id) |
remove(builder: GraphQlRemoveBuilder): Response |
Deleting an entity. Returns true in response when deleted successfully, false - Entity with specified id not found for deletion. | val builder = remove(id) client.remove(builder) |
remove(id: Any, inTxId: TxId? = null): Boolean | Simplified deletion of entity c id | client.remove(id) |
updateSublist(builder: GraphQlUpdateSublistBuilder): Response<List<R>> | Change child list (passed to GraphQlAddToSublistBuilder or GraphQlRemoveFromSublistBuilder) | val builder = addToSublist( id = createdAccount.uuid, sublistFieldGetter = Account::getChanges, entitiesToAdd = entitiesToAdd ) сlient.updateSublist<Account, Change>(builder) |
In addition to methods for working with transactions in query builders, you can run separate queries only for working with transactions:
signature | Description | usage example |
---|---|---|
beginTx(): Response |
Start Transaction. Returns true in response to a successful operation | client.beginTx() |
commit(txId: TxId): Response |
Execute in a specific transaction | client.commit(txId) |
rollback(txId: TxId): Response |
Commit a specific transaction | client.rollback(txId) |
Or execute a block of specified queries in a transaction:
signature | Description | usage example |
---|---|---|
tx(block: suspend (txId: TxId) -> T): T | Execution of the block action block in the transaction. Before the block, the transaction begins, after - commit/rollback is performed. | val createdZone = client.tx { txId -> // performing the necessary actions within the transaction txId val zone = client.createEmpty<Zone>(txId) client.createEmpty<Compensation>(txId) // return value from block } |
tx(block: suspend (txId: TxId) -> T, onError: suspend () -> Unit = {}): T | Execution of the block action block in the transaction with indication of the onError action block performed in case of block error/transaction operation. | client.tx( block = { txId → // actions within a transaction }, onError = { // actions performed in case of an error in the main block } ) |