-
-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add @namespaced
directive for namespacing by seperation of concerns
#2478
Conversation
# Conflicts: # docs/master/api-reference/directives.md # src/Schema/Directives/NamespacedDirective.php
@sniper7kills Could you rebase your pull request atop this branch and add a test? I think directives such as |
@spawnia If you could give me a little push-start I'd be more than glad to take a shot at implementing some tests for this. I'm in the namespaced-directive branch with the following test; but I get an error "No directive found for namespaced". If you could give me a base test to start off of I'd be grateful. public function testNamespaced(): void
{
$this->mockResolver()
->with(null, [
'foo' => 1,
]);
$this->schema = /** @lang GraphQL */ 'type Query {
foo: FooQueries! @namespaced
}
type FooQueries {
single(id: Int @spread): Int
}
';
$this->graphQL(/** @lang GraphQL */ '{
foo {
single(id: 1)
}
}
');
} Regarding the type Contact @model(class: "\\App\\Models\\Core\\Contact"){
id: ID!
company_id: ID
name: String!
"The contact profile photo URL"
photo: String
type: ContactTypes!
description: String
phone: String
email: String
company: Contact @BelongsTo
employees: [Contact!] @HasMany
"The notes for the contact"
notes: [Note]! @morphMany
"The attachments for the contact"
attachments: [Attachment]! @morphMany
"When the contact was created."
created_at: DateTime!
"When the contact was last updated."
updated_at: DateTime!
}
enum ContactTypes {
company
person
}
extend type CoreQueries {
contacts: ContactQueries! @namespaced
}
type ContactQueries {
"Find a contact by an identifying attribute."
single(
"Search by primary key."
id: ID @eq @rules(apply: ["prohibits:name", "required_without:name"])
"Search by name."
name: String @eq @rules(apply: ["prohibits:id", "required_without:id"])
): Contact @find
"List multiple contacts."
list(
"Filters by name. Accepts SQL LIKE wildcards `%` and `_`."
name: String @where(operator: "like")
includeIds: [String!] @in(key: "id", , ignoreNull: true)
parentId: String @where(key: "company_id", ignoreNull: true)
type: ContactTypes @where(ignoreNull: true)
): [Contact!]! @paginate(defaultCount: 10)
}
extend type CoreMutations {
contacts: ContactMutations! @namespaced
}
type ContactMutations {
create(
input: CreateContactInput! @spread
): Contact! @create
update(
input: UpdateContactInput @spread
): Contact! @update
delete(
id: String! @whereKey
): Contact @delete
}
input CreateContactInput {
company_id: ID
name: String!
type: ContactTypes!
company_id: ID
description: String
phone: String
email: String
file: VaporFileUpload
notes: CreateNoteBelongsToMany
attachments: CreateAttachmentBelongsToMany
}
input UpdateContactInput {
id: ID!
company_id: ID
name: String
type: ContactTypes
description: String
phone: String
email: String
file: VaporFileUpload
notes: CreateNoteBelongsToMany
attachments: CreateAttachmentBelongsToMany
}
input UpsertContactInput {
id: ID
company_id: ID
name: String
type: ContactTypes
description: String
phone: String
email: String
file: VaporFileUpload
notes: CreateNoteBelongsToMany
attachments: CreateAttachmentBelongsToMany
}
input CreateContactBelongsToMany{
create: [CreateContactInput!]
upsert: [UpsertContactInput!]
connect: [ID!]
sync: [ID!]
} |
Your test should look similar to the ones in https://github.com/nuwave/lighthouse/tree/master/tests/Integration/Schema/Directives. Make sure to extend the correct base class, then your directive should be found. It is just because many directives are somewhat magical when it comes to figuring out the correct model to use, the correct namespace, etc. |
Ah! Thank you! I was mistakenly making a Unit Test instead of an Integration Test. Please let me know if there are any special test cases you would like me to make to address any concerns I simply duplicated the nest directive test. |
# Conflicts: # CHANGELOG.md
Thank you @sniper7kills, works as intended. |
Resolves #2266, supersedes #2469
Changes
Adds the
@namespaced
directive.Breaking changes
None.