Skip to content

Commit

Permalink
Fix data race
Browse files Browse the repository at this point in the history
The argument of unmarshalInput may be the same for concurrent use if it pass as graphql "variables".
So we have to copy it before setting default values
  • Loading branch information
skaji committed Feb 6, 2021
1 parent 997da42 commit 18678b1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion codegen/input.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
{{- if not .HasUnmarshal }}
func (ec *executionContext) unmarshalInput{{ .Name }}(ctx context.Context, obj interface{}) ({{.Type | ref}}, error) {
var it {{.Type | ref}}
var asMap = obj.(map[string]interface{})
asMap := map[string]interface{}{}
for k, v := range obj.(map[string]interface{}) {
asMap[k] = v
}
{{ range $field := .Fields}}
{{- if $field.Default}}
if _, present := asMap[{{$field.Name|quote}}] ; !present {
Expand Down

0 comments on commit 18678b1

Please sign in to comment.