-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwp-graphql-enqueue.php
63 lines (57 loc) · 1.87 KB
/
wp-graphql-enqueue.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
<?php
/**
* Automatically add Enqueued Scripts and Styles to WPGraphQL
*
* @link https://github.com/emaildano/wp-graphql-enqueue
* @since 0.1.0
* @package WPGraphQL_Enqueue
*
* @wordpress-plugin
* Plugin Name: WPGraphQL for WordPress Scripts and Styles
* Plugin URI: https://github.com/emaildano/wp-graphql-enqueue
* Description: Automatically add Enqueued Scripts and Styles to WPGraphQL
* Version: 0.1.0
* Author: Daniel Olson
* Author URI: https://www.github.com/emaildano
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: wp-graphql-enqueue
* Domain Path: /languages
*/
add_action('graphql_register_types', 'register_enqueue');
function register_enqueue()
{
require('class-style-connection.php');
register_graphql_object_type('EnqueuedStyle', [
'description' => __("Man's best friend", 'wp-graphql-enqueue'),
'fields' => [
'handle' => [
'type' => 'String',
'description' => __('The style\'s registered handle.', 'wp-graphql-enqueue'),
],
'src' => [
'type' => 'String',
'description' => __('The source of the enqueued style.', 'wp-graphql-enqueue'),
],
'id' => [
'type' => 'ID',
'description' => __('The ID of the enqueued style.', 'wp-graphql-enqueue'),
'resolve' => function ($style) {
return $style['handle'];
}
],
],
]);
register_graphql_connection([
'fromType' => 'RootQuery',
'toType' => 'EnqueuedStyle',
'fromFieldName' => 'styles',
'resolve' => function ($source, $args, $context, $info) {
$resolver = new StyleConnectionResolver($source, $args, $context, $info);
return $resolver->get_connection();
},
// 'resolveNode' => function ($node) {
// wp_send_json($node);
// }
]);
}