Ali*_*A2F 5 lighthouse laravel graphql 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 {
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")
}
Run Code Online (Sandbox Code Playgroud)
每次我想引用Field模型时,我都必须输入整个App\\Models\\CustomerManagement\\BusinessInformation\\Field. 我想知道我是否可以声明一个类似的变量model_namespace并使用它而不是大模型命名空间。
编辑:
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")
}
Run Code Online (Sandbox Code Playgroud)
您有几个选项:您基本上可以使用命名空间配置加载默认命名空间数组: https://github.com/nuwave/lighthouse/pull/525/files
或者使用组指令: https://lighthouse-php.com/3.0/api-reference/directives.html#group