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

Fix data race (issue #1455) #1456

Merged
merged 2 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this copy need to go deeper for nested types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lwc Thanks for the review.

gqlgen will set the default values for fields (i.e., asMap's direct values).
So I don't think we need deep copy here.

{{ range $field := .Fields}}
	{{- if $field.Default}}
		if _, present := asMap[{{$field.Name|quote}}] ; !present {
			asMap[{{$field.Name|quote}}] = {{ $field.Default | dump }}
		}
	{{- end}}
{{- end }}

asMap[k] = v
}
{{ range $field := .Fields}}
{{- if $field.Default}}
if _, present := asMap[{{$field.Name|quote}}] ; !present {
Expand Down
50 changes: 40 additions & 10 deletions codegen/testserver/generated.go

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

5 changes: 4 additions & 1 deletion example/config/generated.go

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

5 changes: 4 additions & 1 deletion example/fileupload/generated.go

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

5 changes: 4 additions & 1 deletion example/scalars/generated.go

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

5 changes: 4 additions & 1 deletion example/starwars/generated/exec.go

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

5 changes: 4 additions & 1 deletion example/todo/generated.go

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

5 changes: 4 additions & 1 deletion example/type-system-extension/generated.go

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

5 changes: 4 additions & 1 deletion integration/generated.go

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