We need to use Calculated Fields (the equivalent of JMSSerializer's @VirtualProperty for API Platform) and all is fine and dandy when we interact with the backend the old school way. However, we can't figure out how to query this calculated field on the GraphQL endpoint. For example:
/** * Undocumented function. * * @Serializer\VirtualProperty() * @Groups({"read"}) */ public function getSlug() { return $this->name.$this->description; }
Regular query:
curl -X GET "http://127.0.0.1:8000/platform/api/properties?page=1" -H "accept: application/ld+json"...
Regular result:
{"@context": "/platform/api/contexts/Property","@id": "/platform/api/properties","@type": "hydra:Collection","hydra:member": [ {"@id": "/platform/api/properties/1","@type": "Property","area": "0.00","bathroomCount": 2,"bedroomCount": 2,"floorCount": 2,"description": "bar","name": "foo","slug": "foobar" // The calculated property },...
GraphQL query:
{ properties { edges { node { slug } } }}
GraphQL result:
{"errors": [ {"message": "Cannot query field \"slug\" on type \"Property\".","extensions": {"category": "graphql" },"locations": [ {"line": 5,"column": 9 } ] } ]}
Thanks.