Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Upload #128

Closed
VincentClair opened this issue Mar 31, 2017 · 5 comments
Closed

File Upload #128

VincentClair opened this issue Mar 31, 2017 · 5 comments

Comments

@VincentClair
Copy link

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no
Version/Branch 0.8.0

Is there a way to upload files through graphql?
Does the bundle manage multipart request?

Here is a related proposal for Apollo: apollographql/apollo#65.

@mcg-web
Copy link
Member

mcg-web commented Mar 31, 2017

Hi, yes it is possible, you must use request to get your file in your mutation resolver, you can inject it using the object request in the expression language...

@ooflorent
Copy link
Contributor

@mcg-web Could you provide an example? :trollface:

@mcg-web
Copy link
Member

mcg-web commented Apr 3, 2017

Here an example using relay mutation:

  • Schema
RootMutation:
    type: object
    config:
        fields:
            uploadFile:
                builder: "Relay::Mutation"
                builderConfig:
                    inputType: UploadFileInput
                    payloadType: UploadFilePayload
                    mutateAndGetPayload: "@=mutation('upload_file', [request, value['title']])"

UploadFilePayload:
    type: relay-mutation-payload
    config:
        fields:
            files: {type: "[String!]!" }

UploadFileInput:
    type: relay-mutation-input
    config:
        fields:
            title: {type: "String!"}
  • Mutation
    public function uploadFile(\Symfony\Component\HttpFoundation\Request $request, $title)
    {
        /** @var \Symfony\Component\HttpFoundation\FileBag; $requestFiles */
        $requestFiles = $request->files;
        if (!$requestFiles->has('myFile')) {
            throw new \Overblog\GraphQLBundle\Error\UserError(sprintf('File "%s" is required.', 'myFile')));
        }
        /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
        $file = $requestFiles->get('myFile');
        // here do some work on your uploaded file
        return [$title];
    }

@ooflorent done! :trollface:

@mcg-web mcg-web added this to the v0.10 milestone Sep 29, 2017
@mcg-web mcg-web modified the milestones: v0.10, v0.11 Nov 22, 2017
@mcg-web
Copy link
Member

mcg-web commented Jan 27, 2018

done here

@mcg-web mcg-web closed this as completed Jan 27, 2018
@SebastienTainon
Copy link
Contributor

SebastienTainon commented Feb 1, 2019

The link was not available anymore, here is the updated link of the documentation: https://github.com/overblog/GraphQLBundle/blob/master/docs/definitions/upload-files.md

(in particular, see this link for usage with apollo-upload-client)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants