自定义过滤器不适用于 API Platform 中的 GraphQL 集合查询

问题描述 投票:0回答:1

我正在使用 API Platform,我想添加 graphQL 支持并在 REST 调用和 graphQL 调用之间保持相同的行为。我的 get 集合有一些自定义过滤器,可以与 REST 配合使用,但它们在 graphQL 中无法识别。根据文档,我添加了以下内容,因此 graphQL 现在知道 collection_query 上有一些过滤器,但仅出现在架构和文档上,实际上这些过滤器未被采用。

 /** 
 * @ApiResource(
 *     graphql={
 *         "item_query",
 *         "collection_query"={
 *              "filters"={
 *                  PointFilter::class,
 *                  ShippingMethodFilter::class,
 *              }
 *          },
 *     }
 * )

我还在这里读到https://github.com/api-platform/core/issues/4615这是“正常”的,因为graphQL仅发送POST请求并且过滤器应用于GET。您知道是否还有其他选择可以使其发挥作用吗?

php symfony graphql api-platform.com
1个回答
0
投票

我终于找到了一个解决方案,我需要全局声明这些过滤器,而不仅仅是为了 graphQL 操作:

/**
 * @ApiResource(
 *     graphql={
 *         "item_query",
 *         "collection_query",
 *     }
 * )
 * @ApiFilter(PointFilter::class)
 * @ApiFilter(ShippingMethodFilter::class)
 */
© www.soinside.com 2019 - 2024. All rights reserved.