WP Manifestindependent plugin directory
manifest / integrations / wp-graphql-upload

WPGraphQL Upload

Adds file upload support to the WP GraphQL Plugin.

★ 36stars
77kcomposer installs
v0.1.5latest · 3 years ago

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/dre1080/wp-graphql-upload/archive/refs/heads/main.zip

On Packagist as dre1080/wp-graphql-upload:

composer require dre1080/wp-graphql-upload
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

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

Requirements

  • PHP >= 7.1
  • WordPress >= 5.0
  • WPGraphQL >= 1.0.0

Activating / Using

You can install and activate the plugin like any WordPress plugin. Download the .zip from Github and add to your plugins directory, then activate.

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,
          ]);

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

Testing

Requirements:

To run the tests, run the following commands:

bin/install-wp-tests.sh
vendor/bin/phpunit

Releases

1 release.

Tag
Published
v0.1.5 latest
Jul 17, 2023 3 years ago

These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.