DrillLab
练习Practice

动手做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.

0 / 148个做对过you got right

练习Exercises

筛出 56 个练习(共 148 个) · 第 4 / 5 页。Showing 56 of 148 · page 4 / 5.
来自From N+1 问题与 DataLoaderThe N+1 problem and DataLoader · Federation 考试Federation exam
L1认出来Spot itDataLoader 靠什么把 N 次合并成 1 次How DataLoader turns N calls into 1

下面哪一条最准确?

Which of these is most accurate?

先选一个选项Pick an option first
来自From N+1 问题与 DataLoaderThe N+1 problem and DataLoader · Federation 考试Federation exam
L1认出来Spot itbatch 函数里哪种写法是错的Which return value from a batch function is wrong

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?

先选一个选项Pick an option first
来自From 先读题:四个 TODO、三处埋雷、十个测试Read the task first: four TODOs, three planted bugs, ten tests · Federation 考试Federation exam
L1认出来Spot it为什么基线里有 4 个测试是通过的Why 4 tests already pass at the baseline

四个 TODO 全都只写了 return []return null,为什么还有 4 个测试通过?

All four TODOs contain nothing but return [] or return null. So why do 4 tests still pass?

先选一个选项Pick an option first
来自From 先读题:四个 TODO、三处埋雷、十个测试Read the task first: four TODOs, three planted bugs, ten tests · Federation 考试Federation exam
L1认出来Spot it埋雷 1 该在哪个文件修Which file should planted bug 1 be fixed in

createOrderLoader 调了不存在的orderDataSource.getOrderById(id)。 正确的修法是?

createOrderLoader calls orderDataSource.getOrderById(id), which does not exist. What is the right fix?

先选一个选项Pick an option first
来自From 先读题:四个 TODO、三处埋雷、十个测试Read the task first: four TODOs, three planted bugs, ten tests · Federation 考试Federation exam
L1排顺序Order it把 Task 1 的推进顺序排对Put the steps of Task 1 in the right order

拿到 node-subgraph,最合理的动作顺序?

You have just opened node-subgraph. What is the most sensible order to work in?

1逐个实现四个 TODOImplement the four TODOs one by one
2读 schema.graphql,记下四个返回类型的可空性Read schema.graphql and note the nullability of the four return types
3npm install,然后 npm test 拿到 6 failed / 4 passed 的基线npm install, then npm test to get the 6 failed / 4 passed baseline
4npm test 转绿,再写个 verify 脚本查 _service 和 _entitiesOnce npm test is green, write a verify script that checks _service and _entities
5读 index.js 和 dataSources,抄下 context 键名与方法名Read index.js and the dataSources, and copy out the context keys and method names
6修三处埋雷Fix the three planted bugs
来自From TODO 2 · Order.shippingInfoTODO 2 · Order.shippingInfo · Federation 考试Federation exam
L1认出来Spot it为什么不能直接调数据源Why you cannot just call the data source

dataSources.shippingDataSource.getShippingInfo(parent.id) 能让两条测试都通过。为什么还是错的?

dataSources.shippingDataSource.getShippingInfo(parent.id) makes both tests pass. So why is it still wrong?

先选一个选项Pick an option first
来自From 先看懂给你的东西:Spring 的几个注解和一条请求链路Understand what you are given: a few Spring annotations and the path one request takes · Federation 考试Federation exam
L1认出来Spot it找不到订单时该怎么处理What to do when the order is not found

getOrderById 端点里,orderService.getOrderById(id) 找不到时会抛EntityNotFoundException。 控制器应该怎么写?

In the getOrderById endpoint, orderService.getOrderById(id) throws EntityNotFoundException when it finds nothing. How should the controller be written?

先选一个选项Pick an option first
来自From 先看懂给你的东西:Spring 的几个注解和一条请求链路Understand what you are given: a few Spring annotations and the path one request takes · Federation 考试Federation exam
L1认出来Spot it这三个参数注解各从哪取值Where each of these parameter annotations reads from

请求是 PATCH /api/orders/7/status, body 是 {"status":"SHIPPED"}
方法签名是 updateOrderStatus(@PathVariable Long id, @RequestBody Map<String,String> statusUpdate)idstatusUpdate 分别是什么?

The request is PATCH /api/orders/7/status with the body {"status":"SHIPPED"}.
The method signature is updateOrderStatus(@PathVariable Long id, @RequestBody Map<String,String> statusUpdate). What are id and statusUpdate?

先选一个选项Pick an option first
来自From 六个端点:状态码就是这道题的全部Six endpoints: the status codes are the whole task · Federation 考试Federation exam
L1认出来Spot itPOST 创建成功该返回什么What a successful POST should return

POST /api/orders 成功创建了一个订单。 该返回哪个状态码,怎么写?

POST /api/orders created an order successfully. Which status code should it return, and how do you write that?

先选一个选项Pick an option first
来自From 六个端点:状态码就是这道题的全部Six endpoints: the status codes are the whole task · Federation 考试Federation exam
L1认出来Spot it为什么 return null 能骗过三个测试Why return null fools three of the tests

baseline 状态下六个端点全是 return null, 五个测试却通过了三个。为什么?

At the baseline all six endpoints are just return null, yet three of the five tests pass. Why?

先选一个选项Pick an option first
来自From 两道书面题:延迟传播与生产配置The two written questions: how delay spreads, and production configuration · Federation 考试Federation exam
L1认出来Spot it哪一行是最严重的安全问题Which line is the most serious security problem

题面给的六行配置里,哪一行能直接导致数据库口令泄漏?

Of the six configuration lines in the question, which one can directly leak the database password?

Properties源项目From source
1server.port=8080
2server.address=0.0.0.0
3spring.datasource.url=jdbc:postgresql://${DB_HOST}:5432/orders
4spring.datasource.username=${DB_USER}
5spring.datasource.password=${DB_PASSWORD}
6management.endpoints.web.exposure.include=*
Source: graphql-federation-practice/QUESTIONS.md
先选一个选项Pick an option first
来自From 两道书面题:延迟传播与生产配置The two written questions: how delay spreads, and production configuration · Federation 考试Federation exam
L1认出来Spot it为什么 User subgraph 慢会拖慢 Orders subgraphWhy a slow User subgraph slows the Orders subgraph down

客户端查 { user(id:"1") { name orders { id } } }。 Accounts subgraph 要 500ms,Orders subgraph 只要 10ms。 总延迟大约是多少,为什么?

A client asks for { user(id:"1") { name orders { id } } }. The Accounts subgraph takes 500ms, the Orders subgraph only 10ms. Roughly what is the total latency, and why?

先选一个选项Pick an option first