在灯塔文档的示例中,他们给出了解析非根字段的示例方法。
<?php
use App\Models\User;
function resolveUserId(User $user): string
{
return $user->name; // test...
}
所以我的猜测是灯塔会搜索一个 resolveUser{Field} 方法,如果它存在就调用它。但是我在哪里放置方法?示例中没有类名或命名空间。
类型查询 @guard(with: ["api"]) { 我:用户!@auth }
type User {
id: ID!
name: String!
email: String!
posts (content_contains: [String]): [Post!]! @hasMany #Would like to be able to resolve content_contains somehow...
created_at: DateTime!
updated_at: DateTime!
}
文档网址:
https://lighthouse-php.com/4.9/the-basics/fields.html#resolving-non-root-fields