Skip to content

Commit

Permalink
Merge pull request #1282 from chuanqisun/master
Browse files Browse the repository at this point in the history
  • Loading branch information
sunli829 committed May 5, 2023
2 parents c7d2826 + 2046041 commit fe693d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/en/src/dataloader.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ impl User {
}
```

To expose `UserNameLoader` in the `ctx`, you have to register it with the schema, along with a task spawner, e.g. `async_std::task::spawn`:

```rust,ignore
let schema = Schema::build(QueryRoot, EmptyMutation, EmptySubscription)
.data(DataLoader::new(
UserNameLoader,
async_std::task::spawn, // or `tokio::spawn`
))
.finish();
```

In the end, only two SQLs are needed to query the results we want!

```sql
Expand Down
11 changes: 11 additions & 0 deletions docs/zh-CN/src/dataloader.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ impl User {
}
```

要在 `ctx` 中获取 `UserNameLoader`,您必须将其和任务生成器(例如 `async_std::task::spawn`)注册到 `Schema` 中:

```rust,ignore
let schema = Schema::build(QueryRoot, EmptyMutation, EmptySubscription)
.data(DataLoader::new(
UserNameLoader,
async_std::task::spawn, // 或者 `tokio::spawn`
))
.finish();
```

最终只需要两个查询语句,就查询出了我们想要的结果!

```sql
Expand Down

0 comments on commit fe693d4

Please sign in to comment.