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

@@ -10,30 +10,37 @@
*/
namespace IPS\blog\api\GraphQL\Mutations;
use GraphQL\Type\Definition\ObjectType;
use IPS\Api\GraphQL\SafeException;
use IPS\Api\GraphQL\TypeRegistry;
use IPS\blog\api\GraphQL\Types\EntryType;
use IPS\blog\Blog;
use IPS\blog\Entry;
use IPS\Content\Api\GraphQL\ItemMutator;
use IPS\Member;
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;
}
/**
* Create blog entry mutation for GraphQL API
*/
class _CreateEntry extends \IPS\Content\Api\GraphQL\ItemMutator
class CreateEntry extends ItemMutator
{
/**
* Class
*/
protected $class = \IPS\blog\Entry::class;
protected string $class = Entry::class;
/*
* @brief Query description
*/
public static $description = "Create a new blog entry";
public static string $description = "Create a new blog entry";
/*
* Mutation arguments
@@ -48,7 +55,7 @@ class _CreateEntry extends \IPS\Content\Api\GraphQL\ItemMutator
/**
* Return the mutation return type
*/
public function type()
public function type(): EntryType
{
return \IPS\blog\api\GraphQL\TypeRegistry::entry();
}
@@ -56,37 +63,38 @@ class _CreateEntry 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\blog\Blog
* @param mixed $val Value passed into this resolver
* @param array $args Arguments
* @param array $context Context values
* @param mixed $info
* @return Entry
*/
public function resolve($val, $args, $context, $info)
public function resolve( mixed $val, array $args, array $context, mixed $info): Entry
{
/* Get blog */
try
{
$blog = \IPS\blog\Blog::loadAndCheckPerms( $args['blogID'] );
$blog = Blog::loadAndCheckPerms( $args['blogID'] );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_BLOG', '1B300/1_graphql', 400 );
throw new SafeException( 'NO_BLOG', '1B300/1_graphql', 400 );
}
/* Check permission */
if ( !$blog->can( 'add', \IPS\Member::loggedIn() ) )
if ( !$blog->can( 'add', Member::loggedIn() ) )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', '1B300/A_graphql', 403 );
throw new SafeException( 'NO_PERMISSION', '1B300/A_graphql', 403 );
}
/* Check we have a title and a post */
if ( !$args['title'] )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_TITLE', '1B300/4_graphql', 400 );
throw new SafeException( 'NO_TITLE', '1B300/4_graphql', 400 );
}
if ( !$args['content'] )
{
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1B300/5_grapqhl', 400 );
throw new SafeException( 'NO_POST', '1B300/5_grapqhl', 400 );
}