Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2465 remote model with omitempty #2468

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions codegen/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func findGoInterface(def types.Type) (*types.Interface, error) {

func equalFieldName(source, target string) bool {
source = strings.ReplaceAll(source, "_", "")
source = strings.ReplaceAll(source, ",omitempty", "")
target = strings.ReplaceAll(target, "_", "")
return strings.EqualFold(source, target)
}
91 changes: 90 additions & 1 deletion integration/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions integration/gqlgen.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
schema:
- "schema.graphql"
- "user.graphql"
- "testomitempty.graphql"

exec:
filename: generated.go
Expand All @@ -10,6 +11,11 @@ resolver:
filename: resolver.go
type: Resolver

struct_tag: json

autobind:
- "github.com/99designs/gqlgen/integration/testomitempty"

models:
Element:
model: github.com/99designs/gqlgen/integration/models-go.Element
Expand Down
4 changes: 4 additions & 0 deletions integration/schema-expected.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ type Query {
viewer: Viewer
}

type RemoteModelWithOmitempty {
newDesc: String
}

type User {
likes: [String!]!
name: String!
Expand Down
3 changes: 3 additions & 0 deletions integration/testomitempty.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type RemoteModelWithOmitempty {
newDesc: String
}
5 changes: 5 additions & 0 deletions integration/testomitempty/testmodel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package testomitempty

type RemoteModelWithOmitempty struct {
Description string `json:"newDesc,omitempty"`
}