diff --git a/config/packages/graphql.yaml b/config/packages/graphql.yaml index 20cb2b09a2..ce4928300c 100644 --- a/config/packages/graphql.yaml +++ b/config/packages/graphql.yaml @@ -6,7 +6,7 @@ overblog_graphql: resolver_maps: - '%chamilo_graphql.resolver_map.query.class%' - '%chamilo_graphql.resolver_map.enum.class%' - - '%chamilo_graphql.resolver_map.union.class%' + - '%chamilo_graphql.resolver_map.interface.class%' - '%chamilo_graphql.resolver_map.scalar.class%' - '%chamilo_graphql.resolver_map.mutation.class%' mappings: @@ -18,7 +18,7 @@ overblog_graphql: parameters: chamilo_graphql.resolver_map.query.class: Chamilo\GraphQlBundle\Map\QueryMap chamilo_graphql.resolver_map.enum.class: Chamilo\GraphQlBundle\Map\EnumMap - chamilo_graphql.resolver_map.union.class: Chamilo\GraphQlBundle\Map\UnionMap + chamilo_graphql.resolver_map.interface.class: Chamilo\GraphQlBundle\Map\InterfaceMap chamilo_graphql.resolver_map.scalar.class: Chamilo\GraphQlBundle\Map\ScalarMap chamilo_graphql.resolver_map.mutation.class: Chamilo\GraphQlBundle\Map\MutationMap diff --git a/src/GraphQlBundle/Map/InterfaceMap.php b/src/GraphQlBundle/Map/InterfaceMap.php new file mode 100644 index 0000000000..1e82e3c1ae --- /dev/null +++ b/src/GraphQlBundle/Map/InterfaceMap.php @@ -0,0 +1,36 @@ + [ + self::RESOLVE_TYPE => function (CTool $tool) { + $toolNames = CourseResolver::getAvailableTools(); + + return $toolNames[$tool->getName()]; + }, + ], + ]; + } +} diff --git a/src/GraphQlBundle/Map/UnionMap.php b/src/GraphQlBundle/Map/UnionMap.php deleted file mode 100644 index 2356f8a154..0000000000 --- a/src/GraphQlBundle/Map/UnionMap.php +++ /dev/null @@ -1,48 +0,0 @@ - [ - self::RESOLVE_TYPE => function (CTool $tool) { - switch ($tool->getName()) { - case TOOL_COURSE_DESCRIPTION: - return 'ToolDescription'; - case TOOL_ANNOUNCEMENT: - return 'ToolAnnouncements'; - case TOOL_NOTEBOOK: - return 'ToolNotebook'; - case TOOL_FORUM: - return 'ToolForums'; - case TOOL_CALENDAR_EVENT: - return 'ToolAgenda'; - case TOOL_DOCUMENT: - return 'ToolDocuments'; - case TOOL_LEARNPATH: - return 'ToolLearningPath'; - } - }, - ], - ]; - } -} diff --git a/src/GraphQlBundle/Resolver/CourseResolver.php b/src/GraphQlBundle/Resolver/CourseResolver.php index 8a2e179a04..3863fdd060 100644 --- a/src/GraphQlBundle/Resolver/CourseResolver.php +++ b/src/GraphQlBundle/Resolver/CourseResolver.php @@ -31,6 +31,22 @@ class CourseResolver implements ContainerAwareInterface { use GraphQLTrait; + /** + * @return array + */ + public static function getAvailableTools() + { + return [ + TOOL_COURSE_DESCRIPTION => 'ToolDescription', + TOOL_ANNOUNCEMENT => 'ToolAnnouncements', + TOOL_NOTEBOOK => 'ToolNotebook', + TOOL_FORUM => 'ToolForums', + TOOL_CALENDAR_EVENT => 'ToolAgenda', + TOOL_DOCUMENT => 'ToolDocuments', + TOOL_LEARNPATH => 'ToolLearningPath', + ]; + } + /** * @param Course $course * @param Argument $args @@ -94,7 +110,11 @@ class CourseResolver implements ContainerAwareInterface } if (empty($args['type'])) { - return $course->getTools($session); + return $course + ->getTools($session) + ->filter(function (CTool $tool) { + return array_key_exists($tool->getName(), self::getAvailableTools()); + }); } $criteria = Criteria::create() diff --git a/src/GraphQlBundle/Resources/config/schema.types.graphql b/src/GraphQlBundle/Resources/config/schema.types.graphql index d3be1d1e64..e03a07599a 100644 --- a/src/GraphQlBundle/Resources/config/schema.types.graphql +++ b/src/GraphQlBundle/Resources/config/schema.types.graphql @@ -100,7 +100,7 @@ type Course { } "Global summary of the course." -type ToolDescription { +type ToolDescription implements CourseTool { name: String category: String image: String @@ -117,7 +117,7 @@ type CourseDescription { } "Personal notes relevant to student or coursework." -type ToolNotebook { +type ToolNotebook implements CourseTool { name: String category: String image: String @@ -136,7 +136,7 @@ type CourseNote { } "Announcements related to the course." -type ToolAnnouncements { +type ToolAnnouncements implements CourseTool { name: String category: String image: String @@ -155,7 +155,7 @@ type CourseAnnouncement { } "Course forum tool." -type ToolForums { +type ToolForums implements CourseTool { name: String category: String image: String @@ -208,7 +208,7 @@ type CourseForumPost { } "A comprehensive diary/calendar tool" -type ToolAgenda { +type ToolAgenda implements CourseTool { name: String category: String image: String @@ -228,7 +228,7 @@ type CourseAgendaEvent { backgroundColor: String } -type ToolDocuments { +type ToolDocuments implements CourseTool { name: String category: String image: String @@ -248,7 +248,7 @@ type CourseDocument { } "A specific sequence of learning objects/experiences." -type ToolLearningPath { +type ToolLearningPath implements CourseTool { name: String category: String image: String @@ -298,9 +298,14 @@ type SessionCategory { endDate: DateTime } -# Unions +# Interfaces -union CourseTool = ToolDescription | ToolAnnouncements | ToolNotebook | ToolForums | ToolAgenda | ToolDocuments | ToolLearningPath +interface CourseTool { + name: String + category: String + image: String + customIcon: String +} # Enums