From f4aa2668a8e693a96506e7a3ccd0180649dc4310 Mon Sep 17 00:00:00 2001 From: sunli Date: Wed, 22 Apr 2020 10:30:21 +0800 Subject: [PATCH] Add some docs --- README.md | 2 +- docs/zh-CN/src/apollo_federation.md | 40 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8bf4c98c..376e7bc0 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ -`async-graphql` is a GraphQL server library that fully supports async/await and is easy to use. +`Async-graphql` is a GraphQL server library that fully supports async/await and is easy to use. It supports all of the GraphQL specifications and is easy to integrate into existing web servers. diff --git a/docs/zh-CN/src/apollo_federation.md b/docs/zh-CN/src/apollo_federation.md index 06b441bb..927360bc 100644 --- a/docs/zh-CN/src/apollo_federation.md +++ b/docs/zh-CN/src/apollo_federation.md @@ -1 +1,41 @@ # Apollo Federation集成 + +`Apollo Federation`是一个`GraphQL`网关,它可以组合多个GraphQL服务,允许每服务仅实现它负责的那一部分数据,参考[官方文档](https://www.apollographql.com/docs/apollo-server/federation/introduction)。 + +`Async-graphql`可以完全支持`Apollo Federation`的所有功能,但需要对`Schema`定义做一些小小的改造。 + +- `async_graphql::Object`和`async_graphql::Interface`的`extends`属性声明这个类别是一个已有类型的扩充。 + +- 字段的`external`属性声明这个字段定义来自其它服务。 + +- 字段的`provides`属性用于要求网关提供的字段集。 + +- 字段的`provides`属性表示解析该字段值需要依赖该类型的字段集。 + +类型的key属性定义稍有不同,必须在查询根类型上定义一个实体查找函数。 + +类似下面这样 + +```rust +struct Query; + +#[Object] +impl Query { + #[entity] + async fn find_user_by_id(&self, id: ID) -> User { + User { id } + } +} +``` + +这相当于 + +```graphql +type User @key(id: ID!) { + id: ID!, +} +``` + +你必须在这个实体查找函数中根据key来创建对应的对象。 + +完整的例子请参考https://github.com/sunli829/async-graphql-examples/tree/master/federation