Skip to content

Commit 8389e7d

Browse files
Silvan-WMDEjenkins-bot
authored andcommitted
GQL: Support globecoordinate value type
This allows retrieving statement values of type globecoordinate, which includes values for latitude, longitude, precision and globe. Bug: T404838 Change-Id: I62f1cb51a54a4dae283d72041ae4517a7b3bc3a2
1 parent d7c472a commit 8389e7d

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

repo/WikibaseRepo.datatypes.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use DataValues\TimeValue;
3333
use DataValues\UnboundedQuantityValue;
3434
use GraphQL\Type\Definition\ObjectType;
35+
use GraphQL\Type\Definition\ResolveInfo;
3536
use GraphQL\Type\Definition\Type;
3637
use MediaWiki\Logger\LoggerFactory;
3738
use MediaWiki\MediaWikiServices;
@@ -210,6 +211,30 @@
210211
new ComplexValueRdfHelper( $vocab, $writer->sub(), $dedupe ) : null;
211212
return new GlobeCoordinateRdfBuilder( $complexValueHelper );
212213
},
214+
'graphql-value-type' => static function () {
215+
return new ObjectType( [
216+
'name' => 'GlobeCoordinateValue',
217+
'fields' => [
218+
'latitude' => Type::nonNull( Type::float() ),
219+
'longitude' => Type::nonNull( Type::float() ),
220+
'precision' => Type::float(),
221+
'globe' => Type::nonNull( Type::string() ),
222+
],
223+
'resolveField' => function ( Statement|PropertyValuePair $valueProvider, $args, $context, ResolveInfo $info ) {
224+
/** @var GlobeCoordinateValue $globeCoordinateValue */
225+
$globeCoordinateValue = $valueProvider->value->content;
226+
'@phan-var GlobeCoordinateValue $globeCoordinateValue';
227+
228+
return match ( $info->fieldName ) {
229+
'latitude' => $globeCoordinateValue->getLatitude(),
230+
'longitude' => $globeCoordinateValue->getLongitude(),
231+
'precision' => $globeCoordinateValue->getPrecision(),
232+
'globe' => $globeCoordinateValue->getGlobe(),
233+
default => null,
234+
};
235+
},
236+
] );
237+
},
213238
],
214239
'VT:monolingualtext' => [
215240
'expert-module' => 'jquery.valueview.experts.MonolingualText',

repo/domains/reuse/src/Infrastructure/GraphQL/schema.graphql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type PredicateProperty {
5050
label(languageCode: LanguageCode!): String
5151
}
5252

53-
union Value = StringValue | ItemValue
53+
union Value = StringValue | ItemValue | GlobeCoordinateValue
5454

5555
type StringValue {
5656
content: String!
@@ -65,6 +65,13 @@ type ValueItem {
6565
label(languageCode: LanguageCode!): String
6666
}
6767

68+
type GlobeCoordinateValue {
69+
latitude: Float!
70+
longitude: Float!
71+
precision: Float
72+
globe: String!
73+
}
74+
6875
enum ValueType {
6976
novalue
7077
somevalue

repo/domains/reuse/tests/phpunit/Infrastructure/GraphQL/GraphQLServiceTest.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Wikibase\Repo\Tests\Domains\Reuse\Infrastructure\GraphQL;
44

5+
use DataValues\Geo\Values\GlobeCoordinateValue;
6+
use DataValues\Geo\Values\LatLongValue;
57
use DataValues\StringValue;
68
use Generator;
79
use GraphQL\GraphQL;
@@ -45,6 +47,7 @@ class GraphQLServiceTest extends MediaWikiIntegrationTestCase {
4547
private static Item $qualifierValueItem;
4648
private static Property $stringTypeProperty;
4749
private static Property $itemTypeProperty;
50+
private static Property $globeCoordinateTypeProperty;
4851
private static Property $qualifierProperty;
4952
private static MediaWikiSite $sitelinkSite;
5053
private const ALLOWED_SITELINK_SITES = [ 'examplewiki', 'otherwiki' ];
@@ -78,6 +81,7 @@ public function testQuery( string $query, array $expectedResult ): void {
7881
$dataTypeLookup->setDataTypeForProperty( self::$stringTypeProperty->getId(), 'string' );
7982
$dataTypeLookup->setDataTypeForProperty( self::$qualifierProperty->getId(), 'string' );
8083
$dataTypeLookup->setDataTypeForProperty( self::$itemTypeProperty->getId(), 'wikibase-item' );
84+
$dataTypeLookup->setDataTypeForProperty( self::$globeCoordinateTypeProperty->getId(), 'globe-coordinate' );
8185

8286
$this->assertEquals(
8387
$expectedResult,
@@ -117,8 +121,9 @@ public function queryProvider(): Generator {
117121
$statementWithNoValuePropertyId = 'P4';
118122
$statementWithNoReferencesPropertyId = $statementWithNoValuePropertyId;
119123
$statementWithSomeValuePropertyId = 'P5';
124+
$statementWithGlobeCoordinateValuePropertyId = 'P6';
120125
$statementWithItemValueQualifierPropertyId = $statementWithItemValuePropertyId; // also type wikibase-item so we can just reuse it.
121-
$statementReferencePropertyId = 'P6';
126+
$statementReferencePropertyId = 'P11';
122127
$unusedPropertyId = 'P9999';
123128
$qualifierStringValue = 'qualifierStringValue';
124129
$statementStringValue = 'statementStringValue';
@@ -135,6 +140,11 @@ public function queryProvider(): Generator {
135140
->withValue( new ItemId( $itemValueItemId ) )
136141
->withQualifier( $statementWithItemValueQualifierPropertyId, self::$qualifierValueItem->getId() )
137142
->build();
143+
$globeCoordinateValue = new GlobeCoordinateValue( new LatLongValue( 52.516, 13.383 ) );
144+
$statementWithGlobeCoordinateValue = NewStatement::forProperty( $statementWithGlobeCoordinateValuePropertyId )
145+
->withGuid( "$itemId\$a82559b1-da8f-4e02-9f72-e304b90a9bde" )
146+
->withValue( $globeCoordinateValue )
147+
->build();
138148

139149
$statementWithNoValue = NewStatement::noValueFor( ( $statementWithNoValuePropertyId ) )
140150
->withGuid( "$itemId\$bed933b7-4207-d679-7571-3630cfb49d9f" )
@@ -154,6 +164,11 @@ public function queryProvider(): Generator {
154164
'string',
155165
);
156166
self::$itemTypeProperty = new Property( new NumericPropertyId( $statementWithItemValuePropertyId ), null, 'wikibase-item' );
167+
self::$globeCoordinateTypeProperty = new Property(
168+
new NumericPropertyId( $statementWithGlobeCoordinateValuePropertyId ),
169+
null,
170+
'globe-coordinate',
171+
);
157172
self::$qualifierProperty = new Property(
158173
new NumericPropertyId( $qualifierPropertyId ),
159174
new Fingerprint( new TermList( [ new Term( 'en', 'qualifier prop' ) ] ) ),
@@ -167,6 +182,7 @@ public function queryProvider(): Generator {
167182
->andSiteLink( $sitelinkSiteId, $sitelinkTitle )
168183
->andStatement( $statementWithStringValue )
169184
->andStatement( $statementWithItemValue )
185+
->andStatement( $statementWithGlobeCoordinateValue )
170186
->andStatement( $statementWithNoValue )
171187
->andStatement( $statementWithSomeValue )
172188
->build();
@@ -355,6 +371,31 @@ public function queryProvider(): Generator {
355371
],
356372
],
357373
];
374+
yield 'statement with globe-coordinate value' => [
375+
"{ item(id: \"$itemId\") {
376+
statements(propertyId: \"$statementWithGlobeCoordinateValuePropertyId\") {
377+
value {
378+
... on GlobeCoordinateValue { latitude longitude precision globe }
379+
}
380+
}
381+
} }",
382+
[
383+
'data' => [
384+
'item' => [
385+
'statements' => [
386+
[
387+
'value' => [
388+
'latitude' => $globeCoordinateValue->getLatitude(),
389+
'longitude' => $globeCoordinateValue->getLongitude(),
390+
'precision' => $globeCoordinateValue->getPrecision(),
391+
'globe' => $globeCoordinateValue->getGlobe(),
392+
],
393+
],
394+
],
395+
],
396+
],
397+
],
398+
];
358399
yield 'statements with novalue and somevalue' => [
359400
"{ item(id: \"$itemId\") {
360401
$statementWithSomeValuePropertyId: statements(propertyId: \"$statementWithSomeValuePropertyId\") {

0 commit comments

Comments
 (0)