-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Using directives on a field returning an interface does not allow nil
#799
Labels
bug
Something isn't working
Comments
Scratch this, I see this is fixed in master (#768) |
I spoke too soon, I still see this issue with the head of master for |
I wasn't able to get the tests setup to verify if this doesn't break anything, but the following patch seems to fix the issue: diff --git a/codegen/config/binder.go b/codegen/config/binder.go
index 72956de..228cb97 100644
--- a/codegen/config/binder.go
+++ b/codegen/config/binder.go
@@ -225,9 +225,13 @@ func (t *TypeReference) IsPtr() bool {
}
func (t *TypeReference) IsNilable() bool {
- _, isPtr := t.GO.(*types.Pointer)
- _, isMap := t.GO.(*types.Map)
- _, isInterface := t.GO.(*types.Interface)
+ goType := t.GO
+ if namedType, isNamed := goType.(*types.Named); isNamed {
+ goType = namedType.Underlying()
+ }
+ _, isPtr := goType.(*types.Pointer)
+ _, isMap := goType.(*types.Map)
+ _, isInterface := goType.(*types.Interface)
return isPtr || isMap || isInterface
} The issue is that the type was a |
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What happened?
Using a directive on a field that returns a GraphQL/Go
interface
type prohibits you from returningnil
, even if the field is nullable, as the generated type assertion fails.What did you expect?
Returning
nil
for an interface field that is nullable is possible when using a directive.Minimal graphql.schema and models to reproduce
schema.graphql
gqlgen.yml
resolver.go
The issue appears to be with this part of the generated code:
I believe it should check for
nil
before the type assertion check as type assertions will return false if the stored value isnil
.versions
The text was updated successfully, but these errors were encountered: