Tutorial - Create building
In this tutorial we show how mutations can be used and how a building can be created through the GraphQL API.
Create a building#
Mutations must be used to write data with a GraphQL API. To create a building, we must use the mutation createBuilding.
The mutation expects a data parameter that is a BuildingCreateInput.
The only two required fields are clientId and name. We must provide them in the data argument. Please note that we have to define the return values we want to request.
The mutation createBuilding returns a BuildingUpdateResult that wraps a Building object. We query the field id in this example.
mutation { createBuilding( data: { clientId: "eba3d7fc-5997-49be-9bfc-9cfdadf7e523" name: "Headquarter" } ) { building { id } }}Response#
{ "data": { "createBuilding": { "building": { "id": "140114e1-9777-4e11-91b0-58250bcc64d8" } } }}Update the building#
If we want to update the building, e.g. set an address, we can use the id we got during the previous mutation.
Request#
mutation { updateBuilding( id: "140114e1-9777-4e11-91b0-58250bcc64d8" data: { addressStreet: "Via delle Vigne" addressNumber: "24" addressCity: "Evionnaz" addressZipCode: "1902" addressCountry: "CH" } ) { building { id name addressStreet addressNumber addressCity addressZipCode addressCountry } }}Response#
{ "data": { "updateBuilding": { "building": { "id": "140114e1-9777-4e11-91b0-58250bcc64d8", "name": "Headquarter", "addressStreet": "Via delle Vigne", "addressNumber": "24", "addressCity": "Evionnaz", "addressZipCode": "1902", "addressCountry": "CH" } } }}