Fix assoc input for account prefs
This commit is contained in:
parent
5e9eccacd1
commit
cf9d67e9cc
5 changed files with 91 additions and 2 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Appwrite\GraphQL;
|
namespace Appwrite\GraphQL;
|
||||||
|
|
||||||
|
use Appwrite\GraphQL\Types\Assoc;
|
||||||
use Appwrite\GraphQL\Types\InputFile;
|
use Appwrite\GraphQL\Types\InputFile;
|
||||||
use Appwrite\GraphQL\Types\Json;
|
use Appwrite\GraphQL\Types\Json;
|
||||||
use Appwrite\GraphQL\Types\Registry;
|
use Appwrite\GraphQL\Types\Registry;
|
||||||
|
@ -24,6 +25,21 @@ class Types
|
||||||
return $type;
|
return $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the JSON type.
|
||||||
|
*
|
||||||
|
* @return Json
|
||||||
|
*/
|
||||||
|
public static function assoc(): Type
|
||||||
|
{
|
||||||
|
if (Registry::has(Assoc::class)) {
|
||||||
|
return Registry::get(Assoc::class);
|
||||||
|
}
|
||||||
|
$type = new Assoc();
|
||||||
|
Registry::set(Assoc::class, $type);
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the InputFile type.
|
* Get the InputFile type.
|
||||||
*
|
*
|
||||||
|
|
42
src/Appwrite/GraphQL/Types/Assoc.php
Normal file
42
src/Appwrite/GraphQL/Types/Assoc.php
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\GraphQL\Types;
|
||||||
|
|
||||||
|
use GraphQL\Language\AST\BooleanValueNode;
|
||||||
|
use GraphQL\Language\AST\FloatValueNode;
|
||||||
|
use GraphQL\Language\AST\IntValueNode;
|
||||||
|
use GraphQL\Language\AST\ListValueNode;
|
||||||
|
use GraphQL\Language\AST\Node;
|
||||||
|
use GraphQL\Language\AST\ObjectValueNode;
|
||||||
|
use GraphQL\Language\AST\StringValueNode;
|
||||||
|
use GraphQL\Type\Definition\ScalarType;
|
||||||
|
|
||||||
|
// https://github.com/webonyx/graphql-php/issues/129#issuecomment-309366803
|
||||||
|
class Assoc extends Json
|
||||||
|
{
|
||||||
|
public $name = 'Assoc';
|
||||||
|
public $description = 'The `Assoc` scalar type represents associative array values.';
|
||||||
|
|
||||||
|
public function serialize($value)
|
||||||
|
{
|
||||||
|
if (\is_string($value)) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return \json_encode($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parseValue($value)
|
||||||
|
{
|
||||||
|
if (\is_array($value)) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return \json_decode($value, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parseLiteral(Node $valueNode, ?array $variables = null)
|
||||||
|
{
|
||||||
|
return \json_decode($valueNode->value, true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -283,6 +283,8 @@ class Mapper
|
||||||
$type = Type::float();
|
$type = Type::float();
|
||||||
break;
|
break;
|
||||||
case 'Utopia\Validator\Assoc':
|
case 'Utopia\Validator\Assoc':
|
||||||
|
$type = Types::assoc();
|
||||||
|
break;
|
||||||
case 'Utopia\Validator\JSON':
|
case 'Utopia\Validator\JSON':
|
||||||
$type = Types::json();
|
$type = Types::json();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -432,6 +432,32 @@ class AccountTest extends Scope
|
||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUpdateAccountPrefs(): array
|
||||||
|
{
|
||||||
|
$projectId = $this->getProject()['$id'];
|
||||||
|
$query = $this->getQuery(self::$UPDATE_ACCOUNT_PREFS);
|
||||||
|
$graphQLPayload = [
|
||||||
|
'query' => $query,
|
||||||
|
'variables' => [
|
||||||
|
'prefs' => [
|
||||||
|
'key' => 'value'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$account = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $projectId,
|
||||||
|
], $this->getHeaders()), $graphQLPayload);
|
||||||
|
|
||||||
|
$this->assertArrayNotHasKey('errors', $account['body']);
|
||||||
|
$this->assertIsArray($account['body']['data']);
|
||||||
|
$this->assertIsArray($account['body']['data']['accountUpdatePrefs']);
|
||||||
|
$this->assertEquals(['data' => \json_encode(['key' => 'value'])], $account['body']['data']['accountUpdatePrefs']['prefs']);
|
||||||
|
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
|
||||||
public function testDeleteAccountSessions(): array
|
public function testDeleteAccountSessions(): array
|
||||||
{
|
{
|
||||||
$projectId = $this->getProject()['$id'];
|
$projectId = $this->getProject()['$id'];
|
||||||
|
|
|
@ -946,14 +946,17 @@ trait Base
|
||||||
}
|
}
|
||||||
}';
|
}';
|
||||||
case self::$UPDATE_ACCOUNT_PREFS:
|
case self::$UPDATE_ACCOUNT_PREFS:
|
||||||
return 'mutation updateAccountPrefs($userId: String!, $prefs: Json!){
|
return 'mutation updateAccountPrefs($prefs: Assoc!){
|
||||||
accountUpdatePrefs(userId: $userId, prefs: $prefs) {
|
accountUpdatePrefs(prefs: $prefs) {
|
||||||
_id
|
_id
|
||||||
name
|
name
|
||||||
registration
|
registration
|
||||||
status
|
status
|
||||||
email
|
email
|
||||||
emailVerification
|
emailVerification
|
||||||
|
prefs {
|
||||||
|
data
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}';
|
}';
|
||||||
case self::$UPDATE_ACCOUNT_STATUS:
|
case self::$UPDATE_ACCOUNT_STATUS:
|
||||||
|
|
Loading…
Reference in a new issue