-
-
Notifications
You must be signed in to change notification settings - Fork 57
Closed
Labels
Description
I think that the "map" in the request is unnecessary. In my opinion it's much easier to do this:
cURL request
curl localhost:3001/graphql \
-F operations='{ "query": "mutation ($file: Upload!) { singleUpload(file: $file) { id } }", "variables": { "file": "0" } }' \
-F [email protected]
Request payload
--------------------------cec8e8123c05ba25
Content-Disposition: form-data; name="operations"
{ "query": "mutation ($file: Upload!) { singleUpload(file: $file) { id } }", "variables": { "file": "0" } }
--------------------------cec8e8123c05ba25
Content-Disposition: form-data; name="0"; filename="a.txt"
Content-Type: text/plain
Alpha file content.
--------------------------cec8e8123c05ba25--
Thus, it is easier to organize server-side support:
Example for webonyx/graphql-php
class UploadType extends ScalarType
{
public $name = 'Upload';
public function parseValue($value)
{
return $_FILES[$value] ?? null;
}
}
Example for nodejs
import { GraphQLScalarType } from 'graphql'
import requestContext from from 'global-request-context'
export const GraphQLUpload = new GraphQLScalarType({
name: 'Upload',
parseValue: value => {
const { req } = requestContext
return req.files[value] || null
}
})
What do you think about this?