Custom type for a specific field
- Dominant language
- Go
- Stars
- 10.8k
- Forks
- 1.3k
- Avg merge
- 2d 36m
- Merged PRs (30d)
- 26
Description
### 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
Contributor guide
Assessment
This issue has not been assessed yet.