diff --git a/src/Appwrite/GraphQL/Types.php b/src/Appwrite/GraphQL/Types.php index fd51e83c2a..279cac2068 100644 --- a/src/Appwrite/GraphQL/Types.php +++ b/src/Appwrite/GraphQL/Types.php @@ -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. * diff --git a/src/Appwrite/GraphQL/Types/Assoc.php b/src/Appwrite/GraphQL/Types/Assoc.php new file mode 100644 index 0000000000..a2099f9b22 --- /dev/null +++ b/src/Appwrite/GraphQL/Types/Assoc.php @@ -0,0 +1,42 @@ +value, true); + } +} diff --git a/src/Appwrite/GraphQL/Types/Mapper.php b/src/Appwrite/GraphQL/Types/Mapper.php index 10758f4220..224f2b5717 100644 --- a/src/Appwrite/GraphQL/Types/Mapper.php +++ b/src/Appwrite/GraphQL/Types/Mapper.php @@ -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; diff --git a/tests/e2e/Services/GraphQL/AccountTest.php b/tests/e2e/Services/GraphQL/AccountTest.php index b24fc8b60c..0d2ccf62cc 100644 --- a/tests/e2e/Services/GraphQL/AccountTest.php +++ b/tests/e2e/Services/GraphQL/AccountTest.php @@ -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']; diff --git a/tests/e2e/Services/GraphQL/Base.php b/tests/e2e/Services/GraphQL/Base.php index 42f508fcae..e7601dff69 100644 --- a/tests/e2e/Services/GraphQL/Base.php +++ b/tests/e2e/Services/GraphQL/Base.php @@ -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: