@@ -189,10 +189,10 @@ private function getMutationFields(string $resourceClass, ResourceMetadata $reso
189
189
*
190
190
* @return array|null
191
191
*/
192
- private function getResourceFieldConfiguration (string $ resourceClass , ResourceMetadata $ resourceMetadata , string $ fieldDescription = null , Type $ type , string $ rootResource , bool $ input = false , string $ mutationName = null )
192
+ private function getResourceFieldConfiguration (string $ resourceClass , ResourceMetadata $ resourceMetadata , string $ fieldDescription = null , Type $ type , string $ rootResource , bool $ input = false , string $ mutationName = null , int $ depth = 0 )
193
193
{
194
194
try {
195
- if (null === $ graphqlType = $ this ->convertType ($ type , $ input , $ mutationName )) {
195
+ if (null === $ graphqlType = $ this ->convertType ($ type , $ input , $ mutationName, $ depth )) {
196
196
return null ;
197
197
}
198
198
@@ -227,7 +227,7 @@ private function getResourceFieldConfiguration(string $resourceClass, ResourceMe
227
227
foreach ($ this ->filterLocator ->get ($ filterId )->getDescription ($ resourceClass ) as $ key => $ value ) {
228
228
$ nullable = isset ($ value ['required ' ]) ? !$ value ['required ' ] : true ;
229
229
$ filterType = \in_array ($ value ['type ' ], Type::$ builtinTypes , true ) ? new Type ($ value ['type ' ], $ nullable ) : new Type ('object ' , $ nullable , $ value ['type ' ]);
230
- $ graphqlFilterType = $ this ->convertType ($ filterType );
230
+ $ graphqlFilterType = $ this ->convertType ($ filterType, false , null , $ depth );
231
231
232
232
if ('[] ' === $ newKey = substr ($ key , -2 )) {
233
233
$ key = $ newKey ;
@@ -317,7 +317,7 @@ private function convertFilterArgsToTypes(array $args): array
317
317
*
318
318
* @throws InvalidTypeException
319
319
*/
320
- private function convertType (Type $ type , bool $ input = false , string $ mutationName = null )
320
+ private function convertType (Type $ type , bool $ input = false , string $ mutationName = null , int $ depth = 0 )
321
321
{
322
322
$ resourceClass = null ;
323
323
switch ($ builtinType = $ type ->getBuiltinType ()) {
@@ -341,7 +341,7 @@ private function convertType(Type $type, bool $input = false, string $mutationNa
341
341
$ graphqlType = $ this ->graphqlTypes ['#iterable ' ];
342
342
break ;
343
343
case Type::BUILTIN_TYPE_OBJECT :
344
- if (is_a ($ type ->getClassName (), \DateTimeInterface::class, true )) {
344
+ if (( $ input && $ depth > 0 ) || is_a ($ type ->getClassName (), \DateTimeInterface::class, true )) {
345
345
$ graphqlType = GraphQLType::string ();
346
346
break ;
347
347
}
@@ -357,14 +357,14 @@ private function convertType(Type $type, bool $input = false, string $mutationNa
357
357
return null ;
358
358
}
359
359
360
- $ graphqlType = $ this ->getResourceObjectType ($ resourceClass , $ resourceMetadata , $ input , $ mutationName );
360
+ $ graphqlType = $ this ->getResourceObjectType ($ resourceClass , $ resourceMetadata , $ input , $ mutationName, $ depth );
361
361
break ;
362
362
default :
363
363
throw new InvalidTypeException (sprintf ('The type "%s" is not supported. ' , $ builtinType ));
364
364
}
365
365
366
366
if ($ this ->isCollection ($ type )) {
367
- return $ this ->paginationEnabled ? $ this ->getResourcePaginatedCollectionType ($ resourceClass , $ graphqlType, $ input ) : GraphQLType::listOf ($ graphqlType );
367
+ return $ this ->paginationEnabled && ! $ input ? $ this ->getResourcePaginatedCollectionType ($ resourceClass , $ graphqlType ) : GraphQLType::listOf ($ graphqlType );
368
368
}
369
369
370
370
return $ type ->isNullable () || (null !== $ mutationName && 'update ' === $ mutationName ) ? $ graphqlType : GraphQLType::nonNull ($ graphqlType );
@@ -375,7 +375,7 @@ private function convertType(Type $type, bool $input = false, string $mutationNa
375
375
*
376
376
* @return ObjectType|InputObjectType
377
377
*/
378
- private function getResourceObjectType (string $ resourceClass , ResourceMetadata $ resourceMetadata , bool $ input = false , string $ mutationName = null ): GraphQLType
378
+ private function getResourceObjectType (string $ resourceClass , ResourceMetadata $ resourceMetadata , bool $ input = false , string $ mutationName = null , int $ depth = 0 ): GraphQLType
379
379
{
380
380
if (isset ($ this ->graphqlTypes [$ resourceClass ][$ mutationName ][$ input ])) {
381
381
return $ this ->graphqlTypes [$ resourceClass ][$ mutationName ][$ input ];
@@ -395,8 +395,8 @@ private function getResourceObjectType(string $resourceClass, ResourceMetadata $
395
395
'name ' => $ shortName ,
396
396
'description ' => $ resourceMetadata ->getDescription (),
397
397
'resolveField ' => $ this ->defaultFieldResolver ,
398
- 'fields ' => function () use ($ resourceClass , $ resourceMetadata , $ input , $ mutationName ) {
399
- return $ this ->getResourceObjectTypeFields ($ resourceClass , $ resourceMetadata , $ input , $ mutationName );
398
+ 'fields ' => function () use ($ resourceClass , $ resourceMetadata , $ input , $ mutationName, $ depth ) {
399
+ return $ this ->getResourceObjectTypeFields ($ resourceClass , $ resourceMetadata , $ input , $ mutationName, $ depth );
400
400
},
401
401
'interfaces ' => [$ this ->getNodeInterface ()],
402
402
];
@@ -407,7 +407,7 @@ private function getResourceObjectType(string $resourceClass, ResourceMetadata $
407
407
/**
408
408
* Gets the fields of the type of the given resource.
409
409
*/
410
- private function getResourceObjectTypeFields (string $ resourceClass , ResourceMetadata $ resourceMetadata , bool $ input = false , string $ mutationName = null ): array
410
+ private function getResourceObjectTypeFields (string $ resourceClass , ResourceMetadata $ resourceMetadata , bool $ input = false , string $ mutationName = null , int $ depth = 0 ): array
411
411
{
412
412
$ fields = [];
413
413
$ idField = ['type ' => GraphQLType::nonNull (GraphQLType::id ())];
@@ -434,7 +434,7 @@ private function getResourceObjectTypeFields(string $resourceClass, ResourceMeta
434
434
continue ;
435
435
}
436
436
437
- if ($ fieldConfiguration = $ this ->getResourceFieldConfiguration ($ resourceClass , $ resourceMetadata , $ propertyMetadata ->getDescription (), $ propertyType , $ resourceClass , $ input , $ mutationName )) {
437
+ if ($ fieldConfiguration = $ this ->getResourceFieldConfiguration ($ resourceClass , $ resourceMetadata , $ propertyMetadata ->getDescription (), $ propertyType , $ resourceClass , $ input , $ mutationName, ++ $ depth )) {
438
438
$ fields ['id ' === $ property ? '_id ' : $ property ] = $ fieldConfiguration ;
439
439
}
440
440
}
@@ -449,19 +449,16 @@ private function getResourceObjectTypeFields(string $resourceClass, ResourceMeta
449
449
/**
450
450
* Gets the type of a paginated collection of the given resource type.
451
451
*
452
- * @param ObjectType|InputObjectType $resourceType
452
+ * @param ObjectType $resourceType
453
453
*
454
- * @return ObjectType|InputObjectType
454
+ * @return ObjectType
455
455
*/
456
- private function getResourcePaginatedCollectionType (string $ resourceClass , GraphQLType $ resourceType, bool $ input = false ): GraphQLType
456
+ private function getResourcePaginatedCollectionType (string $ resourceClass , GraphQLType $ resourceType ): GraphQLType
457
457
{
458
458
$ shortName = $ resourceType ->name ;
459
- if ($ input ) {
460
- $ shortName .= 'Input ' ;
461
- }
462
459
463
- if (isset ($ this ->graphqlTypes [$ resourceClass ]['connection ' ][ $ input ] )) {
464
- return $ this ->graphqlTypes [$ resourceClass ]['connection ' ][ $ input ] ;
460
+ if (isset ($ this ->graphqlTypes [$ resourceClass ]['connection ' ])) {
461
+ return $ this ->graphqlTypes [$ resourceClass ]['connection ' ];
465
462
}
466
463
467
464
$ edgeObjectTypeConfiguration = [
@@ -472,7 +469,7 @@ private function getResourcePaginatedCollectionType(string $resourceClass, Graph
472
469
'cursor ' => GraphQLType::nonNull (GraphQLType::string ()),
473
470
],
474
471
];
475
- $ edgeObjectType = $ input ? new InputObjectType ( $ edgeObjectTypeConfiguration ) : new ObjectType ($ edgeObjectTypeConfiguration );
472
+ $ edgeObjectType = new ObjectType ($ edgeObjectTypeConfiguration );
476
473
$ pageInfoObjectTypeConfiguration = [
477
474
'name ' => "{$ shortName }PageInfo " ,
478
475
'description ' => 'Information about the current page. ' ,
@@ -481,7 +478,7 @@ private function getResourcePaginatedCollectionType(string $resourceClass, Graph
481
478
'hasNextPage ' => GraphQLType::nonNull (GraphQLType::boolean ()),
482
479
],
483
480
];
484
- $ pageInfoObjectType = $ input ? new InputObjectType ( $ pageInfoObjectTypeConfiguration ) : new ObjectType ($ pageInfoObjectTypeConfiguration );
481
+ $ pageInfoObjectType = new ObjectType ($ pageInfoObjectTypeConfiguration );
485
482
486
483
$ configuration = [
487
484
'name ' => "{$ shortName }Connection " ,
@@ -492,7 +489,7 @@ private function getResourcePaginatedCollectionType(string $resourceClass, Graph
492
489
],
493
490
];
494
491
495
- return $ this ->graphqlTypes [$ resourceClass ]['connection ' ][ $ input ] = $ input ? new InputObjectType ( $ configuration ) : new ObjectType ($ configuration );
492
+ return $ this ->graphqlTypes [$ resourceClass ]['connection ' ] = new ObjectType ($ configuration );
496
493
}
497
494
498
495
private function isCollection (Type $ type ): bool
0 commit comments