Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -11,16 +11,26 @@
|
||||
namespace IPS\Api;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use GraphQL\Error\DebugFlag;
|
||||
use GraphQL\GraphQL as _GraphQL;
|
||||
use GraphQL\Type\Schema;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\IPS;
|
||||
use IPS\Member;
|
||||
use function defined;
|
||||
use const IPS\DEBUG_GRAPHQL;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Base API Controller
|
||||
*/
|
||||
class _GraphQL
|
||||
class GraphQL
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
@@ -33,20 +43,20 @@ class _GraphQL
|
||||
*
|
||||
* @param string $query The query to execute
|
||||
* @param array $variables Variables to include in query
|
||||
* @param \IPS\Member|NULL $member Member to check or NULL for currently logged in member.
|
||||
* @param Member|null $member Member to check or NULL for currently logged in member.
|
||||
* @return array GraphQL response
|
||||
*/
|
||||
public static function execute( string $query, array $variables = [], ?\IPS\Member $member = NULL )
|
||||
public static function execute( string $query, array $variables = [], ?Member $member = NULL ) : array
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
$member = $member ?: Member::loggedIn();
|
||||
/* Register our GraphQL library */
|
||||
\IPS\IPS::$PSR0Namespaces['GraphQL'] = \IPS\ROOT_PATH . "/system/3rd_party/graphql-php";
|
||||
IPS::$PSR0Namespaces['GraphQL'] = \IPS\ROOT_PATH . "/system/3rd_party/graphql-php";
|
||||
|
||||
/* Execute! */
|
||||
$result = \GraphQL\GraphQL::executeQuery(
|
||||
new \GraphQL\Type\Schema([
|
||||
'query' => \IPS\Api\GraphQL\TypeRegistry::query(),
|
||||
'mutation' => \IPS\Api\GraphQL\TypeRegistry::mutation()
|
||||
$result = _GraphQL::executeQuery(
|
||||
new Schema([
|
||||
'query' => TypeRegistry::query(),
|
||||
'mutation' => TypeRegistry::mutation()
|
||||
]),
|
||||
$query,
|
||||
NULL, // $rootValue
|
||||
@@ -57,7 +67,6 @@ class _GraphQL
|
||||
);
|
||||
|
||||
/* Convert result into JSON and send */
|
||||
$output = $result->toArray( ( \IPS\IN_DEV OR \IPS\DEBUG_GRAPHQL ) ? \GraphQL\Error\DebugFlag::INCLUDE_DEBUG_MESSAGE | \GraphQL\Error\DebugFlag::INCLUDE_TRACE : false );
|
||||
return $output;
|
||||
return $result->toArray( ( \IPS\IN_DEV OR DEBUG_GRAPHQL ) ? DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE : false );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user