movio / bramble

A federated GraphQL API gateway
https://movio.github.io/bramble/
MIT License
497 stars 55 forks source link

Multipart. Got a null response for non-nullable field #262

Closed suhodolskiy closed 3 months ago

suhodolskiy commented 3 months ago

I get an error when sending a multipart request with a file. But If I send a request bypassing the gateway, there is no error.

Response

{
  "errors": [
    {
      "message": "map[string]interface {} is not an Upload",
      "path": [
        "uploadFile",
        "input",
        "file"
      ],
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "extensions": {
        "selectionPath": [
          "uploadFile"
        ],
        "selectionSet": "{ uploadFile(input: $input) { id url } }",
        "serviceName": "...",
        "serviceUrl": "http://..."
      }
    },
    {
      "message": "got a null response for non-nullable field \"uploadFile\"",
      "path": [
        "uploadFile"
      ]
    }
  ],
  "data": null
}

Request payload

-----------------------------386949902811154848193528235860
Content-Disposition: form-data; name="operations"

{"query":"mutation UploadFile($input: UploadFileInput!) {\n  uploadFile(input: $input) {\n    id\n    url\n  }\n}","variables":{"input":{"file":null,"entity":"user-avatar"}}}
-----------------------------386949902811154848193528235860
Content-Disposition: form-data; name="map"

{"1":["variables.input.file"]}
-----------------------------386949902811154848193528235860
Content-Disposition: form-data; name="1"; filename="cropped-1712928276777.jpeg"
Content-Type: image/jpeg

...

Schema

scalar Upload

input UploadFileInput {
    entity: String!
    file: Upload!
}

type File {
    id: String!
    url: String!
}

type Mutation {
    uploadFile(input: UploadFileInput): File! @authorized
}
{
  "data": {
    "service": {
      "name": "...",
      "schema": "directive @authorized on FIELD_DEFINITION\ninput UploadFileInput {\n\tentity: String!\n\tfile: Upload!\n}\n\ntype File {\n\tid: String!\n\turl: String!\n}\n\ntype Mutation {\n\tuploadFile(input: UploadFileInput): File! @authorized\n}\ntype Service {\n\tname: String!\n\tversion: String!\n\tschema: String!\n}\n\ntype Query {\n\tservice: Service!\n}\nscalar Upload\n"
    }
  }
}

It looks like it's a gateway's side issue or I'm doing something wrong. I will be glad to hear your opinions or get advice on how to solve this. Thanks!

pkqk commented 3 months ago

Hi @suhodolskiy, this is a duplicate of https://github.com/movio/bramble/issues/154, bramble doesn't have support for the multipart upload spec yet. It's separate from the graphql spec and we haven't looked at using it yet.

There's some pointers of where to start in the discussion on #154 if you'd like to have a go implementing it.