Introduction on GraphQL

GraphQL provides a flexible and efficient approach to data fetching. As a query language for APIs, it enables clients to request specific data, reducing over-fetching and under-fetching issues. Unlike traditional REST and SOAP APIs, GraphQL allows access to multiple resources through a single endpoint, enhancing efficiency and performance.

alt text

Documentation

GraphQL API documentation is directly integrated with the API's schema. This ensures that the documentation remains accurate and up-to-date. Use GraphQL's introspection feature to query the schema itself, providing detailed information about available types, fields, and operations.

Deprecation is essential in GraphQL since it lacks versioning like REST. Parts of the Schema can be marked as deprecated, and this status will be automatically reflected in the documentation. GraphQL tooling, including client libraries, will notify developers when they are using deprecated tools.

GraphQL Basics

Everything available through a GraphQL API is typed and included in its schema. Use the schema to build precise queries that fetch only the needed data, solving the problem of over-fetching. This approach also clarifies which fields each service is using, aiding in the continuous improvement of the API. Access the entire schema in the side-menu or view a visual representation using Chargetrip Voyager.

The schema helps validate queries before execution, eliminating unwelcome surprises such as unavailable data or erroneous structures.

All GraphQL requests are sent to the same endpoint, allowing the retrieval of all necessary data in a single request. Use GraphQL features like connections, variables, and aliases to make queries highly efficient and retrieve data across various resource types in one request.

Primary operations

GraphQL supports three primary operations: queries, mutations, and subscriptions. Queries retrieve data, mutations modify data, and subscriptions provide real-time updates. Examples of each operation are provided below.

Below are examples of each one.