Reputation: 9692
Using lookahead in GraphQL Ruby is really helpful to optimize your database queries, but it seems like you can only use it at the field level. This is fine for normal GraphQL API, but when using Apollo Federation, the entry point is not a query field, it is a reference resolver. Something like the following:
class User < BaseObject
key fields: :user_id
field :user_id, ID, null: false
underscore_reference_keys true
def self.resolve_reference(reference, _context)
Loaders::Record.for(User).load(reference[:user_id])
end
end
So you only have access to the reference (the object sent from the previous subgraph) and the context. Is there any way we can lookahead using the context?
Upvotes: 0
Views: 99