88
88
use ApiPlatform \Laravel \Eloquent \PropertyAccess \PropertyAccessor as EloquentPropertyAccessor ;
89
89
use ApiPlatform \Laravel \Eloquent \PropertyInfo \EloquentExtractor ;
90
90
use ApiPlatform \Laravel \Eloquent \Serializer \EloquentNameConverter ;
91
+ use ApiPlatform \Laravel \Eloquent \Serializer \Mapping \Loader \RelationMetadataLoader ;
91
92
use ApiPlatform \Laravel \Eloquent \Serializer \SerializerContextBuilder as EloquentSerializerContextBuilder ;
92
93
use ApiPlatform \Laravel \GraphQl \Controller \EntrypointController as GraphQlEntrypointController ;
93
94
use ApiPlatform \Laravel \GraphQl \Controller \GraphiQlController ;
@@ -218,12 +219,21 @@ public function register(): void
218
219
$ this ->app ->bind (LoaderInterface::class, AttributeLoader::class);
219
220
$ this ->app ->bind (ClassMetadataFactoryInterface::class, ClassMetadataFactory::class);
220
221
$ this ->app ->singleton (ClassMetadataFactory::class, function (Application $ app ) {
222
+ /** @var ConfigRepository */
223
+ $ config = $ app ['config ' ];
224
+ $ nameConverter = $ config ->get ('api-platform.name_converter ' , SnakeCaseToCamelCaseNameConverter::class);
225
+ if ($ nameConverter && class_exists ($ nameConverter )) {
226
+ $ nameConverter = new EloquentNameConverter ($ app ->make ($ nameConverter ));
227
+ }
228
+
221
229
return new ClassMetadataFactory (
222
230
new LoaderChain ([
223
231
new PropertyMetadataLoader (
224
232
$ app ->make (PropertyNameCollectionFactoryInterface::class),
233
+ $ nameConverter
225
234
),
226
235
new AttributeLoader (),
236
+ // new RelationMetadataLoader($app->make(ModelMetadata::class)),
227
237
])
228
238
);
229
239
});
@@ -261,6 +271,10 @@ public function register(): void
261
271
$ this ->app ->singleton (PropertyMetadataFactoryInterface::class, function (Application $ app ) {
262
272
/** @var ConfigRepository $config */
263
273
$ config = $ app ['config ' ];
274
+ $ nameConverter = $ config ->get ('api-platform.name_converter ' , SnakeCaseToCamelCaseNameConverter::class);
275
+ if ($ nameConverter && class_exists ($ nameConverter )) {
276
+ $ nameConverter = new EloquentNameConverter ($ app ->make ($ nameConverter ));
277
+ }
264
278
265
279
return new CachePropertyMetadataFactory (
266
280
new SchemaPropertyMetadataFactory (
@@ -274,7 +288,8 @@ public function register(): void
274
288
new EloquentPropertyMetadataFactory (
275
289
$ app ->make (ModelMetadata::class),
276
290
),
277
- )
291
+ ),
292
+ $ nameConverter
278
293
),
279
294
$ app ->make (ResourceClassResolverInterface::class)
280
295
),
@@ -287,6 +302,10 @@ public function register(): void
287
302
$ this ->app ->singleton (PropertyNameCollectionFactoryInterface::class, function (Application $ app ) {
288
303
/** @var ConfigRepository $config */
289
304
$ config = $ app ['config ' ];
305
+ $ nameConverter = $ config ->get ('api-platform.name_converter ' , SnakeCaseToCamelCaseNameConverter::class);
306
+ if ($ nameConverter && class_exists ($ nameConverter )) {
307
+ $ nameConverter = new EloquentNameConverter ($ app ->make ($ nameConverter ));
308
+ }
290
309
291
310
return new CachePropertyNameCollectionMetadataFactory (
292
311
new ClassLevelAttributePropertyNameCollectionFactory (
@@ -296,7 +315,8 @@ public function register(): void
296
315
new PropertyInfoPropertyNameCollectionFactory ($ app ->make (PropertyInfoExtractorInterface::class)),
297
316
$ app ->make (ResourceClassResolverInterface::class)
298
317
)
299
- )
318
+ ),
319
+ $ nameConverter
300
320
),
301
321
true === $ config ->get ('app.debug ' ) ? 'array ' : $ config ->get ('api-platform.cache ' , 'file ' )
302
322
);
0 commit comments