Why Use GraphQL?
Reducing Network Round Trips with GraphQL
If you’ve ever used a REST API, you know that making multiple resources request can be time-consuming and bandwidth-intensive. With GraphQL, you can make a single query call that resolves all of the data you need in one go. This not only saves time and bandwidth but also helps to avoid the “waterfall” effect of dependent resources being resolved on previous requests.
Strongly-typed schema for GraphQL
A strongly-typed schema is one in which all the types (such as Boolean, String, Int, Float, ID, Scalar) are specified in the schema. This helps determine the data that is available and the form it exists in. Consequently, it makes GraphQL less error-prone and more validated. It also provides auto-completion for supported IDE/editors.
The Benefits of GraphQL: No Over-Fetching or Under-Fetching
GraphQL is a query language for APIs that was developed by Facebook. It allows developers to fetch only the data that they need, nothing more and nothing less. This solves the issues that arise due to over-fetching and under-fetching. Over-fetching is when you fetch more data than you need, and under-fetching is when you don’t fetch enough data. With GraphQL, developers can specify exactly what they need, so there’s no wasted data or missing data.
Schema Stitching: Combining Schemas
Schema stitching is a way of combining multiple schemas into a single schema. This can be useful in a microservices architecture, where each microservice handles the business logic and data for a specific domain. By stitching together the schemas from each microservice, you can create a single, unified schema that covers all of the domains in your system. This can be helpful when you need to query data from multiple microservices, or when you want to create new data that spans multiple domains. For example, if you have a customer service microservice and an order service microservice, you could use schema stitching to combine their schemas into one customer-order schema. This would allow you to query both customer and order data in one place, and would make it possible to create new orders that include information about the customer (such as their contact information). Schema stitching is not without its challenges, however. One challenge is that the schemas from different microservices may conflict with each other — for example, they may use different names for the same concept. Another challenge is that some data may not fit cleanly into any one schema — for example, an order may have items that come from different product categories. In these cases, careful design is required to ensure that the combined schema makes sense and does not introduce any inconsistencies or errors.
Versioning is not required in GraphQL
You can update the schema without affecting existing queries. This is because GraphQL uses a single endpoint (e.g., api.domain.com/graphql) for all requests and responses. The schema defines the structure of data that can be queried from the endpoint. If you make changes to the schema, existing queries will still work as long as the new schema is backwards-compatible with the old schema
