You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey y'all, I'm working on a nice example I'd like to eventually put in the docs / book, but I'm a little stuck on making it modular.
The current minimal example looks nice, but it quickly gets cumbersome to have a bunch of definitions in one massive file. Here's what I'm trying to do roughly:
Structuring a project this way will make it easier to add new functionality to a GraphQL project made in Juniper. The only problem I'm having is I don't know how to "merge" these separate schemas into one schema at the end at compile time.
use juniper;use juniper_from_schema::graphql_schema_from_file;usesuper::Context;graphql_schema_from_file!("src/graphql/hello/schema.gql");pubstructQuery;implQueryFieldsforQuery{fnfield_hello(&self,executor:&juniper::Executor<'_,Context>,name:String,) -> juniper::FieldResult<String>{Ok(format!("Hello, {}!", name))}}
And in a module users: schema.gql
typeQuery {
# The directive makes the return value `FieldResult<String>` # rather than the default `FieldResult<&String>`currentUser: String!@juniper(ownership: "owned")
}
mod.rs
usesuper::Context;use juniper;use juniper_from_schema::graphql_schema_from_file;graphql_schema_from_file!("src/graphql/users/schema.gql");pubstructQuery;pubstructUser{name:String,}implQueryFieldsforQuery{fnfield_current_user(&self,executor:&juniper::Executor<'_,Context>,) -> juniper::FieldResult<String>{let user = User{name:String::from("Ferris"),};Ok(format!("The current user is {}.", user.name))}}
These modules can contain anything you want. There's just one thing I couldn't figure out.
How would you then "plop" their Query and Mutation types into the root query and mutation types of the root schema?
Like, for example in the root graphql module of the repo I linked:
use juniper;mod hello;mod users;pubstructContext;impl juniper::ContextforContext{}pubstructQuery;#[juniper::object(Context = Context,)]implQuery{// ..hello::Query// ..users::Query// ^ How do I put the contents of these here at compile time?// The idea is to have a nice folder structure separated by concern.}pubstructMutation;#[juniper::object(Context = Context,)]implMutation{}pubtypeSchema = juniper::RootNode<'static,Query,Mutation>;
I think having this would enable us to make more scalable projects. I've already used this folder structure in a JavaScript-based GraphQL server in production and it's great. Really easy to add stuff to.
The text was updated successfully, but these errors were encountered:
vladinator1000
changed the title
Making an example with modular folder structure
An example with modular folder structure
Jul 19, 2019
Hey y'all, I'm working on a nice example I'd like to eventually put in the docs / book, but I'm a little stuck on making it modular.
The current minimal example looks nice, but it quickly gets cumbersome to have a bunch of definitions in one massive file. Here's what I'm trying to do roughly:
Structuring a project this way will make it easier to add new functionality to a GraphQL project made in Juniper. The only problem I'm having is I don't know how to "merge" these separate schemas into one schema at the end at compile time.
I've created a little repository to illustrate the goal: https://github.com/savovs/juniper-schema
A minimal example would be if you have more than one module.
i.e. in a module hello:
schema.gql
mod.rs
And in a module users:
schema.gql
mod.rs
These modules can contain anything you want. There's just one thing I couldn't figure out.
How would you then "plop" their Query and Mutation types into the root query and mutation types of the root schema?
Like, for example in the root graphql module of the repo I linked:
I think having this would enable us to make more scalable projects. I've already used this folder structure in a JavaScript-based GraphQL server in production and it's great. Really easy to add stuff to.
The text was updated successfully, but these errors were encountered: