Directives with ":" in value generate incorrect go tags
- Dominant language
- Go
- Stars
- 10.8k
- Forks
- 1.3k
- Avg merge
- 2d 36m
- Merged PRs (30d)
- 26
Description
### What happened?
I declare a directive for custom go tags (in `schema.directives.gql`):
```
directive @goTag(
key: String!
value: String
) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION
```
Then I use it the following way :
```
type Value {
value: Float!
unit: String!
}
type Order {
name: String! @goTag(key: "gorm", value: "primaryKey")
amount: Value! @goTag(key: "gorm", value: "embedded;embeddedPrefix:dissolutionAmount_")
submitterRef String!
submitter: Person! @goTag(key: "gorm", value: "foreignKey: SubmitterRef")
}
```
Then I run code generation: `go run github.com/99designs/gqlgen generate` and the resulting code contains gorm tags that cut out text after colon:
```
type Order struct {
Name string `json:"name" gorm:"primaryKey"` // <--- this is correct
Amount Value `json:"amount" gorm:"embedded;embeddedPrefix` // INCORRECT - everything after "embeddedPrefix" is truncated: ":dissolutionAmount_" is missing, including trailing double quote
SubmitterRef string. `json:"submitterRef"`
Submitter Person `json:"submitter" gorm:"foreignKey` // INCORRECT - value in gorm tag is truncated, ": SubmitterRef" is missing
}
```
### What did you expect?
I expect the generated go code to include the correct gorm tags in the respective fields:
```
type Order struct {
Name string `json:"name" gorm:"primaryKey"`
Amount Value `json:"amount" gorm:"embedded;embeddedPrefix:dissolutionAmount_"`
SubmitterRef string. `json:"submitterRef"`
Submitter Person `json:"submitter" gorm:"foreignKey:SubmitterRef"`
}
```
### Minimal graphql.schema and models to reproduce
### versions
- `go run github.com/99designs/gqlgen version`? v0.17.34
- `go version`? v1.21.0
Contributor guide
Research direction
Look at the code generation for directives, likely in codegen/ or plugin/. The issue is that colons in directive values are being incorrectly parsed or escaped when generating Go struct tags. Start by searching for 'goTag' or directive handling. Run the provided example to reproduce the bug, then examine how the tag string is assembled. The fix should ensure the full value is preserved in the generated tag.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, graphql
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100