5

我创建了一个这样的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")
}

每次我想引用Field模型时,我都必须输入整个App\\Models\\CustomerManagement\\BusinessInformation\\Field. 我想知道我是否可以声明一个变量model_namespace并使用它来代替大模型命名空间。

4

1 回答 1

1

编辑:

https://lighthouse-php.com/4.4/api-reference/directives.html#namespace

您应该使用 @namespace 指令

extend type Query @namespace(field: "App\\Blog") {
  posts: [Post!]! @field(resolver: "Post@resolveAll")
}

您有几个选择:您基本上可以使用命名空间配置加载默认命名空间数组: https ://github.com/nuwave/lighthouse/pull/525/files

或者使用组指令: https ://lighthouse-php.com/3.0/api-reference/directives.html#group

于 2020-05-31T16:45:41.913 回答