File uploads

With Buoy, you can upload files to your backend through a mutation. Just define the variables to contain the files your want to upload. Supported types are File FileList and Blob.

Preparing your backend

Your backend must support the graphql-multipart-request-spec. Lighthouse supports this out-of-the-box in the master branch. Follow their guide to enable file uploads in your schema.

Uploading a file

In order to upload files, simply add them as variables.

Example:

public uploadFile(): void {
    this.buoy.mutate(
        gql `
            mutation ($file: Upload!) {
                shareFile(file: $file) {
                    url
                }
            }
        `,
        {
            // Pick the first file form file-input
            file: this.file.nativeElement.files[0]
        },
        {
            scope: 'shareFile'
        }
    ).toPromise().then(
        (success) => {
            console.log('File was uploaded, and is available at:', success.url);
        },
        (error) => {
            console.log('ERROR', error);
        }
    );
}
Last Updated: 3/15/2019, 1:15:04 PM