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,25 +11,31 @@
|
||||
|
||||
namespace IPS\core\api\GraphQL\Queries;
|
||||
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\ListOfType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\core\api\GraphQL\Types\MemberType;
|
||||
use IPS\Db;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function is_int;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Members query for GraphQL API
|
||||
*/
|
||||
class _Members
|
||||
class Members
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = 'Returns a list of members';
|
||||
public static string $description = 'Returns a list of members';
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -50,7 +56,7 @@ class _Members
|
||||
'type' => TypeRegistry::eNum( [
|
||||
'name' => 'member_order_by',
|
||||
'description' => 'Fields on which topics can be sorted',
|
||||
'values' => \IPS\core\api\GraphQL\Types\MemberType::getOrderByOptions()
|
||||
'values' => MemberType::getOrderByOptions()
|
||||
] ),
|
||||
'defaultValue' => NULL // will use default sort option
|
||||
],
|
||||
@@ -68,8 +74,10 @@ class _Members
|
||||
|
||||
/**
|
||||
* Return the query return type
|
||||
*
|
||||
* @return ListOfType<MemberType>
|
||||
*/
|
||||
public function type()
|
||||
public function type() : ListOfType
|
||||
{
|
||||
return TypeRegistry::listOf( \IPS\core\api\GraphQL\TypeRegistry::member() );
|
||||
}
|
||||
@@ -77,19 +85,20 @@ class _Members
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return [\IPS\Members]
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return ActiveRecordIterator
|
||||
*/
|
||||
public function resolve( $val, $args, $context, $info )
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : ActiveRecordIterator
|
||||
{
|
||||
$where = [];
|
||||
$sortBy = ( isset( $args['orderBy'] ) and \in_array( $args['orderBy'], \IPS\core\api\GraphQL\Types\MemberType::getOrderByOptions() ) ) ? $args['orderBy'] : 'member_id';
|
||||
$sortDir = ( isset( $args['orderDir'] ) and \in_array( mb_strtolower( $args['orderDir'] ), array( 'asc', 'desc' ) ) ) ? $args['orderDir'] : 'desc';
|
||||
$limit =( isset( $args['orderDir'] ) and \is_int( $args['limit'] ) ) ? $args['limit'] : 25;
|
||||
$sortBy = ( isset( $args['orderBy'] ) and in_array( $args['orderBy'], MemberType::getOrderByOptions() ) ) ? $args['orderBy'] : 'member_id';
|
||||
$sortDir = ( isset( $args['orderDir'] ) and in_array( mb_strtolower( $args['orderDir'] ), array( 'asc', 'desc' ) ) ) ? $args['orderDir'] : 'desc';
|
||||
$limit =( isset( $args['orderDir'] ) and is_int( $args['limit'] ) ) ? $args['limit'] : 25;
|
||||
|
||||
$query = \IPS\Db::i()->select( '*', 'core_members', $where, "{$sortBy} {$sortDir}", $limit );
|
||||
return new \IPS\Patterns\ActiveRecordIterator( $query, 'IPS\Member' );
|
||||
$query = Db::i()->select( '*', 'core_members', $where, "{$sortBy} {$sortDir}", $limit );
|
||||
return new ActiveRecordIterator( $query, 'IPS\Member' );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user