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
@@ -10,25 +10,30 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Content\Api\GraphQL\ItemMutator;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Topic;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark topic read mutation for GraphQL API
|
||||
*/
|
||||
class _MarkTopicRead extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
class MarkTopicRead extends ItemMutator
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Mark a topic as read";
|
||||
public static string $description = "Mark a topic as read";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -42,8 +47,10 @@ class _MarkTopicRead extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @reutrn TopicType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : TopicType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
@@ -51,25 +58,24 @@ class _MarkTopicRead extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Topic
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Topic
|
||||
{
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( $args['id'] );
|
||||
$topic = Topic::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', 'GQL/0005/1', 400 );
|
||||
throw new SafeException( 'NO_TOPIC', 'GQL/0005/1', 400 );
|
||||
}
|
||||
|
||||
if( !$topic->can('read') )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_ID', 'GQL/0005/2', 403 );
|
||||
throw new SafeException( 'INVALID_ID', 'GQL/0005/2', 403 );
|
||||
}
|
||||
|
||||
$this->_markRead( $topic );
|
||||
|
||||
Reference in new issue
Block a user