I'm new to Rust so I could be barking up the wrong tree.
I'm writing a GraphQL server and I like being able to break things up into multiple files, each file concentrating on just one thing.
For my queries, rather than having one big file with all the code to handle graphql queries I'd like to create a query struct and then have each of the queries in there own files ( I know I'm using a Juniper project as an example but it's jut a way to demonstrate what I'm trying to learn).
So for now I have this.
// query.rs
#[juniper::object(Context = Context)]
impl QueryRoot {
fn members(context: &Context) -> Vec<Member> {
use crate::schema::members::dsl::*;
let connection = context.db.get().unwrap();
members
.limit(100)
.load::<Member>(&connection)
.expect("Error loading members")
}
fn teams(context: &Context) -> Vec<Team> {
use crate::schema::teams::dsl::*;
let connection = context.db.get().unwrap();
teams
.limit(100)
.load::<Team>(&connection)
.expect("Error loading teams")
}
}
Is there a way I can move the two fn's (members and teams) into their own files and if so how would I pull them into the struct?
If I have to keep all the queries in one file then the code will mushroom.