-
Notifications
You must be signed in to change notification settings - Fork 1
/
NodeWithOrganizers.php
67 lines (61 loc) · 1.88 KB
/
NodeWithOrganizers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* GraphQL Interface Type - NodeWithOrganizers
*
* @package WPGraphQL\TEC\Events\Type\WPInterface;
* @since 0.0.1
*/
namespace WPGraphQL\TEC\Events\Type\WPInterface;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQLRelay\Relay;
use WPGraphQL\AppContext;
use WPGraphQL\Registry\TypeRegistry;
use WPGraphQL\TEC\Events\Data\OrganizerHelper;
use WPGraphQL\TEC\Events\Type\WPObject\Organizer;
/**
* Class - NodeWithOrganizers
*/
class NodeWithOrganizers {
/**
* Name of the type.
*
* @var string Type name.
*/
public static $type = 'NodeWithOrganizers';
/**
* Registers GraphQL Interface
*
* @param TypeRegistry $type_registry .
*/
public static function register_interface( TypeRegistry &$type_registry ): void {
register_graphql_interface_type(
self::$type,
[
'description' => __( 'Organizer Fields', 'wp-graphql-tec' ),
'connections' => [
'organizers' => [
'toType' => Organizer::$type,
'resolve' => function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
if ( empty( $source->organizerDatabaseIds ) ) {
return null;
}
$args['where']['post__in'] = $source->organizerDatabaseIds;
return OrganizerHelper::resolve_connection( $source, $args, $context, $info, 'tribe_organizer' );
},
],
],
'fields' => [
'organizerDatabaseIds' => [
'type' => [ 'list_of' => 'Int' ],
'description' => __( 'The list of organizer database IDs.', 'wp-graphql-tec' ),
],
'organizerIds' => [
'type' => [ 'list_of' => 'ID' ],
'description' => __( 'The list of organizer global IDs.', 'wp-graphql-tec' ),
'resolve' => fn( $source ) => ! empty( $source->organizerDatabaseIds ) ? array_map( fn( $id) => Relay::toGlobalId( 'tribe_organizer', (string) $id ), $source->organizerDatabaseIds ) : null,
],
],
]
);
}
}