99designs / 99designs/gqlgen

assignment to entry in nil map when uploading a file

未关闭 适合新手
#1,509 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Go
星标
10.8k
派生
1.3k
平均合并
2 天 36 分钟
30 天内合并 PR
26

描述

### What happened?
If the operation field is incorrect during the file upload, a panic is triggered. `assignment to entry in nil map`
The panic occurs in https://github.com/99designs/gqlgen/blob/master/graphql/handler.go#L115

Request:
```
curl --location --request POST 'localhost/graphql' \
--form 'map="{\"1\": [\"variables.file\"]}"' \
--form '1=@"/Users/user_name/image_2021-03-17_14-22-00.png"' \
--form 'operations="{\"query\": \"mutation($file: Upload!) {imageLibraryUpload(input: {name: \\\"image_2021-03-17_14-22-00.png\\\",src: $file}){id}}\"}"'
```

If you add a variable object to the operations, everything will be successful.
```
curl --location --request POST 'localhost/graphql' \
--form 'map="{\"1\": [\"variables.file\"]}"' \
--form '1=@"/Users/user_name/image_2021-03-17_14-22-00.png"' \
--form 'operations="{\"variables\": {\"file\": null}, \"query\": \"mutation($file: Upload!) {imageLibraryUpload(input: {name: \\\"image_2021-03-17_14-22-00.png\\\",src: $file}){id}}\"}"'
```

### What did you expect?
Correct error

### Minimal graphql.schema and models to reproduce

```
type Mutation {
imageLibraryUpload(input: imageLibraryUploadInput!): UploadedImage!
}

type UploadedImage {
id: ID!
srcUrl: String!
}

input imageLibraryUploadInput {
name: String!
src: Upload!
}
```

### versions
- `gqlgen version`? `v0.9.3`
- `go version`? `go1.15.4 darwin/amd64`
- dep or go modules? `go modules`

贡献指南

打开贡献指南

调研方向

panic 发生在 graphql/handler.go 第 115 行,该处尝试向 nil map 赋值。首先检查该行附近的文件上传解析逻辑,特别是 'operations' 字段的解析方式以及 'variables' map 的初始化方式。使用提供的 curl 命令重现该问题以查看 panic,然后确保在赋值之前正确初始化 map。检查现有的文件上传相关测试,以了解预期行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
go
领域
backend-api-design
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
65/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。