Skip to content

Commit

Permalink
Merge pull request #705 from 99designs/fix-error-race
Browse files Browse the repository at this point in the history
Fix a data race when handling concurrent resolver errors
  • Loading branch information
vektah authored May 14, 2019
2 parents 9ca43ba + 962470d commit ab961ce
Show file tree
Hide file tree
Showing 22 changed files with 1,163 additions and 881 deletions.
1 change: 1 addition & 0 deletions codegen/generated!.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{{ reserveImport "strconv" }}
{{ reserveImport "time" }}
{{ reserveImport "sync" }}
{{ reserveImport "sync/atomic" }}
{{ reserveImport "errors" }}
{{ reserveImport "bytes" }}

Expand Down
16 changes: 12 additions & 4 deletions codegen/object.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
{{end}}

out := graphql.NewFieldSet(fields)
invalid := false
var invalids uint32
for i, field := range fields {
switch field.Name {
case "__typename":
Expand All @@ -50,7 +50,11 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
res = ec._{{$object.Name}}_{{$field.Name}}(ctx, field{{if not $object.Root}}, obj{{end}})
{{- if $field.TypeReference.GQL.NonNull }}
if res == graphql.Null {
invalid = true
{{- if $object.IsConcurrent }}
atomic.AddUint32(&invalids, 1)
{{- else }}
invalids++
{{- end }}
}
{{- end }}
return res
Expand All @@ -59,7 +63,11 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
out.Values[i] = ec._{{$object.Name}}_{{$field.Name}}(ctx, field{{if not $object.Root}}, obj{{end}})
{{- if $field.TypeReference.GQL.NonNull }}
if out.Values[i] == graphql.Null {
invalid = true
{{- if $object.IsConcurrent }}
atomic.AddUint32(&invalids, 1)
{{- else }}
invalids++
{{- end }}
}
{{- end }}
{{- end }}
Expand All @@ -69,7 +77,7 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
}
}
out.Dispatch()
if invalid { return graphql.Null }
if invalids > 0 { return graphql.Null }
return out
}
{{- end }}
Expand Down
21 changes: 0 additions & 21 deletions codegen/testdata/gqlgen.yml

This file was deleted.

168 changes: 0 additions & 168 deletions codegen/testdata/schema.graphql

This file was deleted.

Loading

0 comments on commit ab961ce

Please sign in to comment.