Hello, I am looking for a piece of advice since this is a problem I have in my head for a while. I am referring to the following TODO (t15733312) in the ConnectionHandler: https://github.com/facebook/relay/blob/31d51a2435557033d4995815f2b76f11f1a1eb05/packages/relay-runtime/handlers/connection/ConnectionHandler.js#L263-L265 (I might have a need for it)
So, we have a query with rather complex inputs. Specifically, we take into account one input object with filters for the connection (simplified):
leads(legacyFilter: $legacyFilter, first: $count, after: null)
@connection(key: "LeadsList_leads", filters: ["legacyFilter"]) {
edges {
# ...
}
}
The legacy filter looks something like this:
input LeadsLegacyFilter {
labels: [ID!]
owners: [ID!]
sources: [ID!]
status: LeadStatus # enum: ALL | ARCHIVED | ...
}
This results in unique virtual connections like so:
client:root:__LeadsList_leads_connection(legacyFilter:{"labels":[],"owners":[],"sources":[],"status":"ALL"})
client:root:__LeadsList_leads_connection(legacyFilter:{"labels":[],"owners":[],"sources":[],"status":"ARCHIVED"})
# but also like this:
client:root:__LeadsList_leads_connection(legacyFilter:{"labels":["TGFiZWw6MWQ2YmFjNjAtODQ0Zi0xMWVhLTg3N2EtZTMzMGRiNWQ4Y2E4"],"owners":["VXNlcjoxMDM4MjYzNA"],"sources":["TGVhZFNvdXJjZTpMZWFkYm9vc3Rlcg"],"status":"ALL"})
Now the issue is starting to be more visible. I need to operate on top of these connections, however, it's quite challenging considering the dynamic nature of the key. For example, one common operation is to move the records between connections with status:ALL and status:ARCHIVED which means I have to update any connection no matter the other filters.
What is the best way how to approach it? Would be some different query design more beneficial? Or perhaps, is the getConnections mentioned in the TODO a correct way? And if so, how to actually implement it?
Thank you very much for your help! I like the work you are doing on Relay! 馃檪
What a strange coincidence: I just found https://github.com/facebook/relay/issues/1861 thanks to @taion adding there a comment just now. 馃槄 Still, I'd like to leave this post open at least for a while to maybe get some updated insights. 馃
It's essentially the same question :p
I'll have my thing open-sourced shortly. It implements the getConnections API per https://github.com/facebook/relay/issues/1861#issuecomment-357830179.
@taion Do I understand correctly your solution is a wrapper around the default connection handler which exposes this extra method? In other words, you register it in Environment.handlerProvider under the same handle key connection?
Right. I run some extra code to save a maps from each connection storage key to the corresponding arguments (by overriding update), then use this extra data to drive getConnections. This follows roughly https://github.com/facebook/relay/issues/1861#issuecomment-306028398.
(Can't really use linked records here, as there's no easy way to flag them not to get GCed)
Open-sourced in https://github.com/relay-tools/relay-connection-handler-plus.
Thanks! I am going to close it as well since there is a pretty simple solution in userspace.
I have one additional question. Would a Relay team accept something like this in a PR? There are some additional changes necessary (for example the direct _mutator access is not very nice).
Most helpful comment
Open-sourced in https://github.com/relay-tools/relay-connection-handler-plus.