Client-Directed Queries
Applications that rely on SOAP or REST architectures have proven themselves over the last decade. However, there are limits to these architectures. The Client-Directed Query approach overcomes these limitations and enables a generic connection of different clients to the same backend. The clients can be defined at any time, several data queries can be combined into a single one and, on top of that, the client itself decides on the granularity of the data.
Applications that rely on SOAP or REST architectures have proven themselves over the last decade. However, there are limits to these architectures. The Client-Directed Query approach overcomes these limitations and enables a generic connection of different clients to the same backend. The clients can be defined at any time, several data queries can be combined into a single one and, on top of that, the client itself decides on the granularity of the data.
What are client-directed queries?
The principle of client-directed queries is to give one or more clients as much control as possible over the content and granularity of their data required and supplied by the backend. This allows a large number of individual REST, SOAP or RPC interfaces to be replaced by a single, centralised interface for all client applications.
The added value: each client application can define its individual data queries using a DSL-based query language and always retrieve the data required in the current application context. Rigid, predefined interfaces thus give way to a flexible and expressive query interface. These data queries promote the Uniform Access Principle, enabling read and write access via the same attribute notation. Example: Instead of using getSurname for reading and setSurname for writing, simply surname is used in both cases.
GraphQL, Falcor and the various SQL dialects for relational database systems, among others, are based on the principle of client-directed queries.
DSL is the abbreviation for Domain-Specific Language. In contrast to universal languages, domain-specific languages are tailored to a specific technical domain and can only be used within this domain. They focus on the interaction between humans and machines.
SQL stands for Structured Query Language and describes a structured language for read and change access to databases. In addition to the SQL standard, there are various dialects that sometimes take into account product-specific and sometimes implementation-specific details.
The Uniform Access Principle goes back to Bertrand Meyer, who formulated the following definition in his work Object-Oriented Software Construction.
Buzzword-Factor
Client-directed queries promise a concrete solution to the inherent problems of the REST architecture style.
Entry hurdle
Client-directed queries can be easily implemented for the first time in the course of smaller projects. The start-up phase is rather short.
Added value
The resulting interface solutions are very flexible, easy to maintain and involve significantly lower costs.
What is GraphQL?
GraphQL is a data query and manipulation language that implements the principle of client-directed queries. Data can be read, written and subscribed to. The client always decides which data it wants to retrieve, to what extent and in which structure. In this way, GraphQL avoids the overfetching, underfetching and chunking that otherwise occurs with REST.
The principle of GraphQL is very simple. The client formulates the desired data structure in JSON. The server analyses the data structure, compiles the data and also returns it as a JSON structure. This allows the client to define complex, hierarchical structures as well as impose restrictions on the selection of fields and data.
Facebook initially developed GraphQL internally for its own applications in 2012 and made it available as open source in 2015. In addition to a reference implementation for JavaScript, there are others for all major languages, such as Java, C# and Ruby. Facebook has since handed over the GraphQL project to the GraphQL Foundation and ultimately to the Linux Foundation.
TechDOSSIER: Advanced Machine Learning
Our TechDOSSIERs summarise important topics and trends in a product-neutral and compact way. We summarise complex aspects of technology according to the information needs of executives and managers by explicitly highlighting certain characteristics of the topics and trends. Among other things, we provide definitions, describe the potential, name external influencing factors, set out an application scenario and explain the barriers to entry.
What advantages does GraphQL offer over RPC, SOAP or REST?
SOAP and REST can basically be understood as variants of the classic RPC based on web technologies. The basic concept is therefore a function call. SOAP focusses on the provision of services, while REST focuses on resources. While REST does not specify a particular format for the representation of the data, SOAP requires the use of XML. This is because SOAP is ultimately a further development of XMLRPC. The data transmitted via SOAP is therefore often unnecessarily bloated. With REST, the fundamentally leaner JSON has prevailed for data representation.
GraphQL is based on a query concept. As with SOAP and REST, HTTP is also used as the transport path, and the queries and responses are represented in JSON. This still results in a noticeable overhead, but this can be compensated for by skilful formulation of the queries.
The real-time communication framework GraphQL IO goes one step further. It uses web sockets as the transport path and either JSON or CBOR for data representation. The overhead therefore always remains low. Another advantage: GraphQL IO is real-time capable. Clients can subscribe to certain data and are informed by the server as soon as the data changes. The GraphQL IO framework independently handles the notification of the change and the subsequent retrieval of the data. This minimises the effort involved in developing a real-time client.
GraphQL and GraphQL IO are based on the principle of client-directed queries. They therefore differ significantly from the established variants SOAP and REST, both in terms of focus and overhead. Only GraphQL IO is fully real-time capable.
GraphQL-IO is based on GraphQL and is a framework for real-time network communication in JavaScript. The client side runs either under Node.js or in the browser, the server side only under Node.js. The framework is licensed under the MIT licence.
While GraphQL is only a formal language specification and GraphQL.js is a reference implementation of a corresponding runtime, GraphQL-IO is a GraphQL-based, all-in-one network communication solution for client and server.
It integrates the necessary third-party libraries, provides a convenient and flexible API and, in particular, supports real-time updates of GraphQL queries (also known as GraphQL subscriptions) via a powerful, framed and optionally compressed websocket channel.
How can you imagine real-time updating with GraphQL?
What do I need to use GraphQL in Java projects?
Although the reference implementation of GraphQL is available for JavaScript, GraphQL can be used with any language. Java, which is still widely used in the field of operational information systems, is no exception.
Especially in conjunction with Spring Boot, GraphQL can be added to applications in no time at all. In addition, relevant open source libraries are available for Spring Boot, further reducing development time.
The GraphQL Java library is available under the MIT licence on Github. Its implementation is based on the existing JavaScript reference implementation.
The GraphQL Java Tools library supports the Contract First development approach when implementing the API. The API is not defined programmatically, but described using the GraphQL Schema Language.
The GraphQL Java Servlet library enables access to the GraphQL APIs via HTTP. Queries can be transferred via GET with URL parameters or via a POST in the body. The servlet also works as a standalone servlet or as a servlet listener.
What training and further education opportunities are available for GraphQL?
We offer you both planned and tried-and-tested training courses on web services, client-directed queries and GraphQL, as well as individual coaching sessions and workshops tailored to your needs. Get in touch with us!
- One-day training course in German
- Web services basics
- REST standards
- REST deployment
- SOAP standards
- SOAP deployment
- Enterprise Service Bus
- One-day training course in German
- Basics of GraphQL
- Queries, mutations, resolvers
- Schema Discription Language
- Subscriptions
- Real-time communication
- Java & Javascript implementation
- One-day or multi-day training in German
- RPC and query-based web services
- Methods, techniques, tools
- Patterns, architecture, best practices
- Implementation and operation
- Requirements and needs analysis
- Knowledge multiplication