@JatinDevDG Thank you. With custom updatedAt timestamps it’s working. Unfortunately, this is very error-prone as every client always need to make sure to update that timestamp. If I forget to update the field in some written client-code, I’ll not receive the data I need.
Do you happen to know when server-side managed createdAt
and updatedAt
timestamps will be available or what the progress is on this? It would really help in a lot of cases and feels like a very basic feature to have. See also: Query sever timestamps in GraphQL?
Edit: I removed the “solution” tag as this workaround is not really what I’m thinking of.
When implementing this using updatedAt
timestamps (set from client or server-side - doesn’t matter) you have to restart the subscription every-time you get data and change the startTime
variable accordingly (see query below). Otherwise you’ll run into the same issue - over-fetching large amount of data that you don’t need.
subscription FooUpdates($startTime: DateTime!) {
queryFoo(filter: {updatedAt: {ge: $startTime} }) {
...
}
}
I suspect that restarting the websocket-connection (potentially multiple times per second) is not very nice to the server.
So instead I propose following directive:
type Foo {
value: Int!
bars: [Bar!]!
}
type Bar {
name: String!
}
subscription FooUpdates {
queryFoo @subscribeChangesOnly {
value
bars {
name
}
}
}
When using this directive, only changes (starting from subscription start) are delivered to the client. Also, changes in sub-graphs will only return the changed part of the graph.
Examples
- 100 Foos in the database, one of them will get its value changed: → Client will receive only that item.
- 100 Foos in the database, one
Bar
get its name changed: → Client will receive only thatfoo
which corresponds to the changedBar
object. Also, only the changed bar object will be returned and not all bar-childs of foo.
@JatinDevDG Please reconsider adding this feature!