Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dre1080/wp-graphql-upload
Upload support and functionality for WPGraphQL as specified by graphql-multipart-request-spec.
https://github.com/dre1080/wp-graphql-upload
graphql graphql-upload upload wordpress wordpress-plugin wp-plugin wpgraphql wpgraphql-plugin
Last synced: 3 days ago
JSON representation
Upload support and functionality for WPGraphQL as specified by graphql-multipart-request-spec.
- Host: GitHub
- URL: https://github.com/dre1080/wp-graphql-upload
- Owner: dre1080
- License: gpl-3.0
- Created: 2021-02-06T00:21:02.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-08T00:36:54.000Z (4 months ago)
- Last Synced: 2024-08-11T08:53:25.705Z (3 months ago)
- Topics: graphql, graphql-upload, upload, wordpress, wordpress-plugin, wp-plugin, wpgraphql, wpgraphql-plugin
- Language: PHP
- Homepage:
- Size: 69.3 KB
- Stars: 33
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WPGraphQL Upload
This plugin adds Upload support to the [WPGraphQL plugin](https://github.com/wp-graphql/wp-graphql) as specified by [graphql-multipart-request-spec](https://github.com/jaydenseric/graphql-multipart-request-spec).
## Requirements
- PHP >= 7.1
- WordPress >= 5.0
- [WPGraphQL]((https://github.com/wp-graphql/wp-graphql)) >= 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:
```sh
composer require dre1080/wp-graphql-upload
```## Usage
Then you can start using in your mutations like so:
```php
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:
- [svn](https://subversion.apache.org/)
- [wp-cli](https://wp-cli.org/)To run the tests, run the following commands:
```sh
bin/install-wp-tests.sh
vendor/bin/phpunit
```