1
0
Fork 0
mirror of synced 2024-07-04 14:10:33 +12:00

Fix assoc input for account prefs

This commit is contained in:
Jake Barnby 2022-12-13 20:04:05 +13:00
parent 5e9eccacd1
commit cf9d67e9cc
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
5 changed files with 91 additions and 2 deletions

View file

@ -2,6 +2,7 @@
namespace Appwrite\GraphQL;
use Appwrite\GraphQL\Types\Assoc;
use Appwrite\GraphQL\Types\InputFile;
use Appwrite\GraphQL\Types\Json;
use Appwrite\GraphQL\Types\Registry;
@ -24,6 +25,21 @@ class Types
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.
*

View 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);
}
}

View file

@ -283,6 +283,8 @@ class Mapper
$type = Type::float();
break;
case 'Utopia\Validator\Assoc':
$type = Types::assoc();
break;
case 'Utopia\Validator\JSON':
$type = Types::json();
break;

View file

@ -432,6 +432,32 @@ class AccountTest extends Scope
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
{
$projectId = $this->getProject()['$id'];

View file

@ -946,14 +946,17 @@ trait Base
}
}';
case self::$UPDATE_ACCOUNT_PREFS:
return 'mutation updateAccountPrefs($userId: String!, $prefs: Json!){
accountUpdatePrefs(userId: $userId, prefs: $prefs) {
return 'mutation updateAccountPrefs($prefs: Assoc!){
accountUpdatePrefs(prefs: $prefs) {
_id
name
registration
status
email
emailVerification
prefs {
data
}
}
}';
case self::$UPDATE_ACCOUNT_STATUS: