This Example shows mostly all base capabilities of using the following set of modules:
- Tarantool GraphQLIDE 0.0.21+
- Tarantool GraphQLAPI 0.0.9+
- Tarantool GraphQLAPI Helpers 0.0.9+ - this particular module available only in Tarantool Enterprise SDK bundle
To build application, start it and setup topology:
# install dependencies
./deps.sh
# or if you've got Tarantool Enterprise
TARANTOOL_ENTERPRISE=TARANTOOL_ENTERPRISE=$HOME/tarantool-enterprise ./deps.sh
# build application
cartridge build
# start all instances including stateboard
cartridge start -d
# configure replicasets and bootstrap vshard
cartridge replicasets setup --bootstrap-vshard
# configure failover
cartridge failover setup --file failover.yml
# fire migrations
cartridge admin --run-dir `pwd`/tmp/run/ --name cartridge-full --instance router migrations
# fill test data
cartridge admin --run-dir `pwd`/tmp/run/ --name cartridge-full --instance router fill
or use bash-scripts:
# install dependencies
./deps.sh
# build and start application
./scripts/start.sh
# bootstrap cluster and failover
./scripts/bootstrap.sh
# create spaces (fire migrations) and fill test data
./scripts/fill.sh
Now you can visit http://localhost:8081 and see your application's Admin Web UI.
Note, that application stateboard is always started by default.
See .cartridge.yml
file to change this behavior.
Application entry point is init.lua
file.
It configures Cartridge, initializes admin functions and exposes metrics endpoints.
Before requiring cartridge
module package_compat.cfg()
is called.
It configures package search path to correctly start application on production
(e.g. using systemd
).
Application has two simple roles:
Both api
and storage
roles exposes /metrics
endpoints:
curl localhost:8081/metrics
Custom user api
role uses the following Cartridge roles:
- cartridge.roles.vshard-router
- cartridge.roles.crud-router
- cartridge.roles.graphqlide
- cartridge.roles.graphqlapi
Custom user storage
role uses the following roles:
- cartridge.roles.vshard-storage
- cartridge.roles.crud-storage
Fragments - separate parts of GraphQL schemas located in ./fragments/*.lua
:
entity.lua
- fragment adds 3 custom queries toDefault
schema:entity_get_by_id
;entity_get_by_name
;entity_get_all
;
helpers.lua
- fragment adds 3 schemas:Data
- CRUD GraphQL API generated based on the current cluster data schema;Service
- ;Spaces
;
logging.lua
- fragment adds custom logging for GraphQL API requests;owner.lua
- fragment adds 3 custom queries toDefault
schema:owner_get_by_id
;owner_get_by_username
;owner_get_all
.
After starting application on router
- http://localhost:8081 instance GraphQL IDE will be available:
The following schemes are available in this demo application:
Admin
- Tarantool Cartridge admin GraphQL API;Data
- CRUD GraphQL API generated based on the current cluster data schema;Default
- custom GraphQL API generated from./fragments/*.lua
;Service
- a set of service queries and mutations;Spaces
- a set of queries and mutations to manipulate spaces.
Switch to Default
schema in GraphQL IDE and make the following requests:
query {
owner_get_all {
bucket_id
owner_surname
owner_name
owner_age
owner_username
owner_id
}
}
query {
owner_get_by_id(owner_id: 1) {
owner_surname
owner_id
owner_age
owner_name
owner_username
}
}
query {
owner_get_by_username(owner_username: "rapid") {
owner_surname
owner_id
owner_username
owner_age
owner_name
entities {
entity_description
entity_owner_id
entity_name
entity_id
}
}
}
query{
entity_get_all {
bucket_id
entity_description
entity_owner_id
entity_name
entity_id
}
}
query {
entity_get_by_id(entity_id: 1) {
entity_description
entity_owner_id
entity_name
entity_id
}
}
query{
entity_get_by_name(entity_name: "SSD") {
entity_description
entity_owner_id
entity_name
entity_id
}
}
For other schemas all available queries and mutations may be found in GraphiQL Docs.