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

Union type strips underscore in interface declaration, but not in method implementation #694

Closed
ZackKorman opened this issue Apr 28, 2019 · 1 comment · Fixed by #700
Closed
Labels
bug Something isn't working v0.9 Fixed in 0.9.0

Comments

@ZackKorman
Copy link

ZackKorman commented Apr 28, 2019

What happened?

We are trying to update from 0.7.2 to 0.8.3, and our schema has types like Content_User and Content_Post. Previously these would generate Go structs of the same name (Content_User and Content_Post), but now they generate structs without the underscore (ContentUser and ContentPost).

I don’t see that documented anywhere, but it’s not a major problem. I can make the changes to handle that. However, we also have a union type defined in the schema: union Content_Child = Content_User | Content_Post, which generates:

type ContentChild interface {
	IsContentChild()
}
...
func (ContentUser) IsContent_Child() {}

func (ContentPost) IsContent_Child() {}

As a result, neither type satisfies ContentChild.

What did you expect?

I expected the underscore to get stripped from the IsContent_Child method, given that the interface refers to IsContentChild.

Minimal graphql.schema and models to reproduce

Schema:

type Content_User {
  foo: String
}

type Content_Post {
  foo: String
}

union Content_Child = Content_User | Content_Post

versions

  • gqlgen version? v0.8.3
  • go version? v1.12.4
  • dep or go modules? go modules
@mathewbyrne mathewbyrne added the bug Something isn't working label May 1, 2019
@ZackKorman
Copy link
Author

I don't have any experience working with the internals of gqlgen, but I feel this commit might have introduced this bug, in changing Is{{.Name }}() to Is{{.Name|go }}(): de3b7cb#diff-6d3fce6819ce4ba7bdbb9fd106746d78

The declaration uses Is{{.Name|go }}():

type {{.Name|go }} interface {
Is{{.Name|go }}()
}

But the implementation uses Is{{ $iface }}():

{{- range $iface := .Implements }}
func ({{ $model.Name|go }}) Is{{ $iface }}() {}
{{- end }}

I am not sure if this helps any.

vektah added a commit that referenced this issue May 8, 2019
@vektah vektah mentioned this issue May 8, 2019
2 tasks
@vektah vektah added the v0.9 Fixed in 0.9.0 label May 15, 2019
cgxxv pushed a commit to cgxxv/gqlgen that referenced this issue Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v0.9 Fixed in 0.9.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants