Fix custom entity list
This commit is contained in:
parent
5f0f136e6e
commit
8cd36b2721
7 changed files with 82 additions and 41 deletions
|
@ -555,7 +555,7 @@ return [
|
||||||
'code' => 400,
|
'code' => 400,
|
||||||
],
|
],
|
||||||
Exception::GRAPHQL_INVALID_QUERY => [
|
Exception::GRAPHQL_INVALID_QUERY => [
|
||||||
'name' => Exception::GRAPHQL_NO_QUERY,
|
'name' => Exception::GRAPHQL_INVALID_QUERY,
|
||||||
'description' => 'Invalid query.',
|
'description' => 'Invalid query.',
|
||||||
'code' => 400,
|
'code' => 400,
|
||||||
],
|
],
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
"chillerlan/php-qrcode": "4.3.3",
|
"chillerlan/php-qrcode": "4.3.3",
|
||||||
"adhocore/jwt": "1.1.2",
|
"adhocore/jwt": "1.1.2",
|
||||||
"slickdeals/statsd": "3.1.0",
|
"slickdeals/statsd": "3.1.0",
|
||||||
"webonyx/graphql-php": "14.1.1"
|
"webonyx/graphql-php": "14.11.*"
|
||||||
},
|
},
|
||||||
"repositories": [
|
"repositories": [
|
||||||
{
|
{
|
||||||
|
|
26
composer.lock
generated
26
composer.lock
generated
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "7e9d6c54d7578238100edc3c1d290506",
|
"content-hash": "69eba53723d6196f86161494e8cc7546",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "adhocore/jwt",
|
"name": "adhocore/jwt",
|
||||||
|
@ -2838,33 +2838,33 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "webonyx/graphql-php",
|
"name": "webonyx/graphql-php",
|
||||||
"version": "v14.1.1",
|
"version": "v14.11.8",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/webonyx/graphql-php.git",
|
"url": "https://github.com/webonyx/graphql-php.git",
|
||||||
"reference": "d6fe86179a388abb0b671eec9688799b96673403"
|
"reference": "04a48693acd785330eefd3b0e4fa67df8dfee7c3"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/webonyx/graphql-php/zipball/d6fe86179a388abb0b671eec9688799b96673403",
|
"url": "https://api.github.com/repos/webonyx/graphql-php/zipball/04a48693acd785330eefd3b0e4fa67df8dfee7c3",
|
||||||
"reference": "d6fe86179a388abb0b671eec9688799b96673403",
|
"reference": "04a48693acd785330eefd3b0e4fa67df8dfee7c3",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"php": "^7.1||^8.0"
|
"php": "^7.1 || ^8"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"amphp/amp": "^2.3",
|
"amphp/amp": "^2.3",
|
||||||
"doctrine/coding-standard": "^6.0",
|
"doctrine/coding-standard": "^6.0",
|
||||||
"nyholm/psr7": "^1.2",
|
"nyholm/psr7": "^1.2",
|
||||||
"phpbench/phpbench": "^0.16.10",
|
"phpbench/phpbench": "^1.2",
|
||||||
"phpstan/extension-installer": "^1.0",
|
"phpstan/extension-installer": "^1.0",
|
||||||
"phpstan/phpstan": "0.12.32",
|
"phpstan/phpstan": "0.12.82",
|
||||||
"phpstan/phpstan-phpunit": "0.12.11",
|
"phpstan/phpstan-phpunit": "0.12.18",
|
||||||
"phpstan/phpstan-strict-rules": "0.12.2",
|
"phpstan/phpstan-strict-rules": "0.12.9",
|
||||||
"phpunit/phpunit": "^7.2|^8.5",
|
"phpunit/phpunit": "^7.2 || ^8.5",
|
||||||
"psr/http-message": "^1.0",
|
"psr/http-message": "^1.0",
|
||||||
"react/promise": "2.*",
|
"react/promise": "2.*",
|
||||||
"simpod/php-coveralls-mirror": "^3.0",
|
"simpod/php-coveralls-mirror": "^3.0",
|
||||||
|
@ -2892,7 +2892,7 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/webonyx/graphql-php/issues",
|
"issues": "https://github.com/webonyx/graphql-php/issues",
|
||||||
"source": "https://github.com/webonyx/graphql-php/tree/v14.1.1"
|
"source": "https://github.com/webonyx/graphql-php/tree/v14.11.8"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -2900,7 +2900,7 @@
|
||||||
"type": "open_collective"
|
"type": "open_collective"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2020-07-21T17:39:31+00:00"
|
"time": "2022-09-21T15:35:03+00:00"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
|
|
|
@ -101,11 +101,7 @@ class Resolvers
|
||||||
$request = $utopia->getResource('request', true);
|
$request = $utopia->getResource('request', true);
|
||||||
$response = $utopia->getResource('response', true);
|
$response = $utopia->getResource('response', true);
|
||||||
$swoole = $request->getSwoole();
|
$swoole = $request->getSwoole();
|
||||||
$swoole->post = [
|
|
||||||
'databaseId' => $databaseId,
|
|
||||||
'collectionId' => $collectionId,
|
|
||||||
'documentId' => $args['id'],
|
|
||||||
];
|
|
||||||
$swoole->server['request_method'] = 'GET';
|
$swoole->server['request_method'] = 'GET';
|
||||||
$swoole->server['request_uri'] = "/v1/databases/$databaseId/collections/$collectionId/documents/{$args['id']}";
|
$swoole->server['request_uri'] = "/v1/databases/$databaseId/collections/$collectionId/documents/{$args['id']}";
|
||||||
$swoole->server['path_info'] = "/v1/databases/$databaseId/collections/$collectionId/documents/{$args['id']}";
|
$swoole->server['path_info'] = "/v1/databases/$databaseId/collections/$collectionId/documents/{$args['id']}";
|
||||||
|
@ -145,7 +141,11 @@ class Resolvers
|
||||||
$swoole->server['request_uri'] = "/v1/databases/$databaseId/collections/$collectionId/documents";
|
$swoole->server['request_uri'] = "/v1/databases/$databaseId/collections/$collectionId/documents";
|
||||||
$swoole->server['path_info'] = "/v1/databases/$databaseId/collections/$collectionId/documents";
|
$swoole->server['path_info'] = "/v1/databases/$databaseId/collections/$collectionId/documents";
|
||||||
|
|
||||||
self::resolve($utopia, $request, $response, $resolve, $reject);
|
$beforeResolve = function ($payload) {
|
||||||
|
return $payload['documents'];
|
||||||
|
};
|
||||||
|
|
||||||
|
self::resolve($utopia, $request, $response, $resolve, $reject, $beforeResolve);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -283,6 +283,8 @@ class Resolvers
|
||||||
Response $response,
|
Response $response,
|
||||||
callable $resolve,
|
callable $resolve,
|
||||||
callable $reject,
|
callable $reject,
|
||||||
|
?callable $beforeResolve = null,
|
||||||
|
?callable $beforeReject = null,
|
||||||
): void {
|
): void {
|
||||||
// Drop json content type so post args are used directly
|
// Drop json content type so post args are used directly
|
||||||
if ($request->getHeader('content-type') === 'application/json') {
|
if ($request->getHeader('content-type') === 'application/json') {
|
||||||
|
@ -298,6 +300,9 @@ class Resolvers
|
||||||
|
|
||||||
$utopia->execute($route, $request);
|
$utopia->execute($route, $request);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
|
if ($beforeReject) {
|
||||||
|
$e = $beforeReject($e);
|
||||||
|
}
|
||||||
$reject($e);
|
$reject($e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -305,6 +310,9 @@ class Resolvers
|
||||||
$payload = $response->getPayload();
|
$payload = $response->getPayload();
|
||||||
|
|
||||||
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 400) {
|
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 400) {
|
||||||
|
if ($beforeReject) {
|
||||||
|
$payload = $beforeReject($payload);
|
||||||
|
}
|
||||||
$reject(new GQLException(
|
$reject(new GQLException(
|
||||||
message: $payload['message'],
|
message: $payload['message'],
|
||||||
code: $response->getStatusCode()
|
code: $response->getStatusCode()
|
||||||
|
@ -320,6 +328,10 @@ class Resolvers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($beforeResolve) {
|
||||||
|
$payload = $beforeResolve($payload);
|
||||||
|
}
|
||||||
|
|
||||||
$resolve($payload);
|
$resolve($payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Appwrite\GraphQL;
|
namespace Appwrite\GraphQL;
|
||||||
|
|
||||||
use Appwrite\Utopia\Response;
|
use Appwrite\Utopia\Response;
|
||||||
|
use Appwrite\Utopia\Response\Model\None;
|
||||||
use GraphQL\Type\Definition\ObjectType;
|
use GraphQL\Type\Definition\ObjectType;
|
||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
use GraphQL\Type\Schema;
|
use GraphQL\Type\Schema;
|
||||||
|
@ -217,9 +218,15 @@ class SchemaBuilder
|
||||||
$type = $attr->getAttribute('type');
|
$type = $attr->getAttribute('type');
|
||||||
$array = $attr->getAttribute('array');
|
$array = $attr->getAttribute('array');
|
||||||
$required = $attr->getAttribute('required');
|
$required = $attr->getAttribute('required');
|
||||||
|
$default = $attr->getAttribute('default');
|
||||||
$escapedKey = str_replace('$', '_', $key);
|
$escapedKey = str_replace('$', '_', $key);
|
||||||
$collections[$collectionId][$escapedKey] = [
|
$collections[$collectionId][$escapedKey] = [
|
||||||
'type' => TypeMapper::typeFromAttribute($type, $array, $required),
|
'type' => TypeMapper::fromCollectionAttribute(
|
||||||
|
$type,
|
||||||
|
$array,
|
||||||
|
$required
|
||||||
|
),
|
||||||
|
'defaultValue' => $default,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +242,7 @@ class SchemaBuilder
|
||||||
$attributes,
|
$attributes,
|
||||||
TypeRegistry::argumentsFor('mutate')
|
TypeRegistry::argumentsFor('mutate')
|
||||||
);
|
);
|
||||||
|
|
||||||
$queryFields[$collectionId . 'Get'] = [
|
$queryFields[$collectionId . 'Get'] = [
|
||||||
'type' => $objectType,
|
'type' => $objectType,
|
||||||
'args' => TypeRegistry::argumentsFor('id'),
|
'args' => TypeRegistry::argumentsFor('id'),
|
||||||
|
@ -247,7 +254,7 @@ class SchemaBuilder
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
$queryFields[$collectionId . 'List'] = [
|
$queryFields[$collectionId . 'List'] = [
|
||||||
'type' => $objectType,
|
'type' => Type::listOf($objectType),
|
||||||
'args' => TypeRegistry::argumentsFor('list'),
|
'args' => TypeRegistry::argumentsFor('list'),
|
||||||
'resolve' => Resolvers::resolveDocumentList(
|
'resolve' => Resolvers::resolveDocumentList(
|
||||||
$utopia,
|
$utopia,
|
||||||
|
@ -255,8 +262,9 @@ class SchemaBuilder
|
||||||
$databaseId,
|
$databaseId,
|
||||||
$collectionId
|
$collectionId
|
||||||
),
|
),
|
||||||
'complexity' => function(int $complexity, array $args) {
|
'complexity' => function (int $complexity, array $args) {
|
||||||
return $complexity * $args['limit'];
|
// FIXME: Update this for query limit
|
||||||
|
return $complexity; //* $args['limit'];
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
$mutationFields[$collectionId . 'Create'] = [
|
$mutationFields[$collectionId . 'Create'] = [
|
||||||
|
|
|
@ -450,24 +450,22 @@ trait Base
|
||||||
}
|
}
|
||||||
}';
|
}';
|
||||||
case self::$GET_CUSTOM_ENTITIES:
|
case self::$GET_CUSTOM_ENTITIES:
|
||||||
return 'query getCustomEntities($name: String!){
|
return 'query getCustomEntities {
|
||||||
actorsList(name: $name) {
|
actorsList {
|
||||||
total
|
_id
|
||||||
actors {
|
name
|
||||||
name
|
age
|
||||||
age
|
alive
|
||||||
alive
|
salary
|
||||||
salary
|
email
|
||||||
email
|
role
|
||||||
role
|
dob
|
||||||
dob
|
ip
|
||||||
ip
|
url
|
||||||
url
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}';
|
}';
|
||||||
case self::$GET_CUSTOM_ENTITY:
|
case self::$GET_CUSTOM_ENTITY:
|
||||||
return 'query getCustomEntity($id: String!){
|
return 'query getCustomEntity($id: String!) {
|
||||||
actorsGet(id: $id) {
|
actorsGet(id: $id) {
|
||||||
name
|
name
|
||||||
age
|
age
|
||||||
|
|
|
@ -465,6 +465,7 @@ class DatabaseServerTest extends Scope
|
||||||
* @depends testCreateFloatAttribute
|
* @depends testCreateFloatAttribute
|
||||||
* @depends testCreateEmailAttribute
|
* @depends testCreateEmailAttribute
|
||||||
* @depends testCreateEnumAttribute
|
* @depends testCreateEnumAttribute
|
||||||
|
* @depends testCreateDatetimeAttribute
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testCreateCustomEntity(): array
|
public function testCreateCustomEntity(): array
|
||||||
|
@ -751,6 +752,28 @@ class DatabaseServerTest extends Scope
|
||||||
$this->assertIsArray($document['body']['data']['databasesGetDocument']);
|
$this->assertIsArray($document['body']['data']['databasesGetDocument']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreateCustomEntity
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testGetCustomEntities($data)
|
||||||
|
{
|
||||||
|
$projectId = $this->getProject()['$id'];
|
||||||
|
$query = $this->getQuery(self::$GET_CUSTOM_ENTITIES);
|
||||||
|
$gqlPayload = [
|
||||||
|
'query' => $query,
|
||||||
|
];
|
||||||
|
|
||||||
|
$customEntities = $this->client->call(Client::METHOD_POST, '/graphql', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $projectId,
|
||||||
|
], $this->getHeaders()), $gqlPayload);
|
||||||
|
|
||||||
|
$this->assertArrayNotHasKey('errors', $customEntities['body']);
|
||||||
|
$this->assertIsArray($customEntities['body']['data']);
|
||||||
|
$this->assertIsArray($customEntities['body']['data']['actorsList']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testCreateCustomEntity
|
* @depends testCreateCustomEntity
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
|
Loading…
Reference in a new issue