codeintel: Expose associated index/upload id in graphql layer
Created by: efritz
This adds AssociatedIndex
to Upload
resolvers and AssociatedUploads
to Index
resolvers.
In order to make sure that we don't have a common n+1 query path when dealing with these objects, I've added a prefetcher layer. To best illustrate how this works, suppose that we have the following query:
query Uploads {
lsifUploads {
nodes {
id
associatedIndex {
id
}
}
}
}
When we hit the LSIFUploadsConnection
resolver, we create a distinct resolver for each upload. In order to communicate between sibling resolvers, we pass in a prefetcher
instance that is shared between the siblings. Whenever an upload record resolver is created, it will stash any associated index identifier in the prefetcher (and symmetrically with index records). When the resolver actually wants to resolve the index, it asks the prefetcher for an object by id, which will perform a batch database query with all stashed identifiers and cache the result.
This reduces the number of queries for the query above from n+1
to two.