Using 3rd-party DTOs in GraphQL
See original GitHub issueIt seems like there’s no way to use object which are not defined as @ApiResource in GraphQL - they are simply invisible. This is not that big of a limitation, since one can define this in YAML like so:
resources:
libphonenumber\PhoneNumber: ~
Serialization groups are also not a problem, since Symfony Serializer can read the config from YAML:
libphonenumber\PhoneNumber:
attributes:
countryCode: &std
groups: ['GraphQLQuery']
nationalNumber: *std
extension: *std
italianLeadingZero: *std
numberOfLeadingZeros: *std
rawInput: *std
countryCodeSource: *std
preferredDomesticCarrierCode: *std
The biggest issue is IDs - it seems like you cannot have objects without IDs as resources. This makes sense from resource perspective, but for simple value objects it’s just not possible to get any IDs. Additionally the method above does not seem to work with core objects (e.g. \DateTimeZone) 😦
I looked into docs, but they’re very sparse for GraphQL. I will happily improve them, but I cannot find a reliable way of making this working for objects without IDs (short of hacking \ApiPlatform\Core\GraphQl\Type\SchemaBuilder)?
This is similar to https://github.com/api-platform/core/issues/1870, but deals with really a different issue - code which you cannot change.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)

Top Related StackOverflow Question
Closing as duplicate, thanks about the resolution @kiler129
@Siregacvek:
That’s simple, you just use the standard Symfony DIC functionality of services decoration.
and the IRI converter itself will simply use composition like the following: