-
Notifications
You must be signed in to change notification settings - Fork 3
/
graphql_api.graphql.inc
131 lines (130 loc) · 3.91 KB
/
graphql_api.graphql.inc
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* @file
*/
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\ObjectType;
/**
* Implements hook_graphql_info().
*
* @return array
*/
function graphql_api_graphql_api_info() {
return [
'types' => [
'field_item_link' => new ObjectType([
'name' => 'field_item_link',
'fields' => function() {
return [
'title' => [
'type' => Type::string(),
'description' => t('The title of the link.')
],
'url' => [
'type' => Type::string(),
'description' => t('The URL of the link.')
],
];
}
]),
'text_formatted' => new ObjectType(
[
'name' => 'text_formatted',
'fields' => [
'value' => [
'type' => Type::string(),
'description' => t('Text'),
],
'summary' => [
'type' => Type::string(),
'description' => t('Summary'),
],
'format' => [
'type' => Type::string(),
'description' => t('Text format'),
],
],
]
),
'image_styles' => new ObjectType([
'name' => 'image_styles',
'fields' => function () {
$fields = [];
foreach (image_styles() as $style_name => $info) {
$field_name = preg_replace('/[^_a-zA-Z0-9]/', '_', $style_name);
if (preg_match('/^[_a-zA-Z][_a-zA-Z0-9]*$/', $field_name)) {
$fields[$field_name] = [
'type' => Type::string(),
'description' => $info['label']
];
} else {
watchdog('GraphQL', "image_styles '{$style_name}' is ignored, not match pattern /^[_a-zA-Z][_a-zA-Z0-9]*$/");
}
}
return $fields;
}
]),
'field_item_file' => new ObjectType(
[
'name' => 'field_item_file',
'fields' => function () {
graphql_api()->addEntityGqlDefinition('file');
$type = graphql_api()->getInterfaceType('file');
return [
'file' => [
'type' => $type,
'description' => t('File'),
'resolve' => function ($value) {
if ($value) {
$file = file_load($value['fid']);
return entity_metadata_wrapper('file', $file);
}
return NULL;
},
],
'description' => [
'type' => Type::string(),
'description' => t('Alt'),
],
'display' => [
'type' => Type::string(),
'description' => t('Display'),
],
];
},
]
),
'field_item_image' => new ObjectType(
[
'name' => 'field_item_image',
'fields' => function () {
// graphql_api()->addEntityGqlDefinition('file');
// $type = graphql_api()->getObjectType('file');
return [
'fid' => [
'type' => Type::string(),
'description' => t('File ID'),
],
'description' => [
'type' => Type::string(),
'description' => t('Alt'),
],
'display' => [
'type' => Type::string(),
'description' => t('Display'),
],
'alt' => [
'type' => Type::string(),
'description' => t('Alt'),
],
'title' => [
'type' => Type::string(),
'description' => t('Title'),
],
];
},
]
)
],
];
}