Платформа API - GraphQL - как запросить вычисляемое поле? - PullRequest
0 голосов
/ 09 апреля 2020

Нам нужно использовать Calculated Fields (эквивалент @VirtualProperty JMSSerializer для API Platform), и все нормально, когда мы взаимодействуем с бэкэндом по-старому. Однако мы не можем понять, как запросить это вычисляемое поле в конечной точке GraphQL. Например:

/**
     * Undocumented function.
     *
     * @Serializer\VirtualProperty()
     * @Groups({"read"})
     */
    public function getSlug()
    {
        return $this->name.$this->description;
    }

Обычный запрос:

curl -X GET "http://127.0.0.1:8000/platform/api/properties?page=1" -H "accept: application/ld+json"...

Обычный результат:

{
  "@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:

{
  properties {
    edges {
      node {
        slug
      }
    }
  }
}

Результат GraphQL :

{
  "errors": [
    {
      "message": "Cannot query field \"slug\" on type \"Property\".",
      "extensions": {
        "category": "graphql"
      },
      "locations": [
        {
          "line": 5,
          "column": 9
        }
      ]
    }
  ]
}

Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...