Skip to content

Commit

Permalink
fix #2465 remote model with omitempty
Browse files Browse the repository at this point in the history
  • Loading branch information
mstephano committed Dec 14, 2022
1 parent da43147 commit c57921a
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 1 deletion.
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"`
}

0 comments on commit c57921a

Please sign in to comment.