Best practices for handling gqlgen resolvers with shared query metadata
- 主要語言
- Go
- 星號
- 10.8k
- 分支
- 1.3k
- 平均合併
- 2 天 36 分鐘
- 30 天內合併 PR
- 26
描述
Hi everyone,
I'm working with gqlgen and need advice on the best way to structure resolvers and gqlgen.yml for the following schema:
```
query {
request: QueryMessage!
}
type QueryMessage {
requestID: String!
offline: Boolean!
maxPageSize: Int
{{userType1}}(filter: {{UserTypeFilterInput1}}!, offset: Int, limit: Int, cursor: String): {{UserTypeResult1}}!
...
{{userTypeN}}(filter: {{UserTypeFilterInputN}}!, offset: Int, limit: Int, cursor: String): {{UserTypeResultN}}!
}
```
Each userType* field in QueryMessage needs access to requestID, offline, and maxPageSize. What is the best approach to achieve this in gqlgen?
How should I structure gqlgen.yml to properly generate resolvers for QueryMessage?
How can I ensure that each resolver function for userType* has access to requestID, offline, and maxPageSize?
Should QueryMessage be a custom Go struct, and if so, how should it be instantiated in resolvers?
Are there best practices for caching or sharing the QueryMessage context across multiple field resolvers?
Any guidance or examples would be greatly appreciated. Thanks!
貢獻指南
研究方向
這個 issue 涉及將 gqlgen resolvers 和 gqlgen.yml 設定檔結構化,以便在多個 resolver fields 之間共用中繼資料(requestID、offline、maxPageSize)。首先,檢查 gqlgen 關於 resolver 模式和 gqlgen.yml schema 的文件。查看 repository 中現有的 resolver 範例,以了解如何傳遞 context 和父物件。確定如何為 QueryMessage 定義自訂 Go struct,以及如何建立它的執行個體,使其欄位可供每個 userType* field resolver 存取。檢查 codebase 中是否已有在不同 resolver 之間共用 context 或快取資料的模式。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- go, graphql
- 領域
- api, backend
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100