You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Vapor has the functionality to fetch an objects parent and children automatically with `@Parent`and @`Children` types. To integrate this into GraphQL, GraphQLKit provides extensions to the `Field` type that lets you use the parentor children property as a keypath. The fetching of those related objects is then done automatically.
66
+
#### `Parent`, `Children` and `Siblings`
67
+
Vapor has the functionality to fetch an objects parent, children or siblings automatically with `@Parent`, `@Children`and `@Siblings` types. To integrate this into GraphQL, GraphQLKit provides extensions to the `Field` type that lets you use the parent, children or siblings property as a keypath. Fetching of those related objects is then done automatically.
68
68
69
69
> :warning: Loading related objects in GraphQL has the [**N+1** problem](https://itnext.io/what-is-the-n-1-problem-in-graphql-dd4921cb3c1a). A solution would be to build a DataLoader package for Swift. But this hasn't been done yet.
70
70
71
71
```swift
72
-
finalclassUser {
72
+
finalclassUser: Model{
73
73
...
74
-
var userId: UUID
75
-
@Parent(key:"userId") var user: User
74
+
75
+
@Children(for: \.$user)
76
+
var todos: [Todo]
77
+
78
+
...
79
+
}
80
+
81
+
finalclass Todo: Model {
82
+
...
83
+
84
+
@Parent(key:"user_id")
85
+
var user: User
86
+
87
+
@Siblings(through: TodoTag.self, from: \.$todo, to: \.$tag)
0 commit comments