动手做Get your hands on it
练习跟着课文走 —— 每节课尾都有本课的练习。这一页是全部练习的总库,想集中刷题的时候来。 每个练习都写清了它来自哪一节,卡住了就回去看那一节。Practice follows the lessons — every lesson ends with the exercises for that lesson. This page is the whole library, for when you want to drill in one sitting. Each exercise names the lesson it came from, so you can go back when you stall.
已筛到你正在学的《Federation 考试》。想看全部就点上面的「全部」。Filtered to Federation exam — the course you are on. Use “All” above to see everything.
练习Exercises
筛出 47 个练习(共 148 个) · 第 2 / 4 页。Showing 47 of 148 · page 2 / 4.仓库里没有 Router。你想确认自己的 User.orders在 federation 链路里能被正确调用。最直接的办法?
There is no Router in the repository. You want to confirm your User.orders is called correctly along the federation path. What is the most direct way?
type User @key(fields: "id") 最准确的含义是?
What does type User @key(fields: "id") mean, most precisely?
__resolveReference 返回 { id: user.id }。 那么 User.orders(user, ...) 里的 user上有哪些属性?
__resolveReference returns { id: user.id }. So which properties does user have inside User.orders(user, ...)?
三个空。第一个是 directive,第二个是标记「这不是我的字段」, 第三个是引用解析要返回什么。
Three blanks. The first is a directive, the second marks a field as not belonging to this service, and the third is what the reference resolver returns.
下面哪一条最准确?
Which of these is most accurate?
batch 函数收到 ids = ['a', 'b', 'c'], 其中 b 在数据库里不存在。下面哪种返回是错的?
The batch function receives ids = ['a', 'b', 'c'], and b does not exist in the database. Which of these return values is wrong?
两个空。第一个要你填对数据源上真实存在的方法名, 第二个要你用 loader 而不是数据源。
Two blanks. The first wants the name of a method that really exists on the data source; the second wants you to go through the loader rather than the data source.
跑 npm test,其中一个 DataLoader 相关的测试挂了。 报错指向 loader 内部。
You run npm test and one of the DataLoader tests fails. The error points inside the loader.
四个 TODO 全都只写了 return [] 或return null,为什么还有 4 个测试通过?
All four TODOs contain nothing but return [] or return null. So why do 4 tests still pass?
createOrderLoader 调了不存在的orderDataSource.getOrderById(id)。 正确的修法是?
createOrderLoader calls orderDataSource.getOrderById(id), which does not exist. What is the right fix?
拿到 node-subgraph,最合理的动作顺序?
You have just opened node-subgraph. What is the most sensible order to work in?
四个空。第 2 个是数据源上的真实方法名, 第 4 个是那行最容易漏的防御。
Four blanks. The second is the method name that really exists on the data source; the fourth is the guard people most often forget.