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

Optional Any type should allow nil values #1876

Closed
sugovsek opened this issue Feb 1, 2022 · 2 comments
Closed

Optional Any type should allow nil values #1876

sugovsek opened this issue Feb 1, 2022 · 2 comments

Comments

@sugovsek
Copy link

sugovsek commented Feb 1, 2022

What happened?

When trying to use Any as an optional input parameter, if you omit it or pass in null, it panics:

interface conversion: interface is nil, not interface {}

The reason seems to be similar to the one in #799 - the relevant line in generated.go:

return ec.resolvers.Mutation().Set(rctx, args["key"].(string), args["value"].(interface{}))

The "value" arg should be checked for nil before the type assertion. If I make this change directly in the generated file, it works as expected.

What did you expect?

Expected no error and the argument to be resolved to nil.

Minimal graphql.schema and models to reproduce

mutation {
    set(key: String!, value: Any): Boolean
}

scalar Any

versions

  • gqlgen version? v0.16.0
  • go version? 1.17
  • dep or go modules? go modules
@frederikhors frederikhors added enhancement New feature or request and removed enhancement New feature or request labels Feb 2, 2022
@AdamJSoftware
Copy link

Any news on this? Any potential work arounds?

@sugovsek
Copy link
Author

sugovsek commented May 6, 2022

My current workaround is an ugly hack, basically editing the generated file to check the value:

var value interface{}
if args["value"] != nil {
    value = args["value"].(interface{})
}
return ec.resolvers.Mutation().SetValue(rctx, args["key"].(string), value)

I'm planning to dig into the templates and make a proper fix, but I'm not sure when since I'm pretty busy these days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants