Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context type with generics not supported #101

Open
librelois opened this issue Dec 1, 2019 · 2 comments
Open

Context type with generics not supported #101

librelois opened this issue Dec 1, 2019 · 2 comments

Comments

@librelois
Copy link

librelois commented Dec 1, 2019

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?

@davidpdrsn
Copy link
Owner

Good catch. I would like to get #74 merged first so we don't have to migrate more graphql_object! macro code to juniper::object. That PR is currently blocked by graphql-rust/juniper#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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants