MODULES > REST API and GraphQL > Querying/Creating/Updating/Deleting with GraphQL
6. Querying/Creating/Updating/Deleting with GraphQL
The REST API based on GraphQL allows to perform all actions of the CRUD:
Create
Read
Update
Delete
This mechanism allows to perform a various kind of action into the repository. Read actions are performed with the keyword "query" in GraphQL whereas Read/Update/Delete actions are performed with the "mutation" keyword.
All the examples below are performed with the ITPM schema.
6.1. Basic queries
6.1.1. Getting an object with its attributes
The following query returns the name of the applications:
Query
Result
query app {
application {
name
}
}
 
 
 
 
{
"data": {
"application": [
{ "name": "AA" },
{ "name": "Account Management" }
]
}
}
6.1.2. Getting an object with its relations
The following query returns the applications and their related business process:
Query
Result
query {
application {
id
name
businessProcess {
id
name
}
}
}
 
 
 
 
 
 
 
 
 
{
"data": {
"application": [
{
"id": "snf5hRn0U91K",
"name": "AA",
"businessProcess": []
},
{
"id": "IubjeRlyFfT1",
"name": "Account Management",
"businessProcess": [
{
"id": "12qog2pV99fG",
"name": "Financial Reporting"
}
]
},
6.2. Basic mutations
6.2.1. Creating an object
The following mutation creates an application. If creation is successful the result returnes the created object.
Query
Result
mutation {
createApplication(application:{
name:"new application"
}) {
id
name
}
}
 
{
"data": {
"createApplication": {
"id": "x2wrAYDkWP8H",
"name": "new application"
}
}
}
6.2.2. Creating an object with a relationship
The following mutation creates an application and links it to an existing business process. If creation is successful the result returnes the created object.
Query
Result
mutation {
createApplication(application : {
name: "new app 3"
businessProcess: {
action:ADD
list:[{id:"39cXIxu2HHrI"}]
}
}) {
id
name
businessProcess {
id
name
}
}
}
{
"data": {
"createApplication": {
"id": "Q2wradDkWbGH",
"name": "new app 3",
"businessProcess": [
{
"id": "39cXIxu2HHrI",
"name": "Accounting"
}
]
}
}
}
 
 
 
6.2.3. Updating an object
The following mutation updates an existing application. If update is successful the result returnes the updated object.
Query
Result
mutation {
updateApplication(id:"IubjeRlyFfT1" application:{
cloudComputing:Cloud_IaaS
}) {
id
cloudComputing
}
}
 
{
"data": {
"updateApplication": {
"id": "IubjeRlyFfT1",
"cloudComputing": "Cloud_IaaS"
}
}
}
 
 
6.2.4. Deleting an object
The following mutation deletes an existing application. If delete is successful the result returnes the number of deleted objects.
Query
Result
mutation {
deleteApplication (id:"snf5hRn0U91K" cascade:false) {
deletedCount
}
}
 
 
{
"data": {
"deleteApplication": {
"deletedCount": 1
}
}
}