Tutorial - List buildings and rooms
In this tutorial we show how a list of buildings and rooms can be queried through the GraphQL API. In the end we want to retrieve the following information:
- Name of the Client
- Buildings of this client
- Address of each building
- All rooms of each building
- Name of the room
- Dimensions of the room
Step 1: Retrieve name of client#
The starting point through the graph is from the client. We can retrieve the id and the name of the client here:
Request#
query { client { id name }}Response#
{ "data": { "client": { "id": "eba3d7fc-5997-49be-9bfc-9cfdadf7e523", "name": "Crédit Lyonnais" } }}Step 2: Retrieve buildings of the client#
The object client provides a field called buildings that can be used to query the buildings that belong to the client.
We can easily query the buildings by making the following modification to our request.
Request#
query { client { id name buildings(first: 10) { edges { node { name addressStreet addressNumber addressCity addressCountry } } } }}Please note that we must provide a pagination argument (first: 10). The pagination is very flexible and is described in more detail in the pagination section of our documentation.
Response#
We receive a response of two buildings
{ "data": { "client": { "id": "eba3d7fc-5997-49be-9bfc-9cfdadf7e523", "name": "Crédit Lyonnais", "buildings": { "edges": [ { "node": { "name": "Building 1", "addressStreet": "rue de la République", "addressNumber": "41", "addressCity": "Lyon", "addressCountry": "FR" } }, { "node": { "name": "Building 2", "addressStreet": "Muellerstrasse", "addressNumber": "23", "addressCity": "8004", "addressCountry": "CH" } } ] } } }}Step 3: Retrieve room data#
Rooms can be retrieved by using the field rooms from the object building. We can expand the query to retrieve the rooms for each building:
Request#
query { client { id name buildings(first: 10) { edges { node { name addressStreet addressNumber addressCity addressCountry rooms(first: 10) { edges { node { name length width height } } } } } } }}Response#
{ "data": { "client": { "id": "eba3d7fc-5997-49be-9bfc-9cfdadf7e523", "name": "Crédit Lyonnais", "buildings": { "edges": [ { "node": { "name": "Building 1", "addressStreet": "rue de la République", "addressNumber": "41", "addressCity": "Lyon", "addressCountry": "FR", "rooms": { "edges": [ { "node": { "name": "Room Mont Blanc", "length": 7.35, "width": 8.65, "height": 3.6 } } ] } } }, { "node": { "name": "Building 2", "addressStreet": "Muellerstrasse", "addressNumber": "23", "addressCity": "8004", "addressCountry": "CH", "rooms": { "edges": [ { "node": { "name": "Room Alpha", "length": 5, "width": 7, "height": 2.4 } }, { "node": { "name": "Room Beta", "length": 12, "width": 16, "height": 2.4 } } ] } } } ] } } }}Summary#
This tutorials demonstrates the flexibility and ease of use of the AIRICA API. We learned how to traverse the graph of the API and query the required fields.