动手做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.
练习Exercises
筛出 47 个练习(共 148 个) · 第 3 / 4 页。Showing 47 of 148 · page 3 / 4.按钮好好的,卡片一渲染就整页白屏。这是真实报错。
The button is fine, and the moment the card renders the whole page goes blank. This is the real error.
新建了组件之后启动开发服务器,Vite 直接报错,页面白屏。
You add a new component, start the dev server, and Vite reports an error right away. The page is blank.
重构时把父组件传的 prop 名改了,子组件忘了跟着改。 页面能显示,但点 Delete 直接崩。
During a refactor the prop name passed by the parent was changed, and the child component was not changed to match. The page still renders, but clicking Delete crashes it.
代码看起来完全正确,手动点也没问题,但两个测试挂了。
The code looks entirely correct and clicking through it by hand works, but two tests fail.
照真实 schema.graphql 补全。 三个空分别关系到「入口类型」「枚举」「输入类型」。
Fill this in from the real schema.graphql. The three blanks are the entry type, the enum and the input type.
照 schema 的非空标记,给每个 resolver 填上正确的返回表达式。 想清楚「这个字段能不能是 null」。
Go by the non-null markers in the schema and write the right return expression for each resolver. Decide first whether the field is allowed to be null.
三个空。第一个是 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.
两个空。第一个要你填对数据源上真实存在的方法名, 第二个要你用 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.
四个空。第 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.
三个空。第 1 个决定你答不答得到 N+1 考点, 第 3 个决定第二条测试过不过。
Three blanks. The first decides whether you answer the N+1 question at all; the third decides whether the second test passes.
四个空横跨两个 resolver。注意它们数据来源不同、兜底策略不同。
Four blanks across two resolvers. Note they read from different places and need different fallbacks.