-
Notifications
You must be signed in to change notification settings - Fork 18
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
support for @Sibling many-to-many relationships? #6
Comments
Hi, awesome that you like the package! The current version doesn't support // Siblings Relationship
extension Graphiti.Field where Arguments == NoArguments, Context == Request, ObjectType: Model {
public convenience init<ToType: Model, ThroughType: Model>(
_ name: FieldKey,
with keyPath: KeyPath<ObjectType, SiblingsProperty<ObjectType, ToType, ThroughType>>
) where FieldType == [TypeReference<ToType>] {
self.init(name.description, at: { (type) -> (Request, NoArguments, EventLoopGroup) throws -> EventLoopFuture<[ToType]> in
return { (context: Request, arguments: NoArguments, eventLoop: EventLoopGroup) in
return type[keyPath: keyPath].query(on: context.db).all()
}
}, as: [TypeReference<ToType>].self)
}
} I'll clean up my code, add some documentation and ship a new version in the next day or two. When I have the time, I'll also publish a blog post explaining its usage. But it should be straightforward to use. I hope this will help you solve your use case. |
@alexsteinerde thanks for getting back so quickly. I copied your sample code into my project, and it seems to work perfectly, at least at first glance. I'll just use that until you're able to get a new release out, no hurry. Really appreciate it! |
I published a new release 2.2.0 with the mentioned extension included. |
New version works great! Thanks again! |
Hi there. Thanks for this amazing library and all the work you put into it! It's been fantastic to use so far! 🙏
I'm having trouble modeling a many-to-many pivot-table based sibling relationship with vapor+graphql-kit. I'm a bit at a loss of even how to approach the problem. I'm wondering if it's something that is not supported yet, or if possibly I just don't know how to set up the schema and resolvers to make it work.
I see that you extended Graphiti's
Field
class here to add keypath-based resolution specifically for children and parent relationships. I'm wondering if something similar would need to be done for sibling relationships. Or is it not possible without some deeper work in the library? Or is it possible by dropping down and working at the Graphiti layer itself somehow?Have you written an example with some code somewhere of how to do this? (I ask because I relied heavily on your excellent blog posts with the Todo examples when getting up and running).
Any info or pointers would be greatly appreciated. Thanks again!
The text was updated successfully, but these errors were encountered: