常见问题通过钩子复制 GraphQL 端点路径更新
通过钩子复制 GraphQL 端点路径更新
如果您遇到以下问题:
...并且您在 Gato GraphQL 中执行了以下任一操作:
- 更新了 GraphQL Single Endpoint 的路径
- 更新了 Custom Endpoints 或 Persisted Queries 的基础 slug
- 禁用了某个端点(通过禁用对应的模块)
...那么您必须通过钩子应用相同的修改,以避免冲突。
钩子
如果您通过插件设置修改了任何公开端点的路径,则必须通过钩子应用相同的修改:
gatographql:before_app_is_loaded:graphql_endpoint_paths
同样,如果您禁用了某个公开端点模块,则必须通过钩子删除对应的路径。
示例
如果您在插件设置中将 Single Endpoint 的路径从 graphql 更改为 api/graphql:
add_filter(
'gatographql:before_app_is_loaded:graphql_endpoint_paths',
function(array $endpointPaths): array {
// Replace the default 'graphql' path with your custom path
return array_map(
fn ($path) => $path === 'graphql' ? 'api/graphql' : $path,
$endpointPaths
);
}
);如果您禁用了 Single Endpoint 模块:
add_filter(
'gatographql:before_app_is_loaded:graphql_endpoint_paths',
function(array $endpointPaths): array {
// Remove the 'graphql' path since the module is disabled
return array_filter(
$endpointPaths,
fn ($path) => $path !== 'graphql',
);
}
);Prev
Next