Skip to content

Commit

Permalink
Merge pull request #14 from justlevine/release/0.1.5
Browse files Browse the repository at this point in the history
release: 0.1.5
  • Loading branch information
dre1080 authored Jul 17, 2023
2 parents 7dcb63a + 627d5d0 commit e45dfdc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Request/BodyParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public static function init()
*/
public static function processRequest(array $bodyParams, array $requestContext)
{
$contentType = isset($_SERVER['CONTENT_TYPE']) ? sanitize_text_field( wp_unslash( $_SERVER['CONTENT_TYPE'] ) ) : '';
$contentType = isset($_SERVER['CONTENT_TYPE']) ? sanitize_text_field(wp_unslash($_SERVER['CONTENT_TYPE'])) : '';

if ('POST' === $requestContext['method'] && stripos($contentType, 'multipart/form-data') !== false) {
if (empty($bodyParams['map'])) {
throw new RequestError('The request must define a `map`');
throw new RequestError(__('The request must define a `map`', 'wp-graphql-upload'));
}

$decodeJson = static function ($json) {
Expand Down
23 changes: 17 additions & 6 deletions src/Type/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function registerType()
$typeRegistry->register_scalar('Upload', [
'description' => sprintf(
// translators: %s is a link to the graphql-multipart-request-spec repo
__( 'The `Upload` special type represents a file to be uploaded in the same HTTP request as specified by [graphql-multipart-request-spec](%s).', 'wp-graphql-upload' ),
__('The `Upload` special type represents a file to be uploaded in the same HTTP request as specified by [graphql-multipart-request-spec](%s).', 'wp-graphql-upload'),
'https://github.com/jaydenseric/graphql-multipart-request-spec'
),
'serialize' => static function ($value) {
Expand All @@ -56,7 +56,7 @@ public static function registerType()
*/
public static function serialize($value)
{
throw new InvariantViolation('`Upload` cannot be serialized');
throw new InvariantViolation(__('`Upload` cannot be serialized', 'wp-graphql-upload'));
}

/**
Expand All @@ -68,13 +68,18 @@ public static function serialize($value)
public static function parseValue($value)
{
if (!static::arrayKeysExist($value, static::$validationFileKeys)) {
throw new UnexpectedValueException('Could not get uploaded file, be sure to conform to GraphQL multipart request specification. Instead got: ' . Utils::printSafe($value));
throw new UnexpectedValueException(
sprintf(
__('Could not get uploaded file, be sure to conform to GraphQL multipart request specification. Instead got: %s', 'wp-graphql-upload'),
Utils::printSafe($value)
)
);
}

// If not supplied, use the server's temp directory.
if (empty($value['tmp_name'])) {
$tmp_dir = get_temp_dir();
$value['tmp_name'] = $tmp_dir . wp_unique_filename($tmp_dir, $value['name']);
$tmp_dir = get_temp_dir();
$value['tmp_name'] = $tmp_dir . wp_unique_filename($tmp_dir, $value['name']);
}

return $value;
Expand All @@ -95,7 +100,13 @@ public static function parseValue($value)
*/
public static function parseLiteral($value, array $variables = null)
{
throw new Error('`Upload` cannot be hardcoded in query, be sure to conform to GraphQL multipart request specification. Instead got: ' . $value->kind, $value);
throw new Error(
sprintf(
__('`Upload` cannot be hardcoded in query, be sure to conform to GraphQL multipart request specification. Instead got: %s', 'wp-graphql-upload'),
$value->kind,
$value
)
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/BodyParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class BodyParserTest extends \WP_UnitTestCase
{
public function tearDown() : void
public function tearDown(): void
{
unset($_SERVER['CONTENT_TYPE'], $_FILES);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/UploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testCanParseUploadedFileInstanceWithoutTmpName(): void
$this->assertEquals($file['name'], $actual['name']);
$this->assertEquals($file['type'], $actual['type']);
$this->assertEquals($file['size'], $actual['size']);
$this->assertStringContainsString(get_temp_dir(),$actual['tmp_name']);
$this->assertStringContainsString(get_temp_dir(), $actual['tmp_name']);
}

public function testCannotParseNonUploadedFileInstance(): void
Expand Down
4 changes: 2 additions & 2 deletions wp-graphql-upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* or newer.
* Author: ando
* Author URI: http://github.com/dre1080
* Version: 0.1.4
* Version: 0.1.5
* Requires at least: 5.0
* Tested up to: 6.2.2
* Requires PHP: 7.1
Expand All @@ -17,7 +17,7 @@
* @package WPGraphQL\Upload
* @category WPGraphQL
* @author ando
* @version 0.1.4
* @version 0.1.5
*/

namespace WPGraphQL;
Expand Down

0 comments on commit e45dfdc

Please sign in to comment.