How to have a Context type with generics without passing the generics back to the schema?
I need to have a generic context that is instantiated differently in testing. (The context contains a handler to the DB that is mocked during tests).
In non-test mode, the context contains a handler to the DB and a reference to a read transaction, the type that represents the read transaction has an explicit lifetime, whose lifetime will therefore correspond to the lifetime of the context.
That's why I need to instantiate a different context for each request.
The problem is that the new macro [juniper::object] does not seem to allow to declare a context with generics without the generics going back to the Query type and therefore to the Schema.
I try:
pub struct Query {}
#[juniper::object(
// Here we specify the context type for this object.
Context = QueryContext<DB: BcDbInReadTx>,
)]
impl Query {
But obviously it doesn't compile. It compiles if I pass the generics back to Query, but as explained above it is not a possible solution in my case.
How can we declare a generic to the context only?
It seems that this was possible with the macro graphql_object!: https://docs.rs/juniper/0.14.1/juniper/macro.graphql_object.html#generics-and-lifetimes.
But I didn't try because I don't want to imply time on something depreciated.
my environment: rust 1.39 juniper 0.14.1
I bet this was accidentally dropped in the conversion to the proc macro.
Happy to take a PR with a test!