#GraphQL #APIs #JSON #REST …GraphQL is a query language for API and a server-side runtime for executing queries by using a type system define for any data. GraphQL isn’t tied to any specific database or storage engine and is instead backed by your existing code and data. GraphQL is a new way to think about building and querying APIs. Rather than construct several REST requests to fetch data that you’re interested in, you can often make a single call to fetch the information you need. Client applications who speak GraphQL can query the schema within its capabilities. This approach decouples clients from servers and allows both of them to evolve and scale independently.
- Single-round trip: All data is fetched in a single round-trip vs. multiple-round trips in REST. In our example above, for a REST client to get all products in each category, it would need to first fetch the store’s categories from one API endpoint, and then for each category fetch their products from another API endpoint.
- No over-fetching: A client has full control of fetching only data that it needs vs. in REST API, on the server-side we have to balance between minimizing multiple round-trips (‘n+1’ problem) and over-fetching; we can eliminate ‘n+1’ problem we described above if we make the API that returns store categories, also return all products, but another set of clients that just wants categories of a store will be over-fetching.
- One endpoint to access your data- Single API endpoint to server all data needs
- Retrieve only the data your client needs in a single request (flexibility)
- No need to tailor endpoints for your views
- No versioning