3.1 The Query Service Model
The Query Service meta-model reveals what informa-
tion is needed to conduct CRUD operations on REST-
ful APIs. To establish this meta-model, the client-side
applications and how they handle their data transfer
with the backend were inspected and evaluated. For
example, in Angular
3
we evaluated the current imple-
mentation of the Angular services.
2 shows the meta-model of the Query Service. A
Query Service contains general information about the
server such as a name, description, author and on
which port it should run for the development process.
It also needs to specify a data model, this is the data
model of the frontend, and it is used by the Query
Service to define the return type of a resolver or an ar-
gument type passed to the resolver function. Hence, it
is needed to know how to provide the data to the view.
A Query Service also consists of several resolvers.
Those resolvers are functions which represent the API
for the client by providing CRUD operations on data
to the client. It can be called by the name of the re-
solver and by potentially passing arguments along.
Since the Query Service just manages access to sev-
eral different RESTful Web services a resolver also
needs an API request. This is the part which handles
the communication with a RESTful API to provide
the data transfer supplied by this resolver. The API
request contains the URL of the API and may include
several query- and URI parameters. Each API request
also contains an HTTP Method (GET, POST, PUT,
etc.). Where applicable, header parameters, a body
and/or authentication need to be passed along with
the request.
4 MODEL-DRIVEN APPROACH
FOR GENERATING RESTFUL
WEB SERVICES
To develop the RESTful Web Services, we propose a
semi-automatic process which is driven by the meta-
model described in 3. 3 gives an overview of the pro-
cess which is accomplished with the help of a web
application. It is composed of four steps: (1) con-
struction of the model by the developer using the UI
of the application resulting in a platform independent
model (PIM), (2) transformation of the PIM to a plat-
form specific model (PSM) to support the format of
a GraphQL
4
server, (3) code generation based on the
PSM, and (4)manual code refinement by the developer.
3
https://angular.io
4
http://graphql.org
4.1 Design Decisions
To provide a practical implementation of the architec-
ture presented in 3, we provide a semi-automatically
generated Query Service. We chose to implement it
as a GraphQL server. GraphQL is a query language
for APIs. This allows the client to send much more
powerful queries to the API then it would be possi-
ble with an ordinary REST request. The client can
exactly specify the structure of a data entity it wants
to be returned. Like this, the client does not have to
transform the data if it wants a different structure as
designed by the API. This also leads to less complex-
ity in the client.
As the server we chose NodeJS
5
since it is conve-
nient to configure and ensures a lightweight server. To
make this GraphQL-based server, we used Apollo
6
,
which is a framework for implementing a GraphQL
server.
4.2 Model Construction
The generation process of the Query Service starts
with the model construction. This is a semi-automatic
step since the developer has to specify the model ac-
cording to his/her needs. The model construction is
supported by the interface of the web application. The
meta-model from 3 is represented as a user form in
the interface which then has to be filled out by the de-
veloper. For example, the developer has to define the
data model and the different APIs to access to resolve
the data. After the developer finished constructing an
instance of the model it is stored in a JSON object for
further process of the application.
4.3 Model Transformer
The next step is a model-to-model transformation
as the PIM has to be transformed to a PSM. This
is just an interim step for the code generation and
therefore invisible to the developer. A PSM is based
on a concrete platform V
¨
olter et al. (2013). In our
case, this platform is the GraphQL server. The
model which was constructed in the previous step,
thus, needs to be transformed to a certain structure
to be able to generate the platform afterward. A
GraphQL server is specified by defining a schema
and resolvers. The GraphQL schema defines which
queries can be sent by the client, hence, describes
the API of the GraphQL server. It specifies the data
types, functions to get data (so-called queries) and
functions to alter data (so-called mutations). The
5
https://nodejs.org/
6
https://www.apollodata.com
MODELSWARD 2018 - 6th International Conference on Model-Driven Engineering and Software Development
482