Commit 2af04e0
Nick Parker
Use original field names for struct 'json:X' annotations
If a graphql command or fields contain underscores (e.g. snake_case), the generator currently converts both the Go struct field names AND the json annotations to PascalCase. In the process, this removes the underscores, which are significant to the query. For example, the following GraphQL query definition...:
```
query GetExporter($tenant: String!, $name: String!) {
exporter_by_pk(tenant: $tenant, name: $name) {
tenant
name
type
credential
config
created_at
updated_at
}
}
```
...is rendered to Go like this:
```
type GetExporterResponse struct {
ExporterByPk struct {
Tenant string `json:"Tenant"`
Name string `json:"Name"`
Type string `json:"Type"`
Credential string `json:"Credential"`
Config string `json:"Config"`
CreatedAt string `json:"CreatedAt"` // was created_at
UpdatedAt string `json:"UpdatedAt"` // was updated_at
} `json:"ExporterByPk"` // was exporter_by_pk
}
```
With this PR, the issue is resolved by using the original names in the `json:X` annotations, while keeping the PascalCase for the Go field names themselves:
```
type GetExporterResponse struct {
ExporterByPk struct {
Tenant string `json:"tenant"`
Name string `json:"name"`
Type string `json:"type"`
Credential string `json:"credential"`
Config string `json:"config"`
CreatedAt string `json:"created_at"` // fixed
UpdatedAt string `json:"updated_at"` // fixed
} `json:"exporter_by_pk"` // fixed
}
```1 parent c489066 commit 2af04e0
1 file changed
+2
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
334 | | - | |
| 334 | + | |
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
340 | | - | |
341 | | - | |
| 340 | + | |
342 | 341 | | |
343 | 342 | | |
344 | 343 | | |
| |||
0 commit comments