Skip to content

Commit b0c89f6

Browse files
dima koushhajenkins-bot
authored andcommitted
GQL: Remove the type field from statement valueType
Bug: T404834 Change-Id: Ifd3dba4d8719323588ac87d62b778d574941a89b
1 parent 7a05916 commit b0c89f6

File tree

8 files changed

+27
-64
lines changed

8 files changed

+27
-64
lines changed

repo/WikibaseRepo.datatypes.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,6 @@
307307
return new ObjectType( [
308308
'name' => 'StringValue',
309309
'fields' => [
310-
'type' => [
311-
'type' => Type::nonNull( Type::string() ),
312-
'resolve' => fn() => 'value',
313-
],
314310
'content' => [
315311
'type' => Type::nonNull( Type::string() ),
316312
'resolve' => fn( Value $v ) => $v->content->getValue(),
@@ -475,10 +471,6 @@
475471
return new ObjectType( [
476472
'name' => 'ItemValue',
477473
'fields' => [
478-
'type' => [
479-
'type' => Type::nonNull( Type::string() ),
480-
'resolve' => fn() => 'value',
481-
],
482474
'content' => [
483475
'type' => Type::nonNull( new ObjectType( [
484476
'name' => 'ValueItem',

repo/domains/reuse/src/Domain/Model/Value.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,16 @@
33
namespace Wikibase\Repo\Domains\Reuse\Domain\Model;
44

55
use DataValues\DataValue;
6-
use InvalidArgumentException;
76

87
/**
98
* @license GPL-2.0-or-later
109
*/
1110
class Value {
1211

13-
public const TYPE_VALUE = 'value';
14-
public const TYPE_NO_VALUE = 'novalue';
15-
public const TYPE_SOME_VALUE = 'somevalue';
16-
1712
/**
18-
* @param string $valueType
1913
* @param DataValue|null $content Guaranteed to be non-null if value type is "value", always null otherwise.
2014
*/
21-
public function __construct( public readonly string $valueType, public readonly ?DataValue $content = null ) {
22-
if ( !in_array( $valueType, [ self::TYPE_VALUE, self::TYPE_SOME_VALUE, self::TYPE_NO_VALUE ] ) ) {
23-
throw new InvalidArgumentException( '$valueType must be one of "value", "somevalue", "novalue"' );
24-
}
25-
if ( $valueType === self::TYPE_VALUE && !$content ) {
26-
throw new InvalidArgumentException( '$value must not be null if $valueType is "value"' );
27-
}
28-
if ( $valueType !== self::TYPE_VALUE && $content ) {
29-
throw new InvalidArgumentException( "There must not be a value if \$valueType is '$valueType'" );
30-
}
15+
public function __construct( public readonly ?DataValue $content = null ) {
3116
}
3217

3318
}

repo/domains/reuse/src/Domain/Services/StatementReadModelConverter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ private function convertSnakToPropertyValuePair( Snak $snak ): PropertyValuePair
6464
return new PropertyValuePair(
6565
new PredicateProperty( $snak->getPropertyId(), $dataType ),
6666
new Value(
67-
$snak->getType(),
6867
$snak instanceof PropertyValueSnak ? $snak->getDataValue() : null
6968
)
7069
);

repo/domains/reuse/src/Infrastructure/GraphQL/Schema/Schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private function statementType(): ObjectType {
131131
'type' => Type::nonNull( $this->predicatePropertyType ),
132132
'resolve' => fn( Statement $statement ) => $statement->property,
133133
],
134-
'value' => Type::nonNull( $this->valueType ),
134+
'value' => $this->valueType,
135135
],
136136
] );
137137
}

repo/domains/reuse/src/Infrastructure/GraphQL/Schema/ValueType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public function __construct() {
2020
$config = [
2121
'types' => array_values( $valueTypes ),
2222
'resolveType' => fn( Value $v ) => $v->content != null && $v->content instanceof StringValue
23-
? $valueTypes[ 'VT:string' ]
24-
: $valueTypes[ 'PT:wikibase-item' ],
23+
? $valueTypes[ 'VT:string' ]
24+
: $valueTypes[ 'PT:wikibase-item' ],
2525
];
2626
parent::__construct( $config );
2727
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type Statement {
2727
rank: Rank!
2828
qualifiers(propertyId: String!): [PropertyValuePair]!
2929
property: PredicateProperty!
30-
value: Value!
30+
value: Value
3131
}
3232

3333
enum Rank {
@@ -50,12 +50,10 @@ type PredicateProperty {
5050
union Value = StringValue | ItemValue
5151

5252
type StringValue {
53-
type: String!
5453
content: String!
5554
}
5655

5756
type ItemValue {
58-
type: String!
5957
content: ValueItem!
6058
}
6159

repo/domains/reuse/tests/phpunit/Infrastructure/DataAccess/EntityLookupItemsBatchRetrieverTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,6 @@ public function testGetItemWithStatementsWithValue(): void {
211211
$statementWithStringValue[0]->id->getSerialization()
212212
);
213213

214-
$this->assertSame(
215-
'value',
216-
$statementWithStringValue[0]->value->valueType
217-
);
218-
219214
$this->assertSame(
220215
'stringValue',
221216
$statementWithStringValue[0]->value->content->getValue()
@@ -226,11 +221,6 @@ public function testGetItemWithStatementsWithValue(): void {
226221
$statementWithItemValue[0]->id->getSerialization()
227222
);
228223

229-
$this->assertSame(
230-
'value',
231-
$statementWithItemValue[0]->value->valueType
232-
);
233-
234224
$this->assertSame(
235225
$itemValueItemId,
236226
$statementWithItemValue[0]->value->content->getEntityId()->getSerialization()

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,21 @@ public function queryProvider(): Generator {
8383
$sitelinkSiteId = self::ALLOWED_SITELINK_SITES[0];
8484
$otherSiteId = self::ALLOWED_SITELINK_SITES[1];
8585
$sitelinkTitle = 'Potato';
86-
$statementPropertyId = 'P1';
86+
$statementWithStringValuePropertyId = 'P1';
8787
$qualifierPropertyId = 'P2';
88-
$statement2PropertyId = 'P3';
88+
$statementWithItemValuePropertyId = 'P3';
89+
$statementWithNoValuePropertyId = 'P4';
90+
$statementWithSomeValueValuePropertyId = 'P5';
8991
$unusedPropertyId = 'P9999';
9092
$qualifierStringValue = 'qualifierStringValue';
9193
$statementStringValue = 'statementStringValue';
92-
$statement = NewStatement::forProperty( ( $statementPropertyId ) )
94+
$statementWithStringValue = NewStatement::forProperty( ( $statementWithStringValuePropertyId ) )
9395
->withGuid( "$itemId\$bed933b7-4207-d679-7571-3630cfb49d7f" )
9496
->withRank( 1 )
9597
->withQualifier( new NumericPropertyId( $qualifierPropertyId ), new StringValue( $qualifierStringValue ) )
9698
->withValue( $statementStringValue )
9799
->build();
98-
$statement2 = NewStatement::forProperty( ( $statement2PropertyId ) )
100+
$statementWithItemValue = NewStatement::forProperty( ( $statementWithItemValuePropertyId ) )
99101
->withGuid( "$itemId\$bed933b7-4207-d679-7571-3630cfb49d8f" )
100102
->withValue( new ItemId( $itemValueItemId ) )
101103
->build();
@@ -106,7 +108,7 @@ public function queryProvider(): Generator {
106108
self::$sitelinkSite->setGlobalId( $sitelinkSiteId );
107109

108110
self::$statementProperty = new Property(
109-
new NumericPropertyId( $statementPropertyId ),
111+
new NumericPropertyId( $statementWithStringValuePropertyId ),
110112
new Fingerprint( new TermList( [ new Term( 'en', 'statement prop' ) ] ) ),
111113
'string',
112114
);
@@ -121,8 +123,8 @@ public function queryProvider(): Generator {
121123
->andDescription( 'en', $enDescription )
122124
->andAliases( 'en', $enAliases )
123125
->andSiteLink( $sitelinkSiteId, $sitelinkTitle )
124-
->andStatement( $statement )
125-
->andStatement( $statement2 )
126+
->andStatement( $statementWithStringValue )
127+
->andStatement( $statementWithItemValue )
126128
->build();
127129

128130
$item2Id = 'Q321';
@@ -171,7 +173,7 @@ public function queryProvider(): Generator {
171173
];
172174
yield 'statement with id and rank' => [
173175
"{ item(id: \"$itemId\") {
174-
$statementPropertyId: statements(propertyId: \"$statementPropertyId\") {
176+
$statementWithStringValuePropertyId: statements(propertyId: \"$statementWithStringValuePropertyId\") {
175177
id
176178
rank
177179
property { id dataType }
@@ -181,12 +183,12 @@ public function queryProvider(): Generator {
181183
[
182184
'data' => [
183185
'item' => [
184-
$statementPropertyId => [
186+
$statementWithStringValuePropertyId => [
185187
[
186-
'id' => $statement->getGuid(),
188+
'id' => $statementWithStringValue->getGuid(),
187189
'rank' => 'normal',
188190
'property' => [
189-
'id' => $statementPropertyId,
191+
'id' => $statementWithStringValuePropertyId,
190192
'dataType' => 'string',
191193
],
192194
],
@@ -198,10 +200,10 @@ public function queryProvider(): Generator {
198200
];
199201
yield 'statement with qualifier' => [
200202
"{ item(id: \"$itemId\") {
201-
statements(propertyId: \"$statementPropertyId\") {
203+
statements(propertyId: \"$statementWithStringValuePropertyId\") {
202204
$qualifierPropertyId: qualifiers(propertyId: \"$qualifierPropertyId\") {
203205
property { id dataType }
204-
value { ...on StringValue { type content } }
206+
value { ...on StringValue { content } }
205207
}
206208
$unusedPropertyId: qualifiers(propertyId: \"$unusedPropertyId\") {
207209
property { id }
@@ -220,7 +222,6 @@ public function queryProvider(): Generator {
220222
'dataType' => 'string',
221223
],
222224
'value' => [
223-
'type' => 'value',
224225
'content' => $qualifierStringValue,
225226
],
226227
],
@@ -234,28 +235,26 @@ public function queryProvider(): Generator {
234235
];
235236
yield 'statements with StringValue and ItemValue' => [
236237
"{ item(id: \"$itemId\") {
237-
$statementPropertyId: statements(propertyId: \"$statementPropertyId\") {
238-
value { ...on StringValue{ type content } }
238+
$statementWithStringValuePropertyId: statements(propertyId: \"$statementWithStringValuePropertyId\") {
239+
value { ...on StringValue{ content } }
239240
}
240-
$statement2PropertyId: statements(propertyId: \"$statement2PropertyId\") {
241-
value { ...on ItemValue{ type content { id } } }
241+
$statementWithItemValuePropertyId: statements(propertyId: \"$statementWithItemValuePropertyId\") {
242+
value { ...on ItemValue{ content { id } } }
242243
}
243244
} }",
244245
[
245246
'data' => [
246247
'item' => [
247-
$statementPropertyId => [
248+
$statementWithStringValuePropertyId => [
248249
[
249250
'value' => [
250-
'type' => 'value',
251251
'content' => $statementStringValue,
252252
],
253253
],
254254
],
255-
$statement2PropertyId => [
255+
$statementWithItemValuePropertyId => [
256256
[
257257
'value' => [
258-
'type' => 'value',
259258
'content' => [ 'id' => $itemValueItemId ],
260259
],
261260
],
@@ -266,7 +265,7 @@ public function queryProvider(): Generator {
266265
];
267266
yield 'labels of predicate properties' => [
268267
"{ item(id: \"$itemId\") {
269-
statements(propertyId: \"{$statementPropertyId}\") {
268+
statements(propertyId: \"{$statementWithStringValuePropertyId}\") {
270269
property {
271270
label(languageCode: \"en\")
272271
}

0 commit comments

Comments
 (0)