The Wayback Machine - https://web.archive.org/web/20210206004820/https://github.com/dre1080/wp-graphql-upload
Skip to content
main
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
Feb 6, 2021
bin
Feb 6, 2021
src
Feb 6, 2021
Feb 6, 2021
Feb 6, 2021
Feb 6, 2021
Feb 6, 2021
Feb 6, 2021

README.md

WPGraphQL Upload

This plugin adds Upload support to the WPGraphQL plugin as specified by graphql-multipart-request-spec.

Requirements

Using this plugin requires having the WPGraphQL plugin installed and activated.

Activating / Using

Activate the plugin like you would any other WordPress plugin.

Once the plugin is active, the Upload scalar type will be available to your mutation input fields.

If you're using composer:

composer require dre1080/wp-graphql-upload

Usage

Then you can start using in your mutations like so:

register_graphql_mutation(
  'upload', [
      'inputFields' => [
          'file' => [
              'type' => ['non_null' => 'Upload'],
          ],
      ],
      'outputFields' => [
          'text' => [
              'type'    => 'String',
              'resolve' => function ($payload) {
                  return $payload['text'];
              },
          ],
      ],
      'mutateAndGetPayload' => function ($input) {
          if (!function_exists('wp_handle_sideload')) {
              require_once(ABSPATH . 'wp-admin/includes/file.php');
          }

          \wp_handle_sideload($input['file'], [
              'test_form' => false,
              'test_type' => false,
          ]);

          $text = 'Uploaded file was "' . $input['file']['name'] . '" ('. $input['file']['type']  .').';

          return ['text' => $text];
      }
  ]
);

About

Upload support and functionality for WPGraphQL

Resources

License

Releases

No releases published

Packages

No packages published