gqlgen requires a go mod tidy which isn't possible
- 主要语言
- Go
- 星标
- 10.8k
- 派生
- 1.3k
- 平均合并
- 2 天 36 分钟
- 30 天内合并 PR
- 26
描述
### What happened?
I run `gqlgen` (installed in `home/go/bin`) and reveive this error:
```
modelgen: package could not be loaded: github.com/99designs/gqlgen/graphql.Boolean: packages.Load: err: exit status 1: stderr: go: updates to go.mod needed; to update it:
go mod tidy
```
Therefore, I run `go mod tidy`, which fails with:
```
github.com/my_company/my_project/internal/cli imports
github.com/my_company/my_project/internal/app/graphql: no matching versions for query "latest"
github.com/my_company/my_project/eventing imports
github.com/my_company/my_project/internal/graphql/models: no matching versions for query "latest"
```
I guess that's b/c `internal/app/graphql` and `internal/graphql/models` don't exist yet (I want `gqlgen` to create files here).
I recall that in the past I solved that problem somehow by flddling with `get get -u` commands, but after reinstalling Ubuntu this time I don't really manage it. I'ld also love to understand what the problem actually is instead of just mindlessly hammering some commands. ;)
When I can create the imported module by hand with an empty dummy file in it, `go mod tidy` works, and so does `gqlgen` afterward. Maybe it would make help if `gqlgen` created its target files before it call `go mod tidy`?
### What did you expect?
Ideally, `gqlgen` generates the file without requiring `go mod tidy`, or I can run `go mod tidy` first (if that solved the issue).
### Minimal graphql.schema and models to reproduce
`graphql.schema`:
```yaml
schema: api/my_entity.graphqls
exec:
filename: internal/app/graphql/gql_exec_gen.go
package: graphql
model:
filename: internal/graphql/models/models_gen.go
package: models
resolver:
filename: internal/graphql/resolver.go
type: Resolver
package: graphql
```
`api/my_entity.graphqls`:
```graphql
type MyEntitiy {
id: ID!
}
type Query {
myEntity(id: ID!): MyEntity
}
```
### versions
github.com/99designs/gqlgen v0.17.32
go1.20.5 linux/amd64
贡献指南
调研方向
查看 gqlgen 的 codegen 中的模型生成步骤,可能位于 internal/codegen 或 cmd/gen.go。问题在于,生成文件的目标目录尚不存在,导致 go mod tidy 失败。检查 gqlgen 如何与 Go 模块交互,以及是否可以在调用 go mod tidy 之前创建占位目录或文件。运行与代码生成相关的现有测试将有助于验证修复是否有效。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- go
- 领域
- build-system
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100