Product changes

Robert van Boesschoten

Data API update: Querying

Another update regarding the Data API. This time focussing on querying, error handling and feedback in particular. In the last period, we released the following features:

  • Self-referencing querying
  • Cyclic querying
  • Breadcrumb querying

For each subject we added a short explaining and a nice little example to see it 'in action'.

Self-referencing querying

It is now allowed to query for self-referencing objects.
In the example below we want to query for one employee, and then his manager, both objects are of the same type (Employee), so that constitutes a self-referencing object.

query { 
oneEmployee
{
id
manager
{
id
name
}
}
}

Some strict rules are applied:

  1. It is only possible to query for self-referencing objects starting from the root object (oneEmployee).
  2. It is not possible to do a nested query for self-referencing objects (ex: employee → manager → employee)

 

Cyclic querying

Return cyclic model with cycle check
When a cycle is detected on a query, the error message will now return the type where the first cycle happens, this is useful for users to remove the forbidden cycles on their queries.

query {
  allSong {
    results {
      artist {
        songs {
          name
        }
      }
    }
  }
}
 
now returns:
{  
"errors": [ { "extensions": {
"statusCode": 400,
"type": "Song" }, "message": "Cyclic queries are not supported. First cycle detected on type: Song"
  }
]
}
Breadcrumb querying

Breadcrumb queries allow you to recursively query a model and its parent (of the same model) until the topmost model is reached (and there is no parent anymore). One use case for this feature is breadcrumbs. For example, the query on the left returns the data on the right. Using this data, the final breadcrumb path can be generated.

Example
query { 
recursiveBreadcrumb(base_where: {name: {eq: "Selectie"}}, by: breadcrumb) {
results {
id
name
breadcrumb {
id
name
}
}
}
}
Result
{

"data": {
"recursiveBreadcrumb": {
"results": [
{
"breadcrumb": null,
"id": 1,
"name": "Home"
},
{
"breadcrumb": {
"id": 1,
"name": "Home"
},
"id": 2,
"name": "Teams"
},
{
"breadcrumb": {
"id": 2,
"name": "Teams"
},
"id": 3,
"name": "AZ Onder 19"
},
{
"breadcrumb": {
"id": 3,
"name": "AZ Onder 19"
},
"id": 4,
"name": "Selectie"
}
]
}
}
}

For a full overview of our Data API documentation, please see the Data API section in our Online Academy.

Subscribe to product changes