What is GraphQL?
GraphQL is a query language for your API (Application Programming Interface) that allows you to request specific data from a server and receive exactly what you need, rather than getting a fixed set of data. It was developed by Facebook and released as open source in 2015.
One of the main benefits of GraphQL is that it allows you to declaratively specify the data you need, rather than specifying how to get the data (as you would with a REST API). This allows you to make more efficient requests, as you only receive the data you need and nothing more.
In addition, GraphQL has a strong type system that allows you to specify the structure of the data you are requesting, which helps to prevent errors and makes it easier to evolve your API over time.
GraphQL is often used as an alternative to REST APIs, as it can be more flexible and efficient. It is particularly well-suited for modern, data-driven applications that require complex, real-time interactions between the client and server.
Key differences between REST and GraphQL
There are a few key differences between REST and GraphQL:
Data fetching: In REST, the server determines what data to send back to the client, based on the endpoint that the client requests. With GraphQL, the client can specify exactly what data it needs, and the server responds with exactly that data. This allows the client to make more efficient requests, as it only receives the data it needs and nothing more.
Endpoints: In REST, each resource is represented by a unique URL, and the client retrieves or manipulates the resource by making requests to that URL. In GraphQL, there is only one endpoint, and the client makes a request by sending a GraphQL query to that endpoint.
Structure of the API: In REST, the structure of the API is fixed and determined by the server. The client has to adapt to the structure of the API in order to make requests and receive data. In GraphQL, the client can specify the structure of the data it needs, and the server responds with data in that structure. This allows the client to evolve its data needs over time without having to change the structure of the API.
Strong type system: GraphQL has a strong type system that allows you to specify the structure of the data you are requesting, which helps to prevent errors and makes it easier to evolve your API over time. REST does not have a strong type system, which can make it more prone to errors and harder to evolve the API.
Usage
The GraphQL can be used to query the data (Queries) but also to update information (Mutations) in our application. To test the GraphQL, you can use tools like:
GraphQL Playground: is a graphical, interactive, in-browser GraphQL IDE But you can also use tools like Postman and SoapUI. Note that not all objects are available yet for querying and/or mutations. Below, we have created a list of the available objects.
Available objects for Queries
- Companies
- Cost Centers
- Hour Schedules
- Persons
- Addresses
- Attachments
- Business Contact Data
- Civil States
- Employee Contracts
- Employee Trainings
- Expense Requests
- Family Member
- Feedbacks
- Job Histories
- Leave Counters
- Leave Requests
- Organizational Role Members
- Personal Contact Data
- Salary Information
- Competences
- Jobs
- Leave Rules
- Leave Types
- Locations
- Organizational Roles
- Organizational Role Competences
- Organizational Units
- Planning Calendar
- Training
- Training Sessions
- Users
- User Authentications
- User Groups
Available objects for Mutations
- Business Contact Data
- Expense Request
- Feedback
- Hour Schedule
- Leave Counters
- Leave Request
- Leave Rules
- Leave Types
- Planning Calendar
- Training Participant
- User
- User Authentication
- User Groups