Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+39 -25
View File
@@ -12,32 +12,46 @@
namespace IPS\Dispatcher;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DomainException;
use Exception;
use IPS\Api\GraphQL as GraphQLApi;
use IPS\Api\OAuthClient;
use IPS\IPS;
use IPS\Member;
use IPS\Request;
use OutOfRangeException;
use function defined;
use function in_array;
use function is_array;
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;
}
/* 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";
/**
* @brief API Dispatcher
*/
class _GraphQL extends Api
class GraphQL extends Api
{
/**
* @brief Path
*/
public $path = '/graphql';
public ?string $path = '/graphql';
/**
* Init
*
* @return void
* @throws \DomainException
* @throws DomainException
*/
public function init()
public function init() : void
{
try
{
@@ -52,27 +66,27 @@ class _GraphQL extends Api
if ( $this->rawAccessToken )
{
$this->_setAccessToken();
$client = \IPS\Api\OAuthClient::load( $this->accessToken['client_id'] );
$client = OAuthClient::load( $this->accessToken['client_id'] );
if( $client->api_access == 'rest' )
{
throw new \IPS\Api\Exception( 'NO_GRAPHQL_ACCESS', '3S426_graphql/1', 403 );
}
\IPS\Member::$loggedInMember = \IPS\Member::load( $this->accessToken['member_id'] );
Member::$loggedInMember = Member::load( $this->accessToken['member_id'] );
}
else
{
$client = \IPS\Api\OAuthClient::load( $this->rawApiKey );
$client = OAuthClient::load( $this->rawApiKey );
/* Check that the API key has access to the GraphQL API */
if( $client->api_access == 'rest' )
{
throw new \IPS\Api\Exception( 'NO_GRAPHQL_ACCESS', '3S426_graphql/1', 403 );
}
\IPS\Member::$loggedInMember = new \IPS\Member;
Member::$loggedInMember = new Member;
}
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_API_KEY', '3S290_graphql/7', 401 );
}
@@ -89,9 +103,9 @@ class _GraphQL extends Api
$response = json_encode( array( 'errors' => array( array( 'message' => $e->getMessage(), 'id' => $e->exceptionCode ) ) ), JSON_PRETTY_PRINT );
/* Do we need to log this? */
if ( \in_array( $e->exceptionCode, array( '2S290_graphql/8', '2S290_graphql/B', '3S290_graphql/7', '3S290_graphql/9' ) ) )
if ( in_array( $e->exceptionCode, array( '2S290_graphql/8', '2S290_graphql/B', '3S290_graphql/7', '3S290_graphql/9' ) ) )
{
$this->_log( $response, $e->getCode(), \in_array( $e->exceptionCode, array( '3S290/7', '3S290/9', '3S290/B' ) ) );
$this->_log( (array)$response, $e->getCode(), in_array( $e->exceptionCode, array( '3S290/7', '3S290/9', '3S290/B' ) ) );
}
/* Output */
@@ -104,26 +118,26 @@ class _GraphQL extends Api
*
* @return void
*/
public function run()
public function run() : void
{
try
{
/* Work out the query (can either use a JSON-encoded or form-encoded) body */
$query = NULL;
$variables = [];
if( \IPS\Request::i()->query )
if( Request::i()->query )
{
$query = \IPS\Request::i()->query;
$query = Request::i()->query;
if( isset( \IPS\Request::i()->variables ) )
if( isset( Request::i()->variables ) )
{
if( \is_array( \IPS\Request::i()->variables ) )
if( is_array( Request::i()->variables ) )
{
$variables = \IPS\Request::i()->variables;
$variables = Request::i()->variables;
}
else
{
$variables = json_decode( \IPS\Request::i()->variables, TRUE );
$variables = json_decode( Request::i()->variables, TRUE );
}
}
}
@@ -141,15 +155,15 @@ class _GraphQL extends Api
$this->_respond( json_encode( array( 'errors' => array( array( 'message' => 'NO_QUERY' ) ) ), JSON_PRETTY_PRINT ), 400 );
}
$output = \IPS\Api\GraphQL::execute( $query, $variables );
$output = GraphQLApi::execute( $query, $variables );
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $output );
Member::loggedIn()->language()->parseOutputForDisplay( $output );
$this->_respond( json_encode( $output, JSON_PRETTY_PRINT ), 200 );
}
catch ( \Exception $e )
catch ( Exception $e )
{
$response = json_encode( array( 'errors' => array( array( 'message' => ( \IPS\IN_DEV OR \IPS\DEBUG_GRAPHQL ) ? $e->getMessage() : 'UNKNOWN_ERROR', 'id' => $e->getCode() ) ) ), JSON_PRETTY_PRINT );
$response = json_encode( array( 'errors' => array( array( 'message' => ( \IPS\IN_DEV OR DEBUG_GRAPHQL ) ? $e->getMessage() : 'UNKNOWN_ERROR', 'id' => $e->getCode() ) ) ), JSON_PRETTY_PRINT );
$this->_respond( $response, 500 );
}
}