99designs / 99designs/gqlgen

Custom type for a specific field

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

描述

### What happened?

In `gqlgen.yml` I'd like to replace the current generated type, `[]string` in Golang from `[String!]` in GraphQL by a custom one because GORM doesn't understand `[]string` as is. I'd like to replace this by `pq.StringArray` instead.

I tried configuring it like this

```
models:
Organization:
fields:
Usecases:
type: "pq.StringArray"
```

Inspiring myself from the `extraFields` documentation, but it did not work. How can I do that?

### What did you expect?

Being able to have `Usecases` in my `Organization` struct to be of type `pq.StringArray` for compatibility reasons.

### Minimal graphql.schema and models to reproduce

```
# Where are all the schema files located? globs are supported eg src/**/*.graphqls
schema:
- internal/graphql/schemas/*.graphql

# Where should the generated server code go?
exec:
filename: internal/graphql/generated/generated.go
package: generated

# Uncomment to enable federation
# federation:
# filename: app/generated/federation.go
# package: generated

# Where should any generated models go?
model:
filename: internal/models/models.go
package: models

# Where should the resolver implementations go?
resolver:
layout: follow-schema
dir: internal/graphql/resolvers
package: resolvers

# Optional: turn on use `gqlgen:"fieldName"` tags in your models
# struct_tag: json

# Optional: turn on to use []Thing instead of []*Thing
# omit_slice_element_pointers: false

# Optional: set to speed up generation time by not performing a final validation pass.
# skip_validation: true

# gqlgen will search for any type names in the schema in these go packages
# if they match it will use them, otherwise it will generate them.
autobind:
- "aquiestoy/internal/models"

# This section declares type mapping between the GraphQL and go type systems
#
# The first line in each type will be used as defaults for resolver arguments and
# modelgen, the others will be allowed when binding to fields. Configure them to
# your liking

models:
Organization:
fields:
Usecases:
type: "pq.StringArray"
```

### versions
- v0.17.39
- go version go1.21.4 darwin/arm64

贡献指南

打开贡献指南

调研方向

查看 gqlgen 配置文件格式和模型生成代码。这个 issue 涉及将 GraphQL 列表类型映射到自定义 Go 类型 (pq.StringArray),以实现与 GORM 的兼容。首先检查 codegen 如何处理字段类型覆盖,这部分代码可能位于模型生成包中。检查现有的自定义类型映射测试,以了解预期的语法和实现。

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

评估

技术栈
go, graphql
领域
api, backend
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

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