GraphQL协议
- schema即协议,通俗的来讲,可以类似rest openapi schema
- 客户端以及服务端根据schema通信,根据其定义进行校验约束
- 客户端在schema范围内可以自由获取(query)或者更新(mutation)需要的字段
1 | type Hero { |
需要关注的GraphQL Java概念
- DataFetcher 定义具体数据获取方式,可以是db,memory
- DataLoader 用于 1对n,数据关联查询,解决 n+1 查询问题,用key做了一些cache
对应SpringBoot以及Netflix DGS 封装映射
Fetcher
- @Controller @MutationMapping @QueryMapping
- @DgsComponent @DgsMutation @DgsQuery
Loader
- @SchemaMapping @BatchMapping
- @DgsData
原生GraphQL SDK demo
1 | private RuntimeWiring buildWiring(){ |
1 |
|
Reference
- https://github.com/eugenp/tutorials/tree/master/spring-boot-modules/spring-boot-graphql
- https://www.baeldung.com/spring-graphql
- https://www.baeldung.com/spring-graphql-error-handling
- https://github.com/danvega/graphql-paging
- https://github.com/danvega/graphql-store
- https://github.com/graphql-java/tutorials
- https://tech.meituan.com/2021/05/06/bff-graphql.html
- https://netflix.github.io/dgs/getting-started/*