gqlgen icon indicating copy to clipboard operation
gqlgen copied to clipboard

assignment to entry in nil map when uploading a file

Open salyakhov-art opened this issue 3 years ago • 3 comments

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

salyakhov-art avatar Apr 07 '21 11:04 salyakhov-art

Strange that you just created this ticket today, because I just encountered this issue today as well.

hickeroar avatar Apr 07 '21 16:04 hickeroar

Any fix for this?

spdrstar avatar Sep 28 '21 08:09 spdrstar

@salyakhov-art Any fix for this issue?

mehnazb3 avatar Mar 01 '22 21:03 mehnazb3

Same error

  • gqlgen v0.17.13
  • go version: go1.19.1 darwin/arm64
  • go modules

Vesli avatar Sep 30 '22 13:09 Vesli

For my side, I check the code and find the params decode from the input, so I think need to declare like follow. https://github.com/99designs/gqlgen/blob/master/graphql/handler/transport/http_form.go#L81-L86

❌ {"query": "mutation uploadImage($image:Upload!) {uploadImage(image: $image){URL}}"} ✅ {"query": "mutation uploadImage($image:Upload!) {uploadImage(image: $image){URL}}", "variables": {"image": null}}

# https://gqlgen.com/getting-started/
scalar Upload

type Image {
    URL: String!
}

extend type Mutation {
    uploadImage(image: Upload!): Image
}

zhongyiio avatar Dec 06 '22 09:12 zhongyiio