graphqlitism
This commit is contained in:
parent
6ca330dd8b
commit
8492ae9ea4
4 changed files with 17 additions and 7 deletions
|
@ -86,7 +86,7 @@ class Image
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Query(name: "post_by_id")]
|
#[Query(name: "post")]
|
||||||
public static function by_id(int $id): ?Image
|
public static function by_id(int $id): ?Image
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
|
|
|
@ -7,17 +7,27 @@ namespace Shimmie2;
|
||||||
use GraphQL\GraphQL as GQL;
|
use GraphQL\GraphQL as GQL;
|
||||||
use GraphQL\Server\StandardServer;
|
use GraphQL\Server\StandardServer;
|
||||||
use GraphQL\Error\DebugFlag;
|
use GraphQL\Error\DebugFlag;
|
||||||
|
use GraphQL\Type\Schema;
|
||||||
use GraphQL\Utils\SchemaPrinter;
|
use GraphQL\Utils\SchemaPrinter;
|
||||||
|
|
||||||
class GraphQL extends Extension
|
class GraphQL extends Extension
|
||||||
{
|
{
|
||||||
|
public static function get_schema(): Schema
|
||||||
|
{
|
||||||
|
global $_tracer;
|
||||||
|
$_tracer->begin("Create Schema");
|
||||||
|
$schema = \GQLA\genSchema();
|
||||||
|
$_tracer->end(null);
|
||||||
|
return $schema;
|
||||||
|
}
|
||||||
|
|
||||||
public function onPageRequest(PageRequestEvent $event)
|
public function onPageRequest(PageRequestEvent $event)
|
||||||
{
|
{
|
||||||
global $page;
|
global $page;
|
||||||
if ($event->page_matches("graphql")) {
|
if ($event->page_matches("graphql")) {
|
||||||
$t1 = ftime();
|
$t1 = ftime();
|
||||||
$server = new StandardServer([
|
$server = new StandardServer([
|
||||||
'schema' => \GQLA\genSchema(),
|
'schema' => $this->get_schema(),
|
||||||
]);
|
]);
|
||||||
$t2 = ftime();
|
$t2 = ftime();
|
||||||
$resp = $server->executeRequest();
|
$resp = $server->executeRequest();
|
||||||
|
@ -36,13 +46,13 @@ class GraphQL extends Extension
|
||||||
{
|
{
|
||||||
if ($event->cmd == "help") {
|
if ($event->cmd == "help") {
|
||||||
print "\tgraphql <query string>\n";
|
print "\tgraphql <query string>\n";
|
||||||
print "\t\teg 'graphql \"{ post_by_id(id: 18) { id, hash } }\"'\n\n";
|
print "\t\teg 'graphql \"{ post(id: 18) { id, hash } }\"'\n\n";
|
||||||
print "\tgraphql-schema\n";
|
print "\tgraphql-schema\n";
|
||||||
print "\t\tdump the schema\n\n";
|
print "\t\tdump the schema\n\n";
|
||||||
}
|
}
|
||||||
if ($event->cmd == "graphql") {
|
if ($event->cmd == "graphql") {
|
||||||
$t1 = ftime();
|
$t1 = ftime();
|
||||||
$schema = \GQLA\genSchema();
|
$schema = $this->get_schema();
|
||||||
$t2 = ftime();
|
$t2 = ftime();
|
||||||
$debug = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::RETHROW_INTERNAL_EXCEPTIONS;
|
$debug = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::RETHROW_INTERNAL_EXCEPTIONS;
|
||||||
$body = GQL::executeQuery($schema, $event->args[0])->toArray($debug);
|
$body = GQL::executeQuery($schema, $event->args[0])->toArray($debug);
|
||||||
|
@ -53,7 +63,7 @@ class GraphQL extends Extension
|
||||||
echo \json_encode($body, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
|
echo \json_encode($body, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
|
||||||
}
|
}
|
||||||
if ($event->cmd == "graphql-schema") {
|
if ($event->cmd == "graphql-schema") {
|
||||||
$schema = \GQLA\genSchema();
|
$schema = $this->get_schema();
|
||||||
echo(SchemaPrinter::doPrint($schema));
|
echo(SchemaPrinter::doPrint($schema));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ class GraphQLTest extends ShimmiePHPUnitTestCase
|
||||||
{
|
{
|
||||||
public function testSchema()
|
public function testSchema()
|
||||||
{
|
{
|
||||||
$schema = \GQLA\genSchema();
|
$schema = GraphQL::get_schema();
|
||||||
$schema->assertValid();
|
$schema->assertValid();
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ class PM
|
||||||
return $pms;
|
return $pms;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Mutation("create_private_message")]
|
#[Mutation(name: "create_private_message")]
|
||||||
public static function send_pm(int $to_id, string $subject, string $message): bool
|
public static function send_pm(int $to_id, string $subject, string $message): bool
|
||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
|
|
Reference in a new issue