Meeting Modern Business Needs with GraphQL

参考资料:https://wso2.com/graphql-apis 主要是wso2 关于graphql api 的思考
 

What is GraphQL?

GraphQL is a query language (for APIs) and runtime to satisfy certain queries for your current data. GraphQL offers a comprehensive and comprehensible description of the data in your API, gives users the ability to demand exactly what they need (and nothing more), allows APIs to be easily modified over time, and provides effective development tools [1].

GraphQL is a new, evolving query language developed by Facebook (primarily for the company’s mobile apps). Initially used for web-based applications, it has gained popularity over the past couple of years in the API management domain owing to its unique advantages. The following diagram shows how GraphQL architecture works.

How GraphQL works

Why Use GraphQL?

One major advantage of having GraphQL in place is that application developers will have the opportunity to reduce back and forth communication, which results in reducing network calls. For example, if we take a look at REST API architecture, a client would need to make several calls to get a particular flow of functionality to work.

REST architecture

On the other hand, GraphQL architecture has a completely different flow, where there will only be a single request object passed to a single endpoint. Then, according to the query object, the functions will be called and the response will be returned.

GraphQL architecture

This also makes the lives of application developers easier as they do not have to worry about multiple endpoints, headers, and status codes. Apart from the above advantages, there are some other advantages such as the ease in which to build the solution and being able to have fine-grained or composite responses.

Architecture Styles or Web Patterns of Communication

When it comes to architecture or web patterns that GraphQL can be incorporated into, there are multiple patterns that we can think of. We will discuss two patterns here.

Composite Pattern

The first one is using GraphQL in a composite pattern. For instance, we can have a GraphQL API that will aggregate data from multiple sources, such as a REST API or database stored procedures (T-SQL, PL-SQL), and build the response. The following diagram illustrates this.

Composite Pattern

Façade Pattern

The next pattern would be to use GraphQL in a facade pattern, where it would use a single query to return some data that is needed for a single use case. For example, in an analytics dashboard, there is a widget that will have some data. In order to populate this widget, and if a traditional REST API is used directly, it would need to make several calls. If we can use GraphQL in a facade pattern, this can be achieved using a single call to the GraphQL API, where it will composite all the calls to the REST API that is needed to populate the widget.

Facade Pattern

The composite pattern is also kind of a facade pattern that uses different sources to get the data for a particular use case

In a similar fashion, the GraphQL concept can be added into several architectural and design patterns as per the need.

Conclusion

The right API management solution is critical for business success. When it comes to the selection process, it is vital to take a closer look at the points we have discussed in this article. The solution should be able to expose GraphQL APIs, which adhere to the GraphQL architecture, and also have the same support for traditional REST APIs.

It needs to be highlighted that traditional API management solutions might not be suitable or support the GraphQL style of communication. This is the reason why a modern API management solution such as WSO2 API Manager is required. It treats GraphQL characteristics as first-class features to reap the benefits of API management on top of the advantages that GraphQL provides.

[1] - https://graphql.org/

posted on   荣锋亮  阅读(337)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2018-08-28 prisma 服务器端订阅试用

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示