99designs / 99designs/gqlgen

Plugin code gen fails in vendor mode

未关闭
#2,710 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Go
星标
10.8k
派生
1.3k
平均合并
2 天 36 分钟
30 天内合并 PR
26

描述

### What happened?

When using `-mod=vendor`, the project should properly account for imports; however, one of the imports is not added to the mod file due to it being specified only in the go template file resulting in:

```
merging type systems failed: unable to build object definition: unable to find type: github.com/99designs/gqlgen/graphql/introspection.Schema
```

The offending file is `github.com/99designs/gqlgen/codegen/root_.gotpl` where `{{ reserveImport "github.com/99designs/gqlgen/graphql/introspection" }}` is reserved but not imported explicitly anywhere.

Using `_ "github.com/99designs/gqlgen/graphql/introspection"` fixes the issue but this should probably be included in the project and not in projects importing the package.

**Keep in mind** this is in a `plugin` project that imports gqlgen.

### What did you expect?

Code generation to work successfully after running `go mod vendor` and `go mod tidy` in `vendor mode` via `-mod=vendor` set in `GOFLAGS`.

### Minimal graphql.schema and models to reproduce

N/A

### versions
- `go run github.com/99designs/gqlgen version`?

`github.com/99designs/gqlgen v0.17.34`

- `go version`?

`go version go1.20.5 darwin/arm64`

贡献指南

打开贡献指南

调研方向

该 issue 位于模板文件 `github.com/99designs/gqlgen/codegen/root_.gotpl` 中。查看在 vendor 模式下如何保留和添加 imports。修复可能涉及确保 `github.com/99designs/gqlgen/graphql/introspection` 的保留 import 被正确包含在生成的 mod 文件中。通过设置 GOFLAGS=-mod=vendor 并在插件项目中运行代码生成进行测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
go
领域
build-system
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
55/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。