Laravel 在lighthouse graphql文件中声明变量

Laravel 在lighthouse graphql文件中声明变量,laravel,graphql,lighthouse,laravel-lighthouse,Laravel,Graphql,Lighthouse,Laravel Lighthouse,我创建了一个graphql文件,如下所示: type Field { id: ID! name_en: String! name_fa: String! description: String! img_url: String! created_at: DateTime! updated_at: DateTime! subFields: [SubField] @hasMany } extend type Query {

我创建了一个graphql文件,如下所示:

type Field {
    id: ID!
    name_en: String!
    name_fa: String!
    description: String!
    img_url: String!
    created_at: DateTime!
    updated_at: DateTime!

    subFields: [SubField] @hasMany
}

extend type Query {
    fields(input: ListInput @spread): [Field] @paginate(model: "App\\Models\\CustomerManagement\\BusinessInformation\\Field" defaultCount: 10)
    field(id: ID! @eq): Field @find(model: "App\\Models\\CustomerManagement\\BusinessInformation\\Field")
}

extend type Mutation {
    createField(
        name_en: String! @rules(apply: ["required"])
        name_fa: String
        description: String
        img_url: String
    ): Field @create(model: "App\\Models\\CustomerManagement\\BusinessInformation\\Field")

    updateField(
        id: ID! @rules(apply: ["required", "int"])
        name_en: String @rules(apply: ["required"])
        name_fa: String
        description: String
        img_url: String
    ): Field @update(model: "App\\Models\\CustomerManagement\\BusinessInformation\\Field")

    deleteField(
        id: ID! @rules(apply: ["required", "int"])
    ): Field @delete(model: "App\\Models\\CustomerManagement\\BusinessInformation\\Field")
}
每次我想参考
字段
模型时,我都必须键入整个
App\\Models\\CustomerManagement\\BusinessInformation\\Field
。我想知道是否可以声明一个像
model\u namespace
这样的变量,并使用它来代替大模型名称空间。

编辑:

您应该使用@namespace指令

extend type Query @namespace(field: "App\\Blog") {
  posts: [Post!]! @field(resolver: "Post@resolveAll")
}
您有两个选择: 基本上可以使用命名空间配置加载默认命名空间数组:

或者使用组指令:

您提供的第一个链接不是我真正想要的,第二个链接在lighthouse v3中,但我使用的是最新版本,即v4.12,其中没有
@group
指令。在这种情况下,您应该创建一个与group指令完全相同的自定义指令:)