GraphQL学习笔记(GraphQL + Spring boot demo) part 1

时间:2023-02-03 10:07:50

GraphQL

GraphQL是什么,我想网上已经有很多介绍的文章了,不了解的可以直接上官网了解一下

http://graphql.org/
https://facebook.github.io/graphql/

这是facebook.github.io上的原话:

This is a Draft RFC Specification for GraphQL, a query language created by Facebook in 2012 for describing the capabilities and requirements of data models for client‐server applications. The development of this standard started in 2015. GraphQL is a new and evolving language and is not complete. Significant enhancement will continue in future editions of this specification.

从介绍可以看出,目前该语言规范还不是非常的完善,不过作为一种新的语言规范,新的实现思路,我们应该辩证地去看待,去学习,未雨绸缪总是好的(当然如果引入机会成本什么的这话题就没完没了了 :P)


GraphQL VS RESTful HTTP API

每个语言或者技术框架都会有它各自的优势,缺点,适用场景,从来就没有什么万金油,网上讨论最多的是GraphQL和RESTful HTTP API,让我们来看看它们各自的优缺点(结果均从互联网搜索学习总结所得):

GraphQL学习笔记(GraphQL + Spring boot demo) part 1

至于在什么时候用哪一种,就需要各位根据具体的项目情况来决定了。


学习demo

以下是这两天在学习Graphql的时候,参考网上的博客文档做的一个结合spring boot的小demo,因为做得很随便,代码写得很粗糙,凑合者看:

https://github.com/NathanPiggy/graphql-demo-with-spring-boot

GraphQL学习笔记(GraphQL + Spring boot demo) part 1


后续需要搞清楚的问题:

  1. 当前端尝试一次过查询两个FieldDefinition的时候,如果其中一个执行超时或者抛出异常了,会不会导致请求失败?
  2. 如果问题1的担忧会发生,如何才能降低FieldDefinition 之间的耦合?

下一步的尝试:
1. 验证问题1.
2. 整合数据库连接到demo

 整合mybatis: http://blog.csdn.net/gaoyib6/article/details/76359390