现在把整个链条完整串一次。
客户端发出问询单:
query ResidentWorkbench($residentId: ID!) {
resident(id: $residentId) {
id
name
zone
tickets(status: OPEN) {
id
title
status
device {
id
name
}
}
}
}变量:
{
"residentId": "r-1001"
}服务端处理流程:
1. 收到 /graphql 请求
2. 解析 GraphQL 文档
3. 按 Schema 校验
4. 执行 Query.resident resolver
5. 执行 Resident.tickets resolver
6. 执行 Ticket.device resolver
7. 合并结果
8. 返回 data / errors / extensions如果一切正常,回执可能是:
{
"data": {
"resident": {
"id": "r-1001",
"name": "林岚",
"zone": "A-7",
"tickets": [
{
"id": "t-501",
"title": "空调异响",
"status": "OPEN",
"device": {
"id": "d-9",
"name": "客厅空调外机"
}
}
]
}
}
}如果某个设备字段失败,仍然可能返回部分成功结果。
这就是 GraphQL 总台最值得建立的地方:
- 有统一入口
- 有明确手册
- 有精确问询
- 有按字段调度
- 有可部分成功的标准回执
到这一步,你已经不该把 GraphQL 看成“一个库”了。
它更像是软件城市里的智能问询总台系统。
#GraphQL 概念关系总图
+----------------------+
| Schema |
| Query / Mutation |
| Types / Inputs |
+----------+-----------+
|
定义“总台能接什么问题”
|
+--------------------------+--------------------------+
| | |
v v v
Query 操作 Mutation 操作 Fragment
问询单 变更工单 可复用模板
\\ / /
\\ / /
+---------------------+--------------------------+
|
v
Variables 变量填空
|
v
校验 Validation
|
v
Resolver 链式调度员
|
+---------------------+----------------------+
| | |
v v v
DB/SQL REST/RPC Cache
|
v
Response { data, errors, extensions }
重点执行风险:
1. 字段太多 -> 查询复杂度上升
2. 嵌套太深 -> Resolver 链变长
3. 天真取数 -> N+1
4. 无对象标识 -> 客户端缓存难做#官方来源链接清单
- GraphQL Learn 首页:https://graphql.org/learn/
- GraphQL Introduction:https://graphql.org/learn/introduction/
- GraphQL Schemas and Types:https://graphql.org/learn/schema/
- GraphQL Queries:https://graphql.org/learn/queries/
- GraphQL Mutations:https://graphql.org/learn/mutations/
- GraphQL Execution:https://graphql.org/learn/execution/
- GraphQL Response:https://graphql.org/learn/response/
- GraphQL Caching:https://graphql.org/learn/caching/
- GraphQL Performance:https://graphql.org/learn/performance/
- GraphQL Serving over HTTP:https://graphql.org/learn/serving-over-http/
- GraphQL Common HTTP Errors:https://graphql.org/learn/debug-errors/
- GraphQL Specification:https://spec.graphql.org/
- GraphQL over HTTP 规范草案:https://graphql.github.io/graphql-over-http/
- GraphQL.js 官方教程:https://www.graphql-js.org/docs/