@@ -13,151 +13,104 @@ use GraphQL\Type\Definition\ObjectType;
13
13
function graphql_api_graphql_api_info () {
14
14
return [
15
15
'types ' => [
16
- 'text_formatted ' => new ObjectType ([
17
- 'name ' => 'text_formatted ' ,
18
- 'fields ' => [
19
- 'value ' => array (
20
- 'type ' => Type::string (),
21
- 'description ' => t ('Text ' ),
22
- ),
23
- 'summary ' => array (
24
- 'type ' => Type::string (),
25
- 'description ' => t ('Summary ' ),
26
- ),
27
- 'format ' => array (
28
- 'type ' => Type::string (),
29
- 'description ' => t ('Text format ' ),
30
- ),
31
- ]
32
- ]),
33
- 'field_item_file ' => new ObjectType ([
34
- 'name ' => 'field_item_file ' ,
35
- 'fields ' => function () {
36
- $ schema = graphql_api ();
37
- $ file_type = $ schema ->getObjectType ('file_file ' );
38
- if (module_exists ('file_entity ' )) {
39
- $ file_type = $ schema ->getInterfaceType ('file ' );
40
- }
41
- return [
42
- 'description ' => [
43
- 'type ' => Type::string (),
44
- 'description ' => t ('Alt ' )
16
+ 'text_formatted ' => new ObjectType (
17
+ [
18
+ 'name ' => 'text_formatted ' ,
19
+ 'fields ' => [
20
+ 'value ' => [
21
+ 'type ' => Type::string (),
22
+ 'description ' => t ('Text ' ),
45
23
],
46
- 'display ' => [
47
- 'type ' => Type::string (),
48
- 'description ' => t ('Display ' )
24
+ 'summary ' => [
25
+ 'type ' => Type::string (),
26
+ 'description ' => t ('Summary ' ),
49
27
],
50
- 'file ' => [
51
- 'type ' => $ file_type ,
52
- 'description ' => t ('File ' )
53
- ]
54
- ];
55
- }
56
- ] ),
57
- 'field_item_image ' => new ObjectType ([
58
- 'name ' => 'field_item_image ' ,
28
+ 'format ' => [
29
+ 'type ' => Type:: string () ,
30
+ 'description ' => t ('Text format ' ),
31
+ ],
32
+ ],
33
+ ]
34
+ ),
35
+ 'image_styles ' => new ObjectType ([
36
+ 'name ' => 'image_styles ' ,
59
37
'fields ' => function () {
60
- $ schema = graphql_api ();
61
- $ file_type = $ schema ->getObjectType ('file_file ' );
62
- if (module_exists ('file_entity ' )) {
63
- $ file_type = $ schema ->getInterfaceType ('file ' );
38
+ $ fields = [];
39
+ foreach (image_styles () as $ style_name => $ info ) {
40
+ $ field_name = preg_replace ('/[^_a-zA-Z0-9]/ ' , '_ ' , $ style_name );
41
+ if (preg_match ('/^[_a-zA-Z][_a-zA-Z0-9]*$/ ' , $ field_name )) {
42
+ $ fields [$ field_name ] = [
43
+ 'type ' => Type::string (),
44
+ 'description ' => $ info ['label ' ]
45
+ ];
46
+ } else {
47
+ watchdog ('GraphQL ' , "image_styles ' {$ style_name }' is ignored, not match pattern /^[_a-zA-Z][_a-zA-Z0-9]*$/ " );
48
+ }
64
49
}
65
- return [
66
- 'description ' => [
67
- 'type ' => Type::string (),
68
- 'description ' => t ('Alt ' )
69
- ],
70
- 'display ' => [
71
- 'type ' => Type::string (),
72
- 'description ' => t ('Display ' )
73
- ],
74
- 'alt ' => [
75
- 'type ' => Type::string (),
76
- 'description ' => t ('Alt ' )
77
- ],
78
- 'title ' => [
79
- 'type ' => Type::string (),
80
- 'description ' => t ('Title ' )
81
- ],
82
- 'width ' => [
83
- 'type ' => Type::float (),
84
- 'description ' => t ('Width ' )
85
- ],
86
- 'height ' => [
87
- 'type ' => Type::float (),
88
- 'description ' => t ('Height ' )
89
- ],
90
- 'file ' => [
91
- 'type ' => $ file_type ,
92
- 'description ' => t ('File ' )
93
- ]
94
- ];
50
+ return $ fields ;
95
51
}
96
52
]),
97
- 'socialfield ' => Type::listOf (new ObjectType ([
98
- 'name ' => 'socialfield ' ,
99
- 'fields ' => [
100
- 'service ' => [
101
- 'type ' => Type::string (),
102
- 'description ' => t ('Service ' )
103
- ],
104
- 'url ' => [
105
- 'type ' => Type::string (),
106
- 'description ' => t ('URL ' )
107
- ],
108
- 'weight ' => [
109
- 'type ' => Type::int (),
110
- 'description ' => t ('Weight ' )
111
- ]
53
+ 'field_item_file ' => new ObjectType (
54
+ [
55
+ 'name ' => 'field_item_file ' ,
56
+ 'fields ' => function () {
57
+ graphql_api ()->addEntityGqlDefinition ('file ' );
58
+ $ type = graphql_api ()->getInterfaceType ('file ' );
59
+ return [
60
+ 'file ' => [
61
+ 'type ' => $ type ,
62
+ 'description ' => t ('File ' ),
63
+ 'resolve ' => function ($ value ) {
64
+ if ($ value ) {
65
+ $ file = file_load ($ value ['fid ' ]);
66
+ return entity_metadata_wrapper ('file ' , $ file );
67
+ }
68
+ return NULL ;
69
+ },
70
+ ],
71
+ 'description ' => [
72
+ 'type ' => Type::string (),
73
+ 'description ' => t ('Alt ' ),
74
+ ],
75
+ 'display ' => [
76
+ 'type ' => Type::string (),
77
+ 'description ' => t ('Display ' ),
78
+ ],
79
+ ];
80
+ },
112
81
]
113
- ])),
114
- 'field_item_name ' => new ObjectType ([
115
- 'name ' => 'field_item_name ' ,
116
- 'fields ' => [
117
- 'title ' => [
118
- 'type ' => Type::string (),
119
- 'description ' => t ('The title of the name. ' )
120
- ],
121
- 'given ' => [
122
- 'type ' => Type::string (),
123
- 'description ' => t ('The given name. ' )
124
- ],
125
- 'middle ' => [
126
- 'type ' => Type::string (),
127
- 'description ' => t ('The middle of the name. ' )
128
- ],
129
- 'family ' => [
130
- 'type ' => Type::string (),
131
- 'description ' => t ('The family of the name. ' )
132
- ],
133
- 'generational ' => [
134
- 'type ' => Type::string (),
135
- 'description ' => t ('The generational of the name. ' )
136
- ],
137
- 'credentials ' => [
138
- 'type ' => Type::string (),
139
- 'description ' => t ('The credentials of the name. ' )
140
- ]
141
- ]
142
- ]),
143
- 'field_item_link ' => new ObjectType ([
144
- 'name ' => 'field_item_link ' ,
145
- 'fields ' => [
146
- 'title ' => [
147
- 'type ' => Type::string (),
148
- 'description ' => t ('The title of the link. ' )
149
- ],
150
- 'url ' => [
151
- 'type ' => Type::string (),
152
- 'description ' => t ('The URL of the link. ' )
153
- ],
154
- // @todo convert attributes to JSON?
155
- // 'attributes' => [
156
- // 'type' => Type::string(),
157
- // 'description' => t('The attributes of the link.')
158
- // ],
82
+ ),
83
+ 'field_item_image ' => new ObjectType (
84
+ [
85
+ 'name ' => 'field_item_image ' ,
86
+ 'fields ' => function () {
87
+ // graphql_api()->addEntityGqlDefinition('file');
88
+ // $type = graphql_api()->getObjectType('file');
89
+ return [
90
+ 'fid ' => [
91
+ 'type ' => Type::string (),
92
+ 'description ' => t ('File ID ' ),
93
+ ],
94
+ 'description ' => [
95
+ 'type ' => Type::string (),
96
+ 'description ' => t ('Alt ' ),
97
+ ],
98
+ 'display ' => [
99
+ 'type ' => Type::string (),
100
+ 'description ' => t ('Display ' ),
101
+ ],
102
+ 'alt ' => [
103
+ 'type ' => Type::string (),
104
+ 'description ' => t ('Alt ' ),
105
+ ],
106
+ 'title ' => [
107
+ 'type ' => Type::string (),
108
+ 'description ' => t ('Title ' ),
109
+ ],
110
+ ];
111
+ },
159
112
]
160
- ])
161
- ]
113
+ ),
114
+ ],
162
115
];
163
- }
116
+ }
0 commit comments