A complete and simple GraphQL api implementation

A complete and simple GraphQL api implementation

Hi

In the way of the moderns web apps, one of the most awesome new technologies is QraphQL. GraphQL is awesome because resolve the problem of the RESTFul APIs, the endpoints, that is staying in the past.

The new way to do right things in cloud services follow the QL trends. But what's the great points about QL?

  1. Only the content that is needed by the website is returned
  2. This reduces network traffic compared to a REST approach where mostly too much content is returned (overfetching).
  3. All content for a single webpage can be fetched in one request
  4. Making many API requests to fetch all content for a webpage (underfetching) can lead to performance issues. With GraphQL there is only one request.
  5. Less coordination needed between API and website parties
  6. Exposing more content is a few line of configuration code. The new content is immediately accessible by the website. There is no need for communication on which endpoints data needs to be made available.
  7. Total flexibility for API consumers
  8. Different API consumers have different needs. To make content fetching performant, one might build specialised REST endpoints that return exactly the information a API consumer needs which is costly and brittle.
  9. GraphQL Schema
  10. The schema enables tools to do auto-complete and detect on compile time that a request will work (or not). This reduced development time.
  11. Documentation is embedded in the schema
  12. This is nice because the documentation is right in the editor instead of on a separate documentation website like with REST.
  13. Versioning is not an issue
  14. Deprecating fields and providing an update path is easy. So much easier than providing proper versioning in REST.
  15. Smart client-side caching
  16. User-specific content makes it hard to achieve a good cache-hit rate using HTTP cache methods. Based on the GraphQL schema there can be intelligent client side caching which knows what data is available and what needs to be fetched.
  17. Efficient changes
  18. GraphQL also supports changes, they are called mutations. Mutations can be batched (multiple mutations) and even fetch content in the same request.

So, I've implemented a little and complete QL example and you can try it on: https://github.com/alvaro-paco/GraphQl-Pdv-Example

要查看或添加评论,请登录

社区洞察

其他会员也浏览了