Skip to content

Commit

Permalink
Fix directives returning nils from optional interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Sep 24, 2019
1 parent eea38e5 commit 34d1097
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 107 deletions.
3 changes: 3 additions & 0 deletions codegen/config/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ func (b *Binder) CopyModifiersFromAst(t *ast.Type, base types.Type) types.Type {
}

func isNilable(t types.Type) bool {
if namedType, isNamed := t.(*types.Named); isNamed {
t = namedType.Underlying()
}
_, isPtr := t.(*types.Pointer)
_, isMap := t.(*types.Map)
_, isInterface := t.(*types.Interface)
Expand Down
4 changes: 2 additions & 2 deletions codegen/interface.gotpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- range $interface := .Interfaces }}

func (ec *executionContext) _{{$interface.Name}}(ctx context.Context, sel ast.SelectionSet, obj *{{$interface.Type | ref}}) graphql.Marshaler {
switch obj := (*obj).(type) {
func (ec *executionContext) _{{$interface.Name}}(ctx context.Context, sel ast.SelectionSet, obj {{$interface.Type | ref}}) graphql.Marshaler {
switch obj := (obj).(type) {
case nil:
return graphql.Null
{{- range $implementor := $interface.Implementors }}
Expand Down
229 changes: 160 additions & 69 deletions codegen/testserver/generated.go

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

Loading

0 comments on commit 34d1097

Please sign in to comment.