Graphql. can I make this work

Hello,

I have this schema

table! {
    members (id) {
        id -> Int4,
        name -> Varchar,
        knockouts -> Int4,
        team_id -> Int4,
    }
}

table! {
    teams (id) {
        id -> Int4,
        name -> Varchar,
    }
}

joinable!(members -> teams (team_id));

allow_tables_to_appear_in_same_query!(
    members,
    teams,
);

now I wonder if I enter a team name or a teamid can I with graphql make a list of all members of a team

I have already this :

#[juniper::object(description = "A team of members")]
impl Team {
  pub fn id(&self) -> i32 {
    self.id
  }

  pub fn name(&self) -> &str {
    self.name.as_str()
  }

  pub fn members(&self) -> Vec<Member> {
    use crate::schema::members::dsl::*;
    let connection = establish_connection(); 
    members 
       .filter(team_id.eq(self.id))
       .limit(100)
       .load::<Member>(&connection)
       .expect("Error loading members")
  }
}

I'm not sure what the actual Question is here.
Teams have members, and so With graphql it's normal for a Team to have a member field which will return a list of members. I don't know which specific Database or storage you are using but in general your approach is correct. You can define the graphql fields as methods in the Impl block of the type, and you can have children like members be retrieved in the method.

One change I would recommend is, instead of reconnecting in the members, you should Connect only once when the app starts and use it as the context.

Here's some snippets from a small forum like thing I'm making as a hobby project with mongodb

in main.rs

//Have a static client here
static CLIENT: Lazy<db::Client> = Lazy::new(db::connect);

There's probably a better way to pass along the client instead of making it static, I'm also just hacking it together for now. Will make it better after everything works. Regardless, Connection is done only once.

in main.rs

//Implement Context for Client, so it can be used as Context
impl juniper::Context for Client {}

async fn graphql(
    st: web::Data<Arc<Schema>>,
    data: web::Json<GraphQLRequest>,
) -> Result<HttpResponse, Error> {
    let res = data.execute(&st, &*CLIENT); //Passing the client here 
    let result = serde_json::to_string(&res)?;
    Ok(HttpResponse::Ok()
        .content_type("application/json")
        .body(result))
}

in article.rs

//notice the 'Context', it's the same Type passed in at main.rs
#[juniper::object(Context = Client)]
impl Article {
    fn id(&self) -> &str {
        self.id.as_str()
    }
    fn title(&self) -> &str {
        self.title.as_str()
    }
    fn content(&self) -> &str {
        self.content.as_str()
    }
    fn imgurl(&self) -> &str {
        self.imgurl.as_str()
    }
    fn comments(&self, ctx: &Client) -> Vec<Comment> {
                           //^^^^^^ You can use it here 
        let collection = ctx.db.collection("comments");
        let comments = collection
            .find(Some(
                doc! {"articleid": ObjectId::with_string(self.id.as_str()).expect("invalid id")},
            ), None)
            .expect("fetching comments failed");

        let comments: Vec<Comment> = comments
            .into_iter()
            .map(|maybe_document| {
                let comment = maybe_document.unwrap();
                Comment::from_document(&comment)
            })
            .collect();

        comments
    }
}