juniper-from-schema icon indicating copy to clipboard operation
juniper-from-schema copied to clipboard

Context type with generics not supported

Open librelois opened this issue 5 years ago • 2 comments

I need a Context type with generics because it contains a database handler whose type varies according to the situations. The Context type with generics is supported by juniper: https://docs.rs/juniper/0.14.1/juniper/macro.graphql_object.html#generics-and-lifetimes

But this doesn't seem to be supported by juniper-from-schema :

error[E0107]: wrong number of type arguments: expected 1, found 0
  --> lib/modules/gva/src/schema.rs:37:19
   |
37 |     context_type: Context<DB: BcDbInReadTx>
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 type argument

error[E0229]: associated type bindings are not allowed here
  --> lib/modules/gva/src/schema.rs:37:31
   |
37 |     context_type: Context<DB: BcDbInReadTx>
   |                           ^^^^^^^^^^^^^^^^ associated type not allowed here

error: aborting due to 2 previous errors

Have you planned to support context type with generics and/or explicit lifetime?

librelois avatar Dec 01 '19 22:12 librelois

Good catch. I would like to get https://github.com/davidpdrsn/juniper-from-schema/pull/74 merged first so we don't have to migrate more graphql_object! macro code to juniper::object. That PR is currently blocked by https://github.com/graphql-rust/juniper/pull/441. I have requested a re-review of that from @theduke so lets wait and see.

Until then you might be able to box your db type

struct Context {
    db: Box<dyn BcDbInReadTx>,
}

davidpdrsn avatar Dec 11 '19 17:12 davidpdrsn

Note to self: I would also be cool to explore the context being generic over one or more lifetimes.

davidpdrsn avatar Jan 15 '20 08:01 davidpdrsn