-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGraphQLFieldtypeGeocoder.module
More file actions
executable file
·90 lines (75 loc) · 2.13 KB
/
GraphQLFieldtypeGeocoder.module
File metadata and controls
executable file
·90 lines (75 loc) · 2.13 KB
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
<?php
/**
* COPYRIGHT NOTICE
* Copyright (c) 2025 Neue Rituale GbR
* @author NR <code@neuerituale.com>
*/
namespace ProcessWire;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\ObjectType;
class GraphQLFieldtypeGeocoder extends WireData implements Module {
/**
* Get module information
* @return array
*/
public static function getModuleInfo(): array {
return [
'title' => 'GraphQLFieldtypeGeocoder',
'version' => 106,
'summary' => 'GraphQL support for FieldtypeGeocoder.',
'icon' => 'globe',
'requires' => ['ProcessGraphQL']
];
}
public static function getType(Field $field): ObjectType {
return new ObjectType([
'name' => 'Geocoder',
'fields' => [
'status' => [
'type' => Type::int(),
'resolve' => function($value) { return (int) $value->status; }
],
'formatted' => [
'type' => Type::string(),
'resolve' => function($value) { return (string) $value->formatted; }
],
'query' => [
'type' => Type::string(),
'resolve' => function($value) { return (string) $value->query; }
],
'geodata' => [
'type' => Type::string(),
'resolve' => function($value) { return (string) json_encode($value->geodata); }
],
'lat' => [
'type' => Type::float(),
'resolve' => function($value) { return is_numeric($value->lat) ? $value->lat : null; }
],
'lng' => [
'type' => Type::float(),
'resolve' => function($value) { return is_numeric($value->lng) ? $value->lng : null; }
],
'coordinates' => [
'type' => Type::listOf(Type::float()),
'resolve' => function($value) {
return [
is_numeric($value->lng) ? $value->lng : null,
is_numeric($value->lat) ? $value->lat : null
];
}
],
'provider' => [
'type' => Type::string(),
'resolve' => function($value) { return (string) $value->provider; }
],
],
]);
}
public static function getInputType(Field $field): \GraphQL\Type\Definition\ScalarType {
return Type::string();
}
public static function setValue(Page $page, Field $field, $value): void {
$fieldName = $field->name;
$page->$fieldName = $value;
}
}