Skip to content

Write docs for using Context with a lifetime #143

Open
@pyrossh

Description

@pyrossh

Right now my context has a lifetime

use juniper::Context as JuniperContext;
use postgres::transaction::Transaction;

pub struct Context<'a> {
    pub tx: Transaction<'a>,
}

impl<'a> JuniperContext for Context<'a> {}

impl<'a> Context<'a> {
    pub fn new(tx: Transaction<'a>) -> Context<'a> {
        Context { tx: tx }
    }
}

But when I try to specify the same lifetime in a resolver then it gives me this error,

error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
 --> src/schema/query.rs:7:18
  |
7 | graphql_object!(<'a> QueryRoot: Context<'a> as "Query" |&self| {
  |                  ^^ unconstrained lifetime parameter
use models::user::User;
use schema::context::Context;

pub struct QueryRoot;

graphql_object!(<'a> QueryRoot: Context<'a> as "Query" |&self| {
    field users(&executor) -> FieldResult<Vec<User>> {
      Ok(vec![])
    }
});

Metadata

Metadata

Assignees

Labels

k::documentationRelated to project documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions