GraphQL add course query #2644

pull/2715/head
Angel Fernando Quiroz Campos 6 years ago
parent 7b9214373f
commit 8488fb7af7
  1. 22
      src/ApiBundle/GraphQL/Resolver/RootResolver.php
  2. 7
      src/ApiBundle/GraphQL/Resources/config/Query.types.yaml

@ -4,6 +4,7 @@
namespace Chamilo\ApiBundle\GraphQL\Resolver;
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\UserBundle\Entity\User;
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface;
@ -31,6 +32,7 @@ class RootResolver implements ResolverInterface, AliasedInterface, ContainerAwar
{
return [
'resolverViewer' => 'viewer',
'resolveCourse' => 'course',
];
}
@ -52,4 +54,24 @@ class RootResolver implements ResolverInterface, AliasedInterface, ContainerAwar
return $user;
}
/**
* @param int $courseId
* @param \ArrayObject $context
*
* @return Course|null
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Doctrine\ORM\TransactionRequiredException
*/
public function resolveCourse($courseId, \ArrayObject $context)
{
$this->checkAuthorization($context);
$course = $this->em->find('ChamiloCoreBundle:Course', $courseId);
$context->offsetSet('course', $course);
return $course;
}
}

@ -7,6 +7,13 @@ Query:
description: "A registered user on the platform."
type: "User"
resolve: "@=resolver('viewer', [context])"
course:
description: 'Get the data from a course on the platform.'
type: 'Course'
args:
id:
type: 'Int!'
resolve: "@=resolver('course', [args['id'], context])"
User:
type: object

Loading…
Cancel
Save