动手做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
筛出 11 个练习(共 148 个)。Showing 11 of 148.照真实 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.
五个空。第 2、4、5 个是这道题真正的得分点。
Five blanks. Numbers 2, 4 and 5 are where the credit in this question actually is.
查一个没有订单的用户,整个 data 变成了null,而且 errors 里有一条很长的消息。
You query a user who has no orders, the whole data turns into null, and errors carries one very long message.
Java 那边。mvn test 全过, 但客户端传小写的 shipped 时服务返回 500。
This one is on the Java side. mvn test passes everything, but the service returns 500 when the client sends the lowercase shipped.