mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Updated injections
This commit is contained in:
parent
beeb66e66d
commit
9fc0342cf1
4 changed files with 112 additions and 8 deletions
|
|
@ -24,12 +24,12 @@ use Utopia\System\System;
|
|||
Http::init()
|
||||
->groups(['graphql'])
|
||||
->inject('project')
|
||||
->inject('auth')
|
||||
->action(function (Document $project, Authorization $auth) {
|
||||
->inject('authorization')
|
||||
->action(function (Document $project, Authorization $authorization) {
|
||||
if (
|
||||
array_key_exists('graphql', $project->getAttribute('apis', []))
|
||||
&& !$project->getAttribute('apis', [])['graphql']
|
||||
&& !(Auth::isPrivilegedUser($auth->getRoles()) || Auth::isAppUser($auth->getRoles()))
|
||||
&& !(Auth::isPrivilegedUser($authorization->getRoles()) || Auth::isAppUser($authorization->getRoles()))
|
||||
) {
|
||||
throw new AppwriteException(AppwriteException::GENERAL_API_DISABLED);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -902,8 +902,7 @@ Http::get('/v1/messaging/providers/:providerId/logs')
|
|||
->inject('dbForProject')
|
||||
->inject('locale')
|
||||
->inject('geodb')
|
||||
->inject('authorization')
|
||||
->action(function (string $providerId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb, Authorization $authorization) {
|
||||
->action(function (string $providerId, array $queries, Response $response, Database $dbForProject, Locale $locale, Reader $geodb) {
|
||||
$provider = $dbForProject->getDocument('providers', $providerId);
|
||||
|
||||
if ($provider->isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -892,11 +892,11 @@ include_once 'api/avatars.php';
|
|||
include_once 'api/console.php';
|
||||
include_once 'api/databases.php';
|
||||
include_once 'api/functions.php';
|
||||
//include_once 'api/graphql.php';
|
||||
include_once 'api/graphql.php';
|
||||
include_once 'api/health.php';
|
||||
include_once 'api/locale.php';
|
||||
include_once 'api/messaging.php';
|
||||
//include_once 'api/migrations.php';
|
||||
include_once 'api/migrations.php';
|
||||
include_once 'api/project.php';
|
||||
include_once 'api/projects.php';
|
||||
include_once 'api/proxy.php';
|
||||
|
|
|
|||
107
app/init2.php
107
app/init2.php
|
|
@ -34,6 +34,8 @@ use Appwrite\Event\Messaging;
|
|||
use Appwrite\Event\Migration;
|
||||
use Appwrite\Event\Usage;
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\GraphQL\Promises\Adapter\Swoole;
|
||||
use Appwrite\GraphQL\Schema;
|
||||
use Appwrite\Hooks\Hooks;
|
||||
use Appwrite\Network\Validator\Origin;
|
||||
use Appwrite\URL\URL;
|
||||
|
|
@ -41,7 +43,6 @@ use Appwrite\Utopia\Queue\Connections;
|
|||
use MaxMind\Db\Reader;
|
||||
use Swoole\Database\PDOConfig;
|
||||
use Swoole\Database\PDOPool;
|
||||
use Swoole\Database\PDOProxy;
|
||||
use Swoole\Database\RedisConfig;
|
||||
use Swoole\Database\RedisPool;
|
||||
use Utopia\Cache\Adapter\None;
|
||||
|
|
@ -52,6 +53,7 @@ use Utopia\Database\Adapter\MariaDB;
|
|||
use Utopia\Database\Adapter\MySQL;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\DI\Container;
|
||||
|
|
@ -368,6 +370,10 @@ $global->set('smtp', function () {
|
|||
return $mail;
|
||||
});
|
||||
|
||||
$global->set('promiseAdapter', function () {
|
||||
return new Swoole();
|
||||
});
|
||||
|
||||
$mode = new Dependency();
|
||||
$mode
|
||||
->setName('mode')
|
||||
|
|
@ -1056,3 +1062,102 @@ $getProjectDB
|
|||
};
|
||||
});
|
||||
$container->set($getProjectDB);
|
||||
|
||||
$promiseAdapter = new Dependency();
|
||||
$promiseAdapter
|
||||
->setName('promiseAdapter')
|
||||
->inject('register')
|
||||
->setCallback(function ($register) {
|
||||
return $register->get('promiseAdapter');
|
||||
});
|
||||
$container->set($promiseAdapter);
|
||||
|
||||
$schema = new Dependency();
|
||||
$schema
|
||||
->setName('schema')
|
||||
->inject('utopia')
|
||||
->inject('dbForProject')
|
||||
->inject('auth')
|
||||
->setCallback(function (Http $utopia, Database $dbForProject, Authorization $auth) {
|
||||
$complexity = function (int $complexity, array $args) {
|
||||
$queries = Query::parseQueries($args['queries'] ?? []);
|
||||
$query = Query::getByType($queries, [Query::TYPE_LIMIT])[0] ?? null;
|
||||
$limit = $query ? $query->getValue() : APP_LIMIT_LIST_DEFAULT;
|
||||
|
||||
return $complexity * $limit;
|
||||
};
|
||||
|
||||
$attributes = function (int $limit, int $offset) use ($dbForProject, $auth) {
|
||||
$attrs = $auth->skip(fn () => $dbForProject->find('attributes', [
|
||||
Query::limit($limit),
|
||||
Query::offset($offset),
|
||||
]));
|
||||
|
||||
return \array_map(function ($attr) {
|
||||
return $attr->getArrayCopy();
|
||||
}, $attrs);
|
||||
};
|
||||
|
||||
$urls = [
|
||||
'list' => function (string $databaseId, string $collectionId, array $args) {
|
||||
return "/v1/databases/$databaseId/collections/$collectionId/documents";
|
||||
},
|
||||
'create' => function (string $databaseId, string $collectionId, array $args) {
|
||||
return "/v1/databases/$databaseId/collections/$collectionId/documents";
|
||||
},
|
||||
'read' => function (string $databaseId, string $collectionId, array $args) {
|
||||
return "/v1/databases/$databaseId/collections/$collectionId/documents/{$args['documentId']}";
|
||||
},
|
||||
'update' => function (string $databaseId, string $collectionId, array $args) {
|
||||
return "/v1/databases/$databaseId/collections/$collectionId/documents/{$args['documentId']}";
|
||||
},
|
||||
'delete' => function (string $databaseId, string $collectionId, array $args) {
|
||||
return "/v1/databases/$databaseId/collections/$collectionId/documents/{$args['documentId']}";
|
||||
},
|
||||
];
|
||||
|
||||
$params = [
|
||||
'list' => function (string $databaseId, string $collectionId, array $args) {
|
||||
return [ 'queries' => $args['queries']];
|
||||
},
|
||||
'create' => function (string $databaseId, string $collectionId, array $args) {
|
||||
$id = $args['id'] ?? 'unique()';
|
||||
$permissions = $args['permissions'] ?? null;
|
||||
|
||||
unset($args['id']);
|
||||
unset($args['permissions']);
|
||||
|
||||
return [
|
||||
'databaseId' => $databaseId,
|
||||
'documentId' => $id,
|
||||
'collectionId' => $collectionId,
|
||||
'data' => $args,
|
||||
'permissions' => $permissions,
|
||||
];
|
||||
},
|
||||
'update' => function (string $databaseId, string $collectionId, array $args) {
|
||||
$documentId = $args['id'];
|
||||
$permissions = $args['permissions'] ?? null;
|
||||
|
||||
unset($args['id']);
|
||||
unset($args['permissions']);
|
||||
|
||||
return [
|
||||
'databaseId' => $databaseId,
|
||||
'collectionId' => $collectionId,
|
||||
'documentId' => $documentId,
|
||||
'data' => $args,
|
||||
'permissions' => $permissions,
|
||||
];
|
||||
},
|
||||
];
|
||||
|
||||
return Schema::build(
|
||||
$utopia,
|
||||
$complexity,
|
||||
$attributes,
|
||||
$urls,
|
||||
$params,
|
||||
);
|
||||
});
|
||||
$container->set($schema);
|
||||
Loading…
Reference in a new issue