From fe13723323d8943856b8353a43b2349fe58fe731 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Wed, 10 Jul 2019 20:56:48 +0200 Subject: [PATCH] Move GraphQL-related model code to a separate module --- src/models/customer.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/models/customer.rs b/src/models/customer.rs index 5e600f5..ce38caf 100644 --- a/src/models/customer.rs +++ b/src/models/customer.rs @@ -1,7 +1,6 @@ use chrono::NaiveDateTime; use diesel::prelude::*; -use juniper::FieldResult; -use juniper_codegen::{object, GraphQLInputObject}; +use juniper_codegen::GraphQLInputObject; use crate::models::{Invoice, Task}; use crate::schema::customers; @@ -54,19 +53,6 @@ impl Customer { } } -#[object(Context = DbConn)] -impl Customer { - /// Returns the invoices billed to the customer. - fn invoices(&self, context: &DbConn) -> FieldResult> { - self.invoices(context).map_err(Into::into) - } - - /// Returns the project/tasks associated with the customer. - fn tasks(&self, context: &DbConn) -> FieldResult> { - self.tasks(context).map_err(Into::into) - } -} - /// The new customer model /// /// This model represents a new customer that can be inserted into the database. @@ -94,3 +80,22 @@ pub struct NewCustomer { /// Flag whether the customer requires time specificaions pub time_specification: bool, } + +mod graphql { + use super::{Customer, DbConn, Invoice, Task}; + + use juniper::{object, FieldResult}; + + #[object(Context = DbConn)] + impl Customer { + /// Returns the invoices billed to the customer. + fn invoices(&self, context: &DbConn) -> FieldResult> { + self.invoices(context).map_err(Into::into) + } + + /// Returns the project/tasks associated with the customer. + fn tasks(&self, context: &DbConn) -> FieldResult> { + self.tasks(context).map_err(Into::into) + } + } +}