1
0
Fork 0
mirror of synced 2024-06-27 18:50:47 +12:00

Fix custom entity list

This commit is contained in:
Jake Barnby 2022-09-22 22:48:22 +12:00
parent 5f0f136e6e
commit 8cd36b2721
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
7 changed files with 82 additions and 41 deletions

View file

@ -555,7 +555,7 @@ return [
'code' => 400,
],
Exception::GRAPHQL_INVALID_QUERY => [
'name' => Exception::GRAPHQL_NO_QUERY,
'name' => Exception::GRAPHQL_INVALID_QUERY,
'description' => 'Invalid query.',
'code' => 400,
],

View file

@ -69,7 +69,7 @@
"chillerlan/php-qrcode": "4.3.3",
"adhocore/jwt": "1.1.2",
"slickdeals/statsd": "3.1.0",
"webonyx/graphql-php": "14.1.1"
"webonyx/graphql-php": "14.11.*"
},
"repositories": [
{

26
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "7e9d6c54d7578238100edc3c1d290506",
"content-hash": "69eba53723d6196f86161494e8cc7546",
"packages": [
{
"name": "adhocore/jwt",
@ -2838,33 +2838,33 @@
},
{
"name": "webonyx/graphql-php",
"version": "v14.1.1",
"version": "v14.11.8",
"source": {
"type": "git",
"url": "https://github.com/webonyx/graphql-php.git",
"reference": "d6fe86179a388abb0b671eec9688799b96673403"
"reference": "04a48693acd785330eefd3b0e4fa67df8dfee7c3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webonyx/graphql-php/zipball/d6fe86179a388abb0b671eec9688799b96673403",
"reference": "d6fe86179a388abb0b671eec9688799b96673403",
"url": "https://api.github.com/repos/webonyx/graphql-php/zipball/04a48693acd785330eefd3b0e4fa67df8dfee7c3",
"reference": "04a48693acd785330eefd3b0e4fa67df8dfee7c3",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-mbstring": "*",
"php": "^7.1||^8.0"
"php": "^7.1 || ^8"
},
"require-dev": {
"amphp/amp": "^2.3",
"doctrine/coding-standard": "^6.0",
"nyholm/psr7": "^1.2",
"phpbench/phpbench": "^0.16.10",
"phpbench/phpbench": "^1.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "0.12.32",
"phpstan/phpstan-phpunit": "0.12.11",
"phpstan/phpstan-strict-rules": "0.12.2",
"phpunit/phpunit": "^7.2|^8.5",
"phpstan/phpstan": "0.12.82",
"phpstan/phpstan-phpunit": "0.12.18",
"phpstan/phpstan-strict-rules": "0.12.9",
"phpunit/phpunit": "^7.2 || ^8.5",
"psr/http-message": "^1.0",
"react/promise": "2.*",
"simpod/php-coveralls-mirror": "^3.0",
@ -2892,7 +2892,7 @@
],
"support": {
"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": [
{
@ -2900,7 +2900,7 @@
"type": "open_collective"
}
],
"time": "2020-07-21T17:39:31+00:00"
"time": "2022-09-21T15:35:03+00:00"
}
],
"packages-dev": [

View file

@ -101,11 +101,7 @@ class Resolvers
$request = $utopia->getResource('request', true);
$response = $utopia->getResource('response', true);
$swoole = $request->getSwoole();
$swoole->post = [
'databaseId' => $databaseId,
'collectionId' => $collectionId,
'documentId' => $args['id'],
];
$swoole->server['request_method'] = 'GET';
$swoole->server['request_uri'] = "/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['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,
callable $resolve,
callable $reject,
?callable $beforeResolve = null,
?callable $beforeReject = null,
): void {
// Drop json content type so post args are used directly
if ($request->getHeader('content-type') === 'application/json') {
@ -298,6 +300,9 @@ class Resolvers
$utopia->execute($route, $request);
} catch (\Throwable $e) {
if ($beforeReject) {
$e = $beforeReject($e);
}
$reject($e);
return;
}
@ -305,6 +310,9 @@ class Resolvers
$payload = $response->getPayload();
if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 400) {
if ($beforeReject) {
$payload = $beforeReject($payload);
}
$reject(new GQLException(
message: $payload['message'],
code: $response->getStatusCode()
@ -320,6 +328,10 @@ class Resolvers
}
}
if ($beforeResolve) {
$payload = $beforeResolve($payload);
}
$resolve($payload);
}
}

View file

@ -3,6 +3,7 @@
namespace Appwrite\GraphQL;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model\None;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;
@ -217,9 +218,15 @@ class SchemaBuilder
$type = $attr->getAttribute('type');
$array = $attr->getAttribute('array');
$required = $attr->getAttribute('required');
$default = $attr->getAttribute('default');
$escapedKey = str_replace('$', '_', $key);
$collections[$collectionId][$escapedKey] = [
'type' => TypeMapper::typeFromAttribute($type, $array, $required),
'type' => TypeMapper::fromCollectionAttribute(
$type,
$array,
$required
),
'defaultValue' => $default,
];
}
@ -235,7 +242,7 @@ class SchemaBuilder
$attributes,
TypeRegistry::argumentsFor('mutate')
);
$queryFields[$collectionId . 'Get'] = [
'type' => $objectType,
'args' => TypeRegistry::argumentsFor('id'),
@ -247,7 +254,7 @@ class SchemaBuilder
)
];
$queryFields[$collectionId . 'List'] = [
'type' => $objectType,
'type' => Type::listOf($objectType),
'args' => TypeRegistry::argumentsFor('list'),
'resolve' => Resolvers::resolveDocumentList(
$utopia,
@ -255,8 +262,9 @@ class SchemaBuilder
$databaseId,
$collectionId
),
'complexity' => function(int $complexity, array $args) {
return $complexity * $args['limit'];
'complexity' => function (int $complexity, array $args) {
// FIXME: Update this for query limit
return $complexity; //* $args['limit'];
},
];
$mutationFields[$collectionId . 'Create'] = [

View file

@ -450,24 +450,22 @@ trait Base
}
}';
case self::$GET_CUSTOM_ENTITIES:
return 'query getCustomEntities($name: String!){
actorsList(name: $name) {
total
actors {
name
age
alive
salary
email
role
dob
ip
url
}
return 'query getCustomEntities {
actorsList {
_id
name
age
alive
salary
email
role
dob
ip
url
}
}';
case self::$GET_CUSTOM_ENTITY:
return 'query getCustomEntity($id: String!){
return 'query getCustomEntity($id: String!) {
actorsGet(id: $id) {
name
age

View file

@ -465,6 +465,7 @@ class DatabaseServerTest extends Scope
* @depends testCreateFloatAttribute
* @depends testCreateEmailAttribute
* @depends testCreateEnumAttribute
* @depends testCreateDatetimeAttribute
* @throws Exception
*/
public function testCreateCustomEntity(): array
@ -751,6 +752,28 @@ class DatabaseServerTest extends Scope
$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
* @throws Exception