@@ -927,6 +927,10 @@ public function register(): void
927
927
);
928
928
});
929
929
930
+ if (interface_exists (FieldsBuilderEnumInterface::class)) {
931
+ $ this ->registerGraphQl ($ this ->app );
932
+ }
933
+
930
934
$ this ->app ->singleton (JsonApiObjectNormalizer::class, function (Application $ app ) {
931
935
return new JsonApiObjectNormalizer (
932
936
$ app ->make (ObjectNormalizer::class),
@@ -936,51 +940,6 @@ public function register(): void
936
940
);
937
941
});
938
942
939
- if ($ this ->app ['config ' ]->get ('api-platform.graphql.enabled ' )) {
940
- $ this ->app ->singleton (GraphQlItemNormalizer::class, function (Application $ app ) {
941
- return new GraphQlItemNormalizer (
942
- $ app ->make (PropertyNameCollectionFactoryInterface::class),
943
- $ app ->make (PropertyMetadataFactoryInterface::class),
944
- $ app ->make (IriConverterInterface::class),
945
- $ app ->make (IdentifiersExtractorInterface::class),
946
- $ app ->make (ResourceClassResolverInterface::class),
947
- $ app ->make (PropertyAccessorInterface::class),
948
- $ app ->make (NameConverterInterface::class),
949
- $ app ->make (SerializerClassMetadataFactory::class),
950
- null ,
951
- $ app ->make (ResourceMetadataCollectionFactoryInterface::class),
952
- $ app ->make (ResourceAccessCheckerInterface::class)
953
- );
954
- });
955
-
956
- $ this ->app ->singleton (GraphQlObjectNormalizer::class, function (Application $ app ) {
957
- return new GraphQlObjectNormalizer (
958
- $ app ->make (ObjectNormalizer::class),
959
- $ app ->make (IriConverterInterface::class),
960
- $ app ->make (IdentifiersExtractorInterface::class),
961
- );
962
- });
963
- }
964
-
965
- $ this ->app ->singleton (GraphQlErrorNormalizer::class, function () {
966
- return new GraphQlErrorNormalizer ();
967
- });
968
-
969
- $ this ->app ->singleton (GraphQlValidationExceptionNormalizer::class, function (Application $ app ) {
970
- /** @var ConfigRepository */
971
- $ config = $ app ['config ' ];
972
-
973
- return new GraphQlValidationExceptionNormalizer ($ config ->get ('api-platform.exception_to_status ' ));
974
- });
975
-
976
- $ this ->app ->singleton (GraphQlHttpExceptionNormalizer::class, function () {
977
- return new GraphQlHttpExceptionNormalizer ();
978
- });
979
-
980
- $ this ->app ->singleton (GraphQlRuntimeExceptionNormalizer::class, function () {
981
- return new GraphQlHttpExceptionNormalizer ();
982
- });
983
-
984
943
$ this ->app ->bind (SerializerInterface::class, Serializer::class);
985
944
$ this ->app ->bind (NormalizerInterface::class, Serializer::class);
986
945
$ this ->app ->singleton (Serializer::class, function (Application $ app ) {
@@ -1009,7 +968,7 @@ public function register(): void
1009
968
$ list ->insert ($ app ->make (JsonApiItemNormalizer::class), -890 );
1010
969
$ list ->insert ($ app ->make (JsonApiObjectNormalizer::class), -995 );
1011
970
1012
- if ($ config -> get ( ' api-platform.graphql.enabled ' )) {
971
+ if (interface_exists (FieldsBuilderEnumInterface::class )) {
1013
972
$ list ->insert ($ app ->make (GraphQlItemNormalizer::class), -890 );
1014
973
$ list ->insert ($ app ->make (GraphQlObjectNormalizer::class), -995 );
1015
974
$ list ->insert ($ app ->make (GraphQlErrorNormalizer::class), -790 );
@@ -1033,7 +992,8 @@ public function register(): void
1033
992
new JsonEncoder ('jsonapi ' ),
1034
993
new JsonEncoder ('jsonhal ' ),
1035
994
new CsvEncoder (),
1036
- ]);
995
+ ]
996
+ );
1037
997
});
1038
998
1039
999
$ this ->app ->singleton (JsonLdItemNormalizer::class, function (Application $ app ) {
@@ -1078,17 +1038,56 @@ function (Application $app) {
1078
1038
return new Inflector ();
1079
1039
});
1080
1040
1081
- if ($ this ->app ['config ' ]->get ('api-platform.graphql.enabled ' )) {
1082
- $ this ->registerGraphQl ($ this ->app );
1083
- }
1084
-
1085
1041
if ($ this ->app ->runningInConsole ()) {
1086
1042
$ this ->commands ([Console \InstallCommand::class]);
1087
1043
}
1088
1044
}
1089
1045
1090
1046
private function registerGraphQl (Application $ app ): void
1091
1047
{
1048
+ $ this ->app ->singleton (GraphQlItemNormalizer::class, function (Application $ app ) {
1049
+ return new GraphQlItemNormalizer (
1050
+ $ app ->make (PropertyNameCollectionFactoryInterface::class),
1051
+ $ app ->make (PropertyMetadataFactoryInterface::class),
1052
+ $ app ->make (IriConverterInterface::class),
1053
+ $ app ->make (IdentifiersExtractorInterface::class),
1054
+ $ app ->make (ResourceClassResolverInterface::class),
1055
+ $ app ->make (PropertyAccessorInterface::class),
1056
+ $ app ->make (NameConverterInterface::class),
1057
+ $ app ->make (SerializerClassMetadataFactory::class),
1058
+ null ,
1059
+ $ app ->make (ResourceMetadataCollectionFactoryInterface::class),
1060
+ $ app ->make (ResourceAccessCheckerInterface::class)
1061
+ );
1062
+ });
1063
+
1064
+ $ this ->app ->singleton (GraphQlObjectNormalizer::class, function (Application $ app ) {
1065
+ return new GraphQlObjectNormalizer (
1066
+ $ app ->make (ObjectNormalizer::class),
1067
+ $ app ->make (IriConverterInterface::class),
1068
+ $ app ->make (IdentifiersExtractorInterface::class),
1069
+ );
1070
+ });
1071
+
1072
+ $ this ->app ->singleton (GraphQlErrorNormalizer::class, function () {
1073
+ return new GraphQlErrorNormalizer ();
1074
+ });
1075
+
1076
+ $ this ->app ->singleton (GraphQlValidationExceptionNormalizer::class, function (Application $ app ) {
1077
+ /** @var ConfigRepository */
1078
+ $ config = $ app ['config ' ];
1079
+
1080
+ return new GraphQlValidationExceptionNormalizer ($ config ->get ('api-platform.exception_to_status ' ));
1081
+ });
1082
+
1083
+ $ this ->app ->singleton (GraphQlHttpExceptionNormalizer::class, function () {
1084
+ return new GraphQlHttpExceptionNormalizer ();
1085
+ });
1086
+
1087
+ $ this ->app ->singleton (GraphQlRuntimeExceptionNormalizer::class, function () {
1088
+ return new GraphQlHttpExceptionNormalizer ();
1089
+ });
1090
+
1092
1091
$ app ->singleton ('api_platform.graphql.type_locator ' , function (Application $ app ) {
1093
1092
$ tagged = iterator_to_array ($ app ->tagged ('api_platform.graphql.type ' ));
1094
1093
@@ -1130,44 +1129,78 @@ private function registerGraphQl(Application $app): void
1130
1129
return new GraphQlSerializerContextBuilder ($ app ->make (NameConverterInterface::class));
1131
1130
});
1132
1131
1133
- $ app ->singleton (' api_platform.graphql.state_provider ' , function (Application $ app ) {
1132
+ $ app ->singleton (GraphQlReadProvider::class , function (Application $ app ) {
1134
1133
/** @var ConfigRepository */
1135
1134
$ config = $ app ['config ' ];
1136
- $ tagged = iterator_to_array ($ app ->tagged (ParameterProviderInterface::class));
1137
- $ resolvers = iterator_to_array ($ app ->tagged ('api_platform.graphql.resolver ' ));
1138
1135
1139
1136
return new GraphQlReadProvider (
1140
- new GraphQlDenormalizeProvider (
1141
- new ResolverProvider (
1142
- new ParameterProvider (
1143
- $ app ->make (CallableProvider::class),
1144
- new ServiceLocator ($ tagged )
1145
- ),
1146
- new ServiceLocator ($ resolvers ),
1147
- ),
1148
- $ app ->make (SerializerInterface::class),
1149
- $ app ->make (GraphQlSerializerContextBuilder::class)
1150
- ),
1137
+ $ this ->app ->make (CallableProvider::class),
1151
1138
$ app ->make (IriConverterInterface::class),
1152
1139
$ app ->make (GraphQlSerializerContextBuilder::class),
1153
1140
$ config ->get ('api-platform.graphql.nesting_separator ' ) ?? '__ '
1154
1141
);
1155
1142
});
1143
+ $ app ->alias (GraphQlReadProvider::class, 'api_platform.graphql.state_provider.read ' );
1144
+
1145
+ $ app ->singleton (ResolverProvider::class, function (Application $ app ) {
1146
+ $ resolvers = iterator_to_array ($ app ->tagged ('api_platform.graphql.resolver ' ));
1147
+
1148
+ return new ResolverProvider (
1149
+ $ app ->make (GraphQlReadProvider::class),
1150
+ new ServiceLocator ($ resolvers ),
1151
+ );
1152
+ });
1153
+
1154
+ $ app ->alias (ResolverProvider::class, 'api_platform.graphql.state_provider.resolver ' );
1155
+
1156
+ $ app ->singleton (GraphQlDenormalizeProvider::class, function (Application $ app ) {
1157
+ return new GraphQlDenormalizeProvider (
1158
+ $ this ->app ->make (ResolverProvider::class),
1159
+ $ app ->make (SerializerInterface::class),
1160
+ $ app ->make (GraphQlSerializerContextBuilder::class)
1161
+ );
1162
+ });
1163
+
1164
+ $ app ->alias (GraphQlDenormalizeProvider::class, 'api_platform.graphql.state_provider.denormalize ' );
1165
+
1166
+ $ app ->singleton ('api_platform.graphql.state_provider.parameter ' , function (Application $ app ) {
1167
+ $ tagged = iterator_to_array ($ app ->tagged (ParameterProviderInterface::class));
1168
+ $ tagged ['api_platform.serializer.filter_parameter_provider ' ] = $ app ->make (SerializerFilterParameterProvider::class);
1169
+
1170
+ return new ParameterProvider (
1171
+ new ParameterValidatorProvider (
1172
+ new SecurityParameterProvider (
1173
+ $ app ->make (GraphQlDenormalizeProvider::class),
1174
+ $ app ->make (ResourceAccessCheckerInterface::class)
1175
+ ),
1176
+ ),
1177
+ new ServiceLocator ($ tagged )
1178
+ );
1179
+ });
1180
+
1181
+ $ app ->singleton ('api_platform.graphql.state_provider.access_checker ' , function (Application $ app ) {
1182
+ return new AccessCheckerProvider ($ app ->make ('api_platform.graphql.state_provider.parameter ' ), $ app ->make (ResourceAccessCheckerInterface::class));
1183
+ });
1184
+
1185
+ $ app ->singleton (NormalizeProcessor::class, function (Application $ app ) {
1186
+ return new NormalizeProcessor (
1187
+ $ app ->make (SerializerInterface::class),
1188
+ $ app ->make (GraphQlSerializerContextBuilder::class),
1189
+ $ app ->make (Pagination::class)
1190
+ );
1191
+ });
1192
+ $ app ->alias (NormalizeProcessor::class, 'api_platform.graphql.state_processor.normalize ' );
1156
1193
1157
1194
$ app ->singleton ('api_platform.graphql.state_processor ' , function (Application $ app ) {
1158
1195
return new WriteProcessor (
1159
- new NormalizeProcessor (
1160
- $ app ->make (SerializerInterface::class),
1161
- $ app ->make (GraphQlSerializerContextBuilder::class),
1162
- $ app ->make (Pagination::class)
1163
- ),
1196
+ $ app ->make ('api_platform.graphql.state_processor.normalize ' ),
1164
1197
$ app ->make (CallableProcessor::class),
1165
1198
);
1166
1199
});
1167
1200
1168
1201
$ app ->singleton (ResolverFactoryInterface::class, function (Application $ app ) {
1169
1202
return new ResolverFactory (
1170
- $ app ->make ('api_platform.graphql.state_provider ' ),
1203
+ $ app ->make ('api_platform.graphql.state_provider.access_checker ' ),
1171
1204
$ app ->make ('api_platform.graphql.state_processor ' )
1172
1205
);
1173
1206
});
@@ -1227,7 +1260,8 @@ private function registerGraphQl(Application $app): void
1227
1260
$ app ->make (SerializerInterface::class),
1228
1261
$ app ->make (ErrorHandlerInterface::class),
1229
1262
debug: $ config ->get ('app.debug ' ),
1230
- negotiator: $ app ->make (Negotiator::class)
1263
+ negotiator: $ app ->make (Negotiator::class),
1264
+ formats: $ config ->get ('api-platform.formats ' )
1231
1265
);
1232
1266
});
1233
1267
}
0 commit comments