A facade allows to adapt a type to its context

In this article we will work on this representation of the Person type.


Declaration of a facade

To describe a facade, akwatype first allows you to select the type on which the facade applies (with key word on) and indicate the fields you wish to retain. All fields that are not listed by name in the facade are ignored.

facade PersonDTO on Person{
    name
    age
    address
}

If a field is of complex type (Address for example) all its structure is taken over


Use of aliases

If you need to rename a field you can use alias by prefixing the field name with its alias followed by :

facade PersonDTO on Person{
    firstName:name
    age
    mainAddress:address
}

 

Declaration of an "inline" facade

As we have seen, when a field is of complex type, all its structure is taken over.

However, most of the time, we also want to apply a facade to this complex field.

Akwatype allows to define a facade directly on the field, by following the name of the field by the description of the facade to be applied between braces. In-line facades can be nested.

facade PersonDTO on Person{
    firstName:name
    age
    mainAddress:address{
        city
        country {
            code
        }
    }
}

Reuse of facades

The "inline" facades can be practical but they do not allow to reuse the descriptions made.

Another method, to apply a facade on a field, is to make the name of this field follow by :: then by the name of an existing facade on the type of the field. For example a facade on the type Address on the address field.

 

facade PersonDTO on Person{
    firstName:name
    age
    mainAddress:address::AddressDTO
}

facade AddressDTO on Address{ city country::CountryDTO }
facade CountryDTO on Country{ code }