33namespace Wikibase \Repo \Domains \Reuse \Infrastructure \GraphQL \Schema ;
44
55use GraphQL \Type \Definition \EnumType ;
6- use GraphQL \Type \Definition \InterfaceType ;
76use GraphQL \Type \Definition \ObjectType ;
87use GraphQL \Type \Definition \Type ;
98use GraphQL \Type \Schema as GraphQLSchema ;
2019class Schema extends GraphQLSchema {
2120 public function __construct (
2221 ItemResolver $ itemResolver ,
23- private readonly ItemIdType $ itemIdType ,
24- private readonly SiteIdType $ siteIdType ,
25- private readonly LanguageCodeType $ languageCodeType ,
26- private readonly PropertyValuePairType $ propertyValuePairType ,
27- private readonly PropertyIdType $ propertyIdType ,
28- private readonly InterfaceType $ labelProviderType ,
22+ private readonly Types $ types ,
2923 ) {
3024 parent ::__construct ( [
3125 'query ' => new ObjectType ( [
@@ -34,7 +28,7 @@ public function __construct(
3428 'item ' => [
3529 'type ' => $ this ->itemType (),
3630 'args ' => [
37- 'id ' => Type::nonNull ( $ this ->itemIdType ),
31+ 'id ' => Type::nonNull ( $ this ->types -> getItemIdType () ),
3832 ],
3933 'resolve ' => fn ( $ rootValue , array $ args ) => $ itemResolver ->resolveItem ( $ args ['id ' ] ),
4034 ],
@@ -44,22 +38,23 @@ public function __construct(
4438 }
4539
4640 private function itemType (): ObjectType {
47- $ labelField = clone $ this ->labelProviderType ->getField ( 'label ' ); // cloned to not override the resolver in other places
41+ $ labelProviderType = $ this ->types ->getLabelProviderType ();
42+ $ labelField = clone $ labelProviderType ->getField ( 'label ' ); // cloned to not override the resolver in other places
4843 $ labelField ->resolveFn = fn ( Item $ item , array $ args ) => $ item ->labels
4944 ->getLabelInLanguage ( $ args ['languageCode ' ] )?->text;
5045
5146 return new ObjectType ( [
5247 'name ' => 'Item ' ,
5348 'fields ' => [
5449 'id ' => [
55- 'type ' => Type::nonNull ( $ this ->itemIdType ),
50+ 'type ' => Type::nonNull ( $ this ->types -> getItemIdType () ),
5651 'resolve ' => fn ( Item $ item ) => $ item ->id ->getSerialization (),
5752 ],
5853 $ labelField ,
5954 'description ' => [
6055 'type ' => Type::string (),
6156 'args ' => [
62- 'languageCode ' => Type::nonNull ( $ this ->languageCodeType ),
57+ 'languageCode ' => Type::nonNull ( $ this ->types -> getLanguageCodeType () ),
6358 ],
6459 'resolve ' => fn ( Item $ item , array $ args ) => $ item ->descriptions
6560 ->getDescriptionInLanguage ( $ args ['languageCode ' ] )?->text,
@@ -68,7 +63,7 @@ private function itemType(): ObjectType {
6863 // @phan-suppress-next-line PhanUndeclaredInvokeInCallable
6964 'type ' => Type::nonNull ( Type::listOf ( Type::string () ) ),
7065 'args ' => [
71- 'languageCode ' => Type::nonNull ( $ this ->languageCodeType ),
66+ 'languageCode ' => Type::nonNull ( $ this ->types -> getLanguageCodeType () ),
7267 ],
7368 'resolve ' => fn ( Item $ item , array $ args ) => $ item ->aliases
7469 ->getAliasesInLanguageInLanguage ( $ args ['languageCode ' ] )?->aliases ?? [],
@@ -82,7 +77,7 @@ private function itemType(): ObjectType {
8277 ],
8378 ] ),
8479 'args ' => [
85- 'siteId ' => Type::nonNull ( $ this ->siteIdType ),
80+ 'siteId ' => Type::nonNull ( $ this ->types -> getSiteIdType () ),
8681 ],
8782 'resolve ' => function ( Item $ item , array $ args ) {
8883 $ sitelink = $ item ->sitelinks ->getSitelinkForSite ( $ args ['siteId ' ] );
@@ -96,33 +91,35 @@ private function itemType(): ObjectType {
9691 // @phan-suppress-next-line PhanUndeclaredInvokeInCallable
9792 'type ' => Type::nonNull ( Type::listOf ( $ this ->statementType () ) ),
9893 'args ' => [
99- 'propertyId ' => Type::nonNull ( $ this ->propertyIdType ),
94+ 'propertyId ' => Type::nonNull ( $ this ->types -> getPropertyIdType () ),
10095 ],
10196 'resolve ' => fn ( Item $ item , array $ args ) => $ item ->statements
10297 ->getStatementsByPropertyId ( new NumericPropertyId ( $ args [ 'propertyId ' ] ) ),
10398 ],
10499 ],
105- 'interfaces ' => [ $ this -> labelProviderType ],
100+ 'interfaces ' => [ $ labelProviderType ],
106101 ] );
107102 }
108103
109104 private function statementType (): ObjectType {
105+ $ propertyValuePairType = $ this ->types ->getPropertyValuePairType ();
106+
110107 $ qualifierType = new ObjectType ( [
111108 'name ' => 'Qualifier ' ,
112109 'fields ' => [
113- $ this -> propertyValuePairType ->getField ( 'property ' ),
114- $ this -> propertyValuePairType ->getField ( 'value ' ),
115- $ this -> propertyValuePairType ->getField ( 'valueType ' ),
110+ $ propertyValuePairType ->getField ( 'property ' ),
111+ $ propertyValuePairType ->getField ( 'value ' ),
112+ $ propertyValuePairType ->getField ( 'valueType ' ),
116113 ],
117- 'interfaces ' => [ $ this -> propertyValuePairType ],
114+ 'interfaces ' => [ $ propertyValuePairType ],
118115 ] );
119116
120117 return new ObjectType ( [
121118 'name ' => 'Statement ' ,
122119 'fields ' => [
123- $ this -> propertyValuePairType ->getField ( 'property ' ),
124- $ this -> propertyValuePairType ->getField ( 'value ' ),
125- $ this -> propertyValuePairType ->getField ( 'valueType ' ),
120+ $ propertyValuePairType ->getField ( 'property ' ),
121+ $ propertyValuePairType ->getField ( 'value ' ),
122+ $ propertyValuePairType ->getField ( 'valueType ' ),
126123 'id ' => [
127124 'type ' => Type::nonNull ( Type::string () ),
128125 'resolve ' => fn ( Statement $ statement ) => $ statement ->id ,
@@ -135,7 +132,7 @@ private function statementType(): ObjectType {
135132 // @phan-suppress-next-line PhanUndeclaredInvokeInCallable
136133 'type ' => Type::nonNull ( Type::listOf ( $ qualifierType ) ),
137134 'args ' => [
138- 'propertyId ' => Type::nonNull ( $ this ->propertyIdType ),
135+ 'propertyId ' => Type::nonNull ( $ this ->types -> getPropertyIdType () ),
139136 ],
140137 'resolve ' => fn ( Statement $ statement , $ args ) => $ statement ->qualifiers
141138 ->getQualifiersByPropertyId ( new NumericPropertyId ( $ args [ 'propertyId ' ] ) ),
@@ -146,7 +143,7 @@ private function statementType(): ObjectType {
146143 'resolve ' => fn ( Statement $ statement ) => $ statement ->references ,
147144 ],
148145 ],
149- 'interfaces ' => [ $ this -> propertyValuePairType ],
146+ 'interfaces ' => [ $ propertyValuePairType ],
150147 ] );
151148 }
152149
@@ -168,14 +165,15 @@ private function rankType(): EnumType {
168165 }
169166
170167 private function referenceType (): ObjectType {
168+ $ propertyValuePairType = $ this ->types ->getPropertyValuePairType ();
171169 $ referencePartType = new ObjectType ( [
172170 'name ' => 'ReferencePart ' ,
173171 'fields ' => [
174- $ this -> propertyValuePairType ->getField ( 'property ' ),
175- $ this -> propertyValuePairType ->getField ( 'value ' ),
176- $ this -> propertyValuePairType ->getField ( 'valueType ' ),
172+ $ propertyValuePairType ->getField ( 'property ' ),
173+ $ propertyValuePairType ->getField ( 'value ' ),
174+ $ propertyValuePairType ->getField ( 'valueType ' ),
177175 ],
178- 'interfaces ' => [ $ this -> propertyValuePairType ],
176+ 'interfaces ' => [ $ propertyValuePairType ],
179177 ] );
180178
181179 return new ObjectType ( [
0 commit comments