GraphQL does not support natively the notion of file uploads, but an extension to the GraphQL protocol was proposed to add support for multipart requests.
GraphQLite supports this extension through the use of the Ecodev/graphql-upload library.
If you are using the Symfony bundle
If you are using our Symfony bundle, the file upload middleware is managed by the bundle. You have nothing to do and can start using it right away.
If you are using a PSR-15 compatible framework
In order to use this, you must first be sure that the
ecodev/graphql-upload PSR-15 middleware is part of your middleware pipe.
GraphQL\Upload\UploadMiddleware to your middleware pipe.
If you are using another framework not compatible with PSR-15
Please check the Ecodev/graphql-upload library documentation for more information on how to integrate it in your framework.
To handle an uploaded file, you type-hint against the PSR-7
public function saveDocument(string $name, UploadedFileInterface $file): Document
// Some code that saves the document.
Of course, you need to use a GraphQL client that is compatible with multipart requests.
See jaydenseric/graphql-multipart-request-spec for a list of compatible clients.