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,20 +10,21 @@
|
||||
*/
|
||||
|
||||
namespace IPS\blog\api\GraphQL;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\Types;
|
||||
use IPS\blog\api\GraphQL\Mutations\CreateEntry;
|
||||
use IPS\blog\api\GraphQL\Mutations\ReplyEntry;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blog mutationss GraphQL API
|
||||
*/
|
||||
abstract class _Mutation
|
||||
abstract class Mutation
|
||||
{
|
||||
/**
|
||||
* Get the supported query types in this app
|
||||
@@ -32,10 +33,9 @@ abstract class _Mutation
|
||||
*/
|
||||
public static function mutations(): array
|
||||
{
|
||||
$return = [
|
||||
'createEntry' => new \IPS\blog\api\GraphQL\Mutations\CreateEntry(),
|
||||
'replyEntry' => new \IPS\blog\api\GraphQL\Mutations\ReplyEntry(),
|
||||
return [
|
||||
'createEntry' => new CreateEntry(),
|
||||
'replyEntry' => new ReplyEntry(),
|
||||
];
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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\CommentType;
|
||||
use IPS\blog\Entry;
|
||||
use IPS\blog\Entry\Comment;
|
||||
use IPS\Content\Api\GraphQL\CommentMutator;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reply to entry mutation for GraphQL API
|
||||
*/
|
||||
class _ReplyEntry extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
class ReplyEntry extends CommentMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = \IPS\blog\Entry\Comment::class;
|
||||
protected string $class = Comment::class;
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Create a new comment";
|
||||
public static string $description = "Create a new comment";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -51,7 +58,7 @@ class _ReplyEntry extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*/
|
||||
public function type()
|
||||
public function type(): CommentType
|
||||
{
|
||||
return \IPS\blog\api\GraphQL\TypeRegistry::comment();
|
||||
}
|
||||
@@ -59,33 +66,34 @@ class _ReplyEntry extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\blog\Entry
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return Comment
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info): Comment
|
||||
{
|
||||
/* Get topic */
|
||||
try
|
||||
{
|
||||
$entry = \IPS\blog\Entry::loadAndCheckPerms( $args['entryID'] );
|
||||
$entry = Entry::loadAndCheckPerms( $args['entryID'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', '1F295/1_graphql', 403 );
|
||||
throw new SafeException( 'NO_TOPIC', '1F295/1_graphql', 403 );
|
||||
}
|
||||
|
||||
/* Get author */
|
||||
if ( !$entry->canComment( \IPS\Member::loggedIn() ) )
|
||||
if ( !$entry->canComment( Member::loggedIn() ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', '2F294/A_graphql', 403 );
|
||||
throw new SafeException( 'NO_PERMISSION', '2F294/A_graphql', 403 );
|
||||
}
|
||||
|
||||
/* Check we have a post */
|
||||
if ( !$args['content'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1F295/3_graphql', 403 );
|
||||
throw new SafeException( 'NO_POST', '1F295/3_graphql', 403 );
|
||||
}
|
||||
|
||||
$originalPost = NULL;
|
||||
@@ -94,9 +102,9 @@ class _ReplyEntry extends \IPS\Content\Api\GraphQL\CommentMutator
|
||||
{
|
||||
try
|
||||
{
|
||||
$originalPost = \IPS\blog\Entry\Comment::loadAndCheckPerms( $args['replyingTo'] );
|
||||
$originalPost = Comment::loadAndCheckPerms( $args['replyingTo'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
// Just ignore it
|
||||
}
|
||||
|
||||
@@ -10,25 +10,29 @@
|
||||
*/
|
||||
|
||||
namespace IPS\blog\api\GraphQL\Queries;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\blog\api\GraphQL\Types\BlogType;
|
||||
use IPS\blog\Blog as BlogObject;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blog query for GraphQL API
|
||||
*/
|
||||
class _Blog
|
||||
class Blog
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a Blog";
|
||||
public static string $description = "Returns a Blog";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -43,7 +47,7 @@ class _Blog
|
||||
/**
|
||||
* Return the query return type
|
||||
*/
|
||||
public function type()
|
||||
public function type(): BlogType
|
||||
{
|
||||
return \IPS\blog\api\GraphQL\TypeRegistry::blog();
|
||||
}
|
||||
@@ -51,18 +55,19 @@ class _Blog
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @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 array $info
|
||||
* @return BlogObject
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info): BlogObject
|
||||
{
|
||||
$blog = \IPS\blog\Blog::load( $args['id'] );
|
||||
$blog = BlogObject::load( $args[ 'id'] );
|
||||
|
||||
if( !$blog->can( 'view', $context['member'] ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
return $blog;
|
||||
}
|
||||
|
||||
@@ -10,25 +10,27 @@
|
||||
*/
|
||||
|
||||
namespace IPS\blog\api\GraphQL\Queries;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\ListOfType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\blog\Blog;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blogs query for GraphQL API
|
||||
*/
|
||||
class _Blogs
|
||||
class Blogs
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a list of blogs";
|
||||
public static string $description = "Returns a list of blogs";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -43,7 +45,7 @@ class _Blogs
|
||||
/**
|
||||
* Return the query return type
|
||||
*/
|
||||
public function type()
|
||||
public function type(): ListOfType
|
||||
{
|
||||
return TypeRegistry::listOf( \IPS\blog\api\GraphQL\TypeRegistry::blog() );
|
||||
}
|
||||
@@ -51,14 +53,15 @@ class _Blogs
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return array
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info): array
|
||||
{
|
||||
\IPS\blog\Blog::loadIntoMemory('view', $context['member']);
|
||||
return \IPS\blog\Blog::roots();
|
||||
Blog::loadIntoMemory('view', $context['member']);
|
||||
return Blog::roots();
|
||||
}
|
||||
}
|
||||
@@ -10,25 +10,35 @@
|
||||
*/
|
||||
|
||||
namespace IPS\blog\api\GraphQL\Queries;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use Exception;
|
||||
use GraphQL\Type\Definition\ListOfType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\blog\api\GraphQL\Types\EntryType;
|
||||
use IPS\blog\Blog;
|
||||
use IPS\blog\Entry;
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Topics query for GraphQL API
|
||||
*/
|
||||
class _Entries
|
||||
class Entries
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a list of blog entries";
|
||||
public static string $description = "Returns a list of blog entries";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -49,7 +59,7 @@ class _Entries
|
||||
'type' => TypeRegistry::eNum([
|
||||
'name' => 'blog_order_by',
|
||||
'description' => 'Fields on which event can be sorted',
|
||||
'values' => \IPS\blog\api\GraphQL\Types\EntryType::getOrderByOptions()
|
||||
'values' => EntryType::getOrderByOptions()
|
||||
]),
|
||||
'defaultValue' => NULL // will use default sort option
|
||||
],
|
||||
@@ -71,7 +81,7 @@ class _Entries
|
||||
/**
|
||||
* Return the query return type
|
||||
*/
|
||||
public function type()
|
||||
public function type(): ListOfType
|
||||
{
|
||||
return TypeRegistry::listOf( \IPS\blog\api\GraphQL\TypeRegistry::entry() );
|
||||
}
|
||||
@@ -79,29 +89,30 @@ class _Entries
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\blog\Entry
|
||||
* @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
|
||||
{
|
||||
\IPS\blog\Blog::loadIntoMemory('view', \IPS\Member::loggedIn() );
|
||||
Blog::loadIntoMemory('view', Member::loggedIn() );
|
||||
|
||||
$blogIds = [];
|
||||
|
||||
/* Are we filtering by blogs? */
|
||||
if( isset( $args['blogs'] ) && \count( $args['blogs'] ) )
|
||||
if( isset( $args['blogs'] ) && count( $args['blogs'] ) )
|
||||
{
|
||||
foreach( $args['blogs'] as $id )
|
||||
{
|
||||
$blog = \IPS\blog\Blog::loadAndCheckPerms( $id );
|
||||
$blog = Blog::loadAndCheckPerms( $id );
|
||||
$blogIds[] = $blog->id;
|
||||
}
|
||||
|
||||
if( \count( $blogIds ) )
|
||||
if( count( $blogIds ) )
|
||||
{
|
||||
$where['container'][] = array( \IPS\Db::i()->in( 'blog_blogs.blog_id', array_filter( $blogIds ) ) );
|
||||
$where['container'][] = array( Db::i()->in( 'blog_blogs.blog_id', array_filter( $blogIds ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,30 +125,30 @@ class _Entries
|
||||
}
|
||||
else
|
||||
{
|
||||
$orderBy = \IPS\blog\Entry::$databaseColumnMap[ $args['orderBy'] ];
|
||||
$orderBy = Entry::$databaseColumnMap[ $args['orderBy'] ];
|
||||
}
|
||||
|
||||
if( $args['orderBy'] === 'last_comment' )
|
||||
{
|
||||
$orderBy = \is_array( $orderBy ) ? array_pop( $orderBy ) : $orderBy;
|
||||
$orderBy = is_array( $orderBy ) ? array_pop( $orderBy ) : $orderBy;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
catch (Exception)
|
||||
{
|
||||
$orderBy = 'last_post';
|
||||
}
|
||||
|
||||
$sortBy = \IPS\blog\Entry::$databaseTable . '.' . \IPS\blog\Entry::$databasePrefix . "{$orderBy} {$args['orderDir']}";
|
||||
$sortBy = Entry::$databaseTable . '.' . Entry::$databasePrefix . "{$orderBy} {$args['orderDir']}";
|
||||
$offset = max( $args['offset'], 0 );
|
||||
$limit = min( $args['limit'], 50 );
|
||||
|
||||
/* Figure out pinned status */
|
||||
if ( $args['honorPinned'] )
|
||||
{
|
||||
$column = \IPS\blog\Entry::$databaseTable . '.' . \IPS\blog\Entry::$databasePrefix . \IPS\blog\Entry::$databaseColumnMap['pinned'];
|
||||
$column = Entry::$databaseTable . '.' . Entry::$databasePrefix . Entry::$databaseColumnMap['pinned'];
|
||||
$sortBy = "{$column} DESC, {$sortBy}";
|
||||
}
|
||||
|
||||
return \IPS\blog\Entry::getItemsWithPermission( $where, $sortBy, array( $offset, $limit ), 'read' );
|
||||
return Entry::getItemsWithPermission( $where, $sortBy, array( $offset, $limit ) );
|
||||
}
|
||||
}
|
||||
@@ -10,25 +10,29 @@
|
||||
*/
|
||||
|
||||
namespace IPS\blog\api\GraphQL\Queries;
|
||||
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\Entry as EntryClass;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry query for GraphQL API
|
||||
*/
|
||||
class _Entry
|
||||
class Entry
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a Blog Entry";
|
||||
public static string $description = "Returns a Blog Entry";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -43,7 +47,7 @@ class _Entry
|
||||
/**
|
||||
* Return the query return type
|
||||
*/
|
||||
public function type()
|
||||
public function type(): EntryType
|
||||
{
|
||||
return \IPS\blog\api\GraphQL\TypeRegistry::entry();
|
||||
}
|
||||
@@ -51,25 +55,26 @@ class _Entry
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\blog\Entry
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
{
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return EntryClass
|
||||
*/
|
||||
public function resolve( mixed $val, array $args, array $context, array $info): EntryClass
|
||||
{
|
||||
try
|
||||
{
|
||||
$entry = \IPS\blog\Entry::loadAndCheckPerms( $args['id'] );
|
||||
$entry = EntryClass::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TOPIC', '2B300/A_graphql', 400 );
|
||||
throw new SafeException( 'NO_TOPIC', '2B300/A_graphql', 400 );
|
||||
}
|
||||
|
||||
if( !$entry->can('read') )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', '2B300/9_graphql', 403 );
|
||||
throw new SafeException( 'NO_PERMISSION', '2B300/9_graphql', 403 );
|
||||
}
|
||||
|
||||
return $entry;
|
||||
|
||||
@@ -10,20 +10,23 @@
|
||||
*/
|
||||
|
||||
namespace IPS\blog\api\GraphQL;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\Types;
|
||||
use IPS\blog\api\GraphQL\Queries\Blog;
|
||||
use IPS\blog\api\GraphQL\Queries\Blogs;
|
||||
use IPS\blog\api\GraphQL\Queries\Entries;
|
||||
use IPS\blog\api\GraphQL\Queries\Entry;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blog queries for GraphQL API
|
||||
*/
|
||||
abstract class _Query
|
||||
abstract class Query
|
||||
{
|
||||
/**
|
||||
* Get the supported query types in this app
|
||||
@@ -33,10 +36,10 @@ abstract class _Query
|
||||
public static function queries(): array
|
||||
{
|
||||
return [
|
||||
'blogs' => new \IPS\blog\api\GraphQL\Queries\Blogs(),
|
||||
'blog' => new \IPS\blog\api\GraphQL\Queries\Blog(),
|
||||
'entries' => new \IPS\blog\api\GraphQL\Queries\Entries(),
|
||||
'entry' => new \IPS\blog\api\GraphQL\Queries\Entry(),
|
||||
'blogs' => new Blogs(),
|
||||
'blog' => new Blog(),
|
||||
'entries' => new Entries(),
|
||||
'entry' => new Entry(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -10,37 +10,38 @@
|
||||
*/
|
||||
|
||||
namespace IPS\blog\api\GraphQL;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\Types;
|
||||
use IPS\blog\api\GraphQL\Types\_BlogType;
|
||||
use IPS\blog\api\GraphQL\Types\BlogType;
|
||||
use IPS\blog\api\GraphQL\Types\CommentType;
|
||||
use IPS\blog\api\GraphQL\Types\EntryType;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
class _TypeRegistry
|
||||
class TypeRegistry
|
||||
{
|
||||
/**
|
||||
* The blog type instance
|
||||
* @var \IPS\blog\api\GraphQL\Types\BlogType
|
||||
* @var BlogType
|
||||
*/
|
||||
protected static $blog;
|
||||
protected static BlogType $blog;
|
||||
|
||||
/**
|
||||
* The blog entry type instance
|
||||
* @var \IPS\blog\api\GraphQL\Types\EntryType
|
||||
* @var EntryType
|
||||
*/
|
||||
protected static $entry;
|
||||
protected static EntryType $entry;
|
||||
|
||||
/**
|
||||
* The entry comment instance
|
||||
* @var \IPS\blog\api\GraphQL\Types\CommentType
|
||||
* @var CommentType
|
||||
*/
|
||||
protected static $comment;
|
||||
protected static CommentType $comment;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -53,24 +54,24 @@ class _TypeRegistry
|
||||
/**
|
||||
* @return BlogType
|
||||
*/
|
||||
public static function blog(): \IPS\blog\api\GraphQL\Types\BlogType
|
||||
public static function blog(): BlogType
|
||||
{
|
||||
return self::$blog ?: (self::$blog = new \IPS\blog\api\GraphQL\Types\BlogType());
|
||||
return self::$blog ?? (self::$blog = new BlogType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EntryType
|
||||
*/
|
||||
public static function entry(): \IPS\blog\api\GraphQL\Types\EntryType
|
||||
public static function entry(): EntryType
|
||||
{
|
||||
return self::$entry ?: (self::$entry = new \IPS\blog\api\GraphQL\Types\EntryType());
|
||||
return self::$entry ?? (self::$entry = new EntryType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CommentType
|
||||
*/
|
||||
public static function comment(): \IPS\blog\api\GraphQL\Types\CommentType
|
||||
public static function comment(): CommentType
|
||||
{
|
||||
return self::$comment ?: (self::$comment = new \IPS\blog\api\GraphQL\Types\CommentType());
|
||||
return self::$comment??( self::$comment = new CommentType() );
|
||||
}
|
||||
}
|
||||
@@ -11,39 +11,42 @@
|
||||
|
||||
namespace IPS\blog\api\GraphQL\Types;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\blog\api\GraphQL\TypeRegistry;
|
||||
use IPS\blog\Blog;
|
||||
use IPS\Node\Api\GraphQL\NodeType;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* BlogType for GraphQL API
|
||||
*/
|
||||
class _BlogType extends \IPS\Node\Api\GraphQL\NodeType
|
||||
class BlogType extends NodeType
|
||||
{
|
||||
/*
|
||||
* @brief The item classname we use for this type
|
||||
*/
|
||||
protected static $nodeClass = \IPS\blog\Blog::class;
|
||||
protected static string $nodeClass = Blog::class;
|
||||
|
||||
/*
|
||||
* @brief GraphQL type name
|
||||
*/
|
||||
protected static $typeName = 'blog_Blog';
|
||||
protected static string $typeName = 'blog_Blog';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type description
|
||||
*/
|
||||
protected static $typeDescription = 'A blog';
|
||||
protected static string $typeDescription = 'A blog';
|
||||
|
||||
/*
|
||||
* @brief Follow data passed in to FollowType resolver
|
||||
*/
|
||||
protected static $followData = array('app' => 'blog', 'area' => 'blog');
|
||||
protected static array $followData = array('app' => 'blog', 'area' => 'blog');
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,8 +54,8 @@ class _BlogType extends \IPS\Node\Api\GraphQL\NodeType
|
||||
*
|
||||
* @return ObjectType
|
||||
*/
|
||||
public static function getItemType()
|
||||
{
|
||||
return \IPS\blog\api\GraphQL\TypeRegistry::entry();
|
||||
public static function getItemType(): ObjectType
|
||||
{
|
||||
return TypeRegistry::entry();
|
||||
}
|
||||
}
|
||||
@@ -11,43 +11,46 @@
|
||||
|
||||
namespace IPS\blog\api\GraphQL\Types;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\blog\api\GraphQL\TypeRegistry;
|
||||
use IPS\blog\Entry\Comment;
|
||||
use IPS\Content\Api\GraphQL\CommentType as ApiCommentType;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* PostType for GraphQL API
|
||||
*/
|
||||
class _CommentType extends \IPS\Content\Api\GraphQL\CommentType
|
||||
class CommentType extends ApiCommentType
|
||||
{
|
||||
/*
|
||||
* @brief The item classname we use for this type
|
||||
*/
|
||||
protected static $commentClass = \IPS\blog\Entry\Comment::class;
|
||||
protected static string $commentClass = Comment::class;
|
||||
|
||||
/*
|
||||
* @brief GraphQL type name
|
||||
*/
|
||||
protected static $typeName = 'blog_Comment';
|
||||
protected static string $typeName = 'blog_Comment';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type description
|
||||
*/
|
||||
protected static $typeDescription = 'A blog comment';
|
||||
protected static string $typeDescription = 'A blog comment';
|
||||
|
||||
/**
|
||||
* Get the item type that goes with this item type
|
||||
*
|
||||
* @return ObjectType
|
||||
*/
|
||||
public static function getItemType()
|
||||
{
|
||||
return \IPS\blog\api\GraphQL\TypeRegistry::comment();
|
||||
public static function getItemType(): ObjectType
|
||||
{
|
||||
return TypeRegistry::comment();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,12 +58,12 @@ class _CommentType extends \IPS\Content\Api\GraphQL\CommentType
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fields()
|
||||
{
|
||||
public function fields(): array
|
||||
{
|
||||
$defaultFields = parent::fields();
|
||||
$postFields = array(
|
||||
'entry' => [
|
||||
'type' => \IPS\blog\api\GraphQL\TypeRegistry::entry(),
|
||||
'type' => TypeRegistry::entry(),
|
||||
'resolve' => function ($comment) {
|
||||
return $comment->item();
|
||||
}
|
||||
|
||||
@@ -11,48 +11,50 @@
|
||||
|
||||
namespace IPS\blog\api\GraphQL\Types;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\_TypeRegistry;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\blog\api\GraphQL\TypeRegistry;
|
||||
use IPS\blog\Entry;
|
||||
use IPS\Content\Api\GraphQL\ItemType;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry for GraphQL API
|
||||
*/
|
||||
class _EntryType extends \IPS\Content\Api\GraphQL\ItemType
|
||||
class EntryType extends ItemType
|
||||
{
|
||||
/*
|
||||
* @brief The item classname we use for this type
|
||||
*/
|
||||
protected static $itemClass = \IPS\blog\Entry::class;
|
||||
protected static string $itemClass = Entry::class;
|
||||
|
||||
/*
|
||||
* @brief GraphQL type name
|
||||
*/
|
||||
protected static $typeName = 'blog_Entry';
|
||||
protected static string $typeName = 'blog_Entry';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type description
|
||||
*/
|
||||
protected static $typeDescription = 'A blog entry';
|
||||
protected static string $typeDescription = 'A blog entry';
|
||||
|
||||
/*
|
||||
* @brief Follow data passed in to FollowType resolver
|
||||
*/
|
||||
protected static $followData = array('app' => 'blogs', 'area' => 'entry');
|
||||
protected static array $followData = array('app' => 'blogs', 'area' => 'entry');
|
||||
|
||||
/**
|
||||
* Get the comment type that goes with this item type
|
||||
*
|
||||
* @return ObjectType
|
||||
*/
|
||||
protected static function getCommentType()
|
||||
{
|
||||
return \IPS\blog\api\GraphQL\TypeRegistry::comment();
|
||||
protected static function getCommentType(): ObjectType
|
||||
{
|
||||
return TypeRegistry::comment();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user