I've created a graphql file like this:
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")
}
Every time I want to refer to Field
model, I have to type the whole App\\Models\\CustomerManagement\\BusinessInformation\\Field
. I was wondering if I could declare a variable like model_namespace
and use it instead of the big model namespace.
EDIT:
https://lighthouse-php.com/4.4/api-reference/directives.html#namespace
You should use the @namespace directive
extend type Query @namespace(field: "App\\Blog") {
posts: [Post!]! @field(resolver: "Post@resolveAll")
}
You have a couple of options: You can basically load a default namespace array using namespace configuration: https://github.com/nuwave/lighthouse/pull/525/files
Or alternatively use a group directive: https://lighthouse-php.com/3.0/api-reference/directives.html#group
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With