Skip to content

Commit

Permalink
style(*): clean-up imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Sep 19, 2023
1 parent 47546c7 commit 06a5924
Show file tree
Hide file tree
Showing 37 changed files with 90 additions and 116 deletions.
5 changes: 4 additions & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
unstable_features = true
max_width = 120
struct_lit_width = 120
tab_spaces = 2
tab_spaces = 2
imports_granularity = "Module"
group_imports = "StdExternalCrate"
4 changes: 3 additions & 1 deletion assets/jsonplaceholder.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ type Post {
userId: Int!
title: String!
body: String!
user: User @http(path: "/users/{{value.userId}}")
user: User
@http(path: "/users", query: {id: "{{parent.value.userId}}"})
@batch(key: "userId", path: ["id"])
}
2 changes: 1 addition & 1 deletion lint.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cargo fmt
cargo +nightly fmt
cargo clippy --all-targets --all-features --fix --allow-staged --allow-dirty
10 changes: 4 additions & 6 deletions src/blueprint/blueprint.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use std::collections::HashMap;

use async_graphql::dynamic::{Schema, SchemaBuilder};
use async_graphql::extensions::ApolloTracing;
use async_graphql::*;
use derive_setters::Setters;
use serde_json::Value;

use crate::config;

use super::GlobalTimeout;
use crate::lambda::Expression;
use crate::lambda::Lambda;
use async_graphql::extensions::ApolloTracing;
use async_graphql::*;
use crate::config;
use crate::lambda::{Expression, Lambda};

/// Blueprint is an intermediary representation that allows us to generate graphQL APIs.
/// It can only be generated from a valid Config.
Expand Down
16 changes: 5 additions & 11 deletions src/blueprint/from_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,18 @@ use async_graphql::parser::types::ConstDirective;
use async_graphql::InputType;
use regex::Regex;

use crate::blueprint;
use super::UnionTypeDefinition;
use crate::blueprint::Type::ListType;
use crate::blueprint::*;
use crate::config;
use crate::config::{Arg, Field};
use crate::config::{Config, InlineType};
use crate::config::{Arg, Config, Field, InlineType};
use crate::directive::DirectiveCodec;
use crate::endpoint::Endpoint;
use crate::http::Method;
use crate::http::Scheme;
use crate::http::{Method, Scheme};
use crate::inet_address::InetAddress;
use crate::json::JsonSchema;
use crate::lambda::Lambda;
use crate::valid::OptionExtension;
use crate::valid::Valid as ValidDefault;
use crate::valid::{ValidExtensions, ValidationError, VectorExtension};

use super::UnionTypeDefinition;
use crate::valid::{OptionExtension, Valid as ValidDefault, ValidExtensions, ValidationError, VectorExtension};
use crate::{blueprint, config};

type Valid<A> = ValidDefault<A, String>;

Expand Down
9 changes: 4 additions & 5 deletions src/blueprint/into_schema.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::borrow::Cow;

use std::sync::Arc;

use async_graphql::dynamic::{self, FieldFuture, SchemaBuilder};

use crate::blueprint::Definition;
use crate::blueprint::{Blueprint, Type};
use async_graphql::dynamic::{
FieldFuture, SchemaBuilder, {self},
};

use crate::blueprint::{Blueprint, Definition, Type};
use crate::http::RequestContext;
use crate::lambda::EvaluationContext;

Expand Down
1 change: 0 additions & 1 deletion src/blueprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ mod into_schema;
mod timeout;

pub use blueprint::*;

pub use timeout::GlobalTimeout;
10 changes: 4 additions & 6 deletions src/blueprint/timeout.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use async_graphql::ServerError;
use async_graphql::{
extensions::{Extension, ExtensionContext, ExtensionFactory, NextExecute},
Response,
};
use async_graphql_value::ConstValue;
use std::sync::Arc;
use std::time::Duration;

use async_graphql::extensions::{Extension, ExtensionContext, ExtensionFactory, NextExecute};
use async_graphql::{Response, ServerError};
use async_graphql_value::ConstValue;
use tokio::time::timeout;

pub struct GlobalTimeout;
Expand Down
3 changes: 2 additions & 1 deletion src/cli/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ impl From<ValidationError<String>> for CLIError {

#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use stripmargin::StripMargin;

use super::*;

#[test]
fn test_no_newline() {
let input = "Hello";
Expand Down
4 changes: 2 additions & 2 deletions src/cli/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::config::Config;

use colored::*;

use crate::config::Config;

pub struct Fmt {}

impl Fmt {
Expand Down
6 changes: 3 additions & 3 deletions src/cli/tc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use std::fs;
use anyhow::Result;
use clap::Parser;

use super::command::{Cli, Command};
use crate::blueprint::Blueprint;
use crate::cli::fmt::Fmt;
use crate::config::Config;
use crate::http::start_server;
use crate::print_schema;
use crate::{blueprint::Blueprint, config::Config};

use super::command::{Cli, Command};

pub async fn run() -> Result<()> {
let cli = Cli::parse();
Expand Down
5 changes: 2 additions & 3 deletions src/config/config.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use std::collections::{BTreeMap, HashSet};

use anyhow::Result;
use async_graphql::parser::types::ServiceDocument;
use derive_setters::Setters;
use serde::{Deserialize, Serialize};
use serde_json::Value;

use super::{Proxy, Server};
use crate::batch::Batch;
use crate::http::Method;
use crate::json::JsonSchema;
use crate::mustache::Mustache;
use crate::path::{path_deserialize, path_serialize, Path};
use anyhow::Result;

use super::{Proxy, Server};

#[derive(Serialize, Deserialize, Clone, Debug, Default, Setters)]
#[serde(rename_all = "camelCase")]
Expand Down
3 changes: 1 addition & 2 deletions src/config/from_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use async_graphql::Name;

use crate::batch::Batch;
use crate::config;
use crate::config::Config;
use crate::config::{GraphQL, RootSchema, Server, Union};
use crate::config::{Config, GraphQL, RootSchema, Server, Union};
use crate::directive::DirectiveCodec;

fn from_document(doc: ServiceDocument) -> Config {
Expand Down
3 changes: 1 addition & 2 deletions src/config/into_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use async_graphql::parser::types::*;
use async_graphql::{Pos, Positioned};
use async_graphql_value::{ConstValue, Name};

use crate::directive::DirectiveCodec;

use super::Config;
use crate::directive::DirectiveCodec;

fn pos<A>(a: A) -> Positioned<A> {
Positioned::new(a, Pos::default())
Expand Down
3 changes: 1 addition & 2 deletions src/directive.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use anyhow::Result;
use async_graphql::parser::types::ConstDirective;
use async_graphql::{Name, Pos, Positioned};
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use serde_path_to_error::deserialize;

use anyhow::Result;

use crate::valid::ValidationError;

fn pos<A>(a: A) -> Positioned<A> {
Expand Down
14 changes: 6 additions & 8 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#![allow(clippy::too_many_arguments)]

use serde_json::json;
use std::collections::BTreeMap;
use std::sync::Arc;

use anyhow::Result;
use derive_setters::Setters;
use serde_json::json;
use url::Url;

use crate::batch::Batch;
use crate::http::Method;
use crate::http::Scheme;
use crate::http::{Method, Scheme};
use crate::inet_address::InetAddress;
use crate::json::JsonLike;
use crate::json::JsonSchema;
use crate::json::{JsonLike, JsonSchema};
use crate::mustache::Mustache;
use crate::path::{Path, Segment};
use anyhow::Result;

use derive_setters::Setters;

const EMPTY_VEC: &Vec<String> = &vec![];

Expand Down
5 changes: 1 addition & 4 deletions src/http/client.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use std::time::Duration;

use http_cache_reqwest::{Cache, CacheMode, HttpCache, HttpCacheOptions, MokaManager};

use reqwest::Client;

use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};

use crate::config::Server;

use super::Response;
use crate::config::Server;

#[derive(Clone)]
pub struct HttpClient {
Expand Down
14 changes: 4 additions & 10 deletions src/http/data_loader.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use std::hash::{Hash, Hasher};
use std::sync::Arc;
use std::time::Duration;

use anyhow::Result;
use async_graphql::async_trait;
use async_graphql::dataloader::{DataLoader, HashMapCache, Loader};
use async_graphql::futures_util::future::join_all;
use async_graphql_value::ConstValue;
use derive_setters::Setters;

use url::Url;

use crate::http::Method;
use crate::http::Response;

use crate::http::HttpClient;
use crate::http::{HttpClient, Method, Response};
use crate::json::JsonLike;
use std::hash::{Hash, Hasher};

use anyhow::Result;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EndpointKey {
pub url: Url,
Expand Down
6 changes: 4 additions & 2 deletions src/http/memo_client.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::{collections::HashMap, sync::Mutex};
use std::collections::HashMap;
use std::sync::Mutex;

use super::HttpClient;
use anyhow::Result;
use http_cache_semantics::RequestLike;
use hyper::Uri;
use reqwest::Method;

use super::HttpClient;

// TODO: drop MemoClient
#[allow(dead_code)]
pub struct MemoClient {
Expand Down
1 change: 0 additions & 1 deletion src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::time::Duration;
use cache_control::CacheControl;
pub use client::*;
pub use data_loader::*;

use hyper::header::CACHE_CONTROL;
pub use method::Method;
pub use request_context::RequestContext;
Expand Down
7 changes: 4 additions & 3 deletions src/http/request_context.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::{collections::HashMap, sync::Mutex};
use std::collections::HashMap;
use std::sync::Mutex;

use async_graphql::dataloader::{DataLoader, HashMapCache};
use derive_setters::Setters;
use hyper::{HeaderMap, Uri};

use super::memo_client::MemoClient;
use super::{EndpointKey, HttpClient, HttpDataLoader, Response, ServerContext};
use crate::config::Server;

use super::{memo_client::MemoClient, EndpointKey, HttpClient, HttpDataLoader, Response, ServerContext};

#[derive(Setters)]
pub struct RequestContext {
pub data_loader: DataLoader<HttpDataLoader, HashMapCache>,
Expand Down
4 changes: 1 addition & 3 deletions src/http/response.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use anyhow::Result;
use derive_setters::Setters;

use http_cache_semantics::ResponseLike;

use anyhow::Result;

#[derive(Clone, Debug, Default, Setters)]
pub struct Response {
pub status: reqwest::StatusCode,
Expand Down
3 changes: 2 additions & 1 deletion src/http/scheme.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serde::{Deserialize, Serialize};
use std::fmt::Display;

use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum Scheme {
Http,
Expand Down
3 changes: 0 additions & 3 deletions src/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ use std::fs;
use std::sync::Arc;

use anyhow::Result;

use async_graphql::http::GraphiQLSource;

use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, HeaderMap, Request, Response, StatusCode};

use super::request_context::RequestContext;
use super::ServerContext;
use crate::async_graphql_hyper;
use crate::blueprint::Blueprint;

use crate::cli::CLIError;
use crate::config::Config;

Expand Down
4 changes: 3 additions & 1 deletion src/http/server_context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use async_graphql::dynamic;
use derive_setters::Setters;

use crate::{blueprint::Blueprint, config::Server, http::HttpClient};
use crate::blueprint::Blueprint;
use crate::config::Server;
use crate::http::HttpClient;

#[derive(Clone, Setters)]
pub struct ServerContext {
Expand Down
3 changes: 2 additions & 1 deletion src/inet_address.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::Display;

use derive_setters::Setters;
use serde::{Deserialize, Serialize};
use std::fmt::Display;
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Setters)]
pub struct InetAddress {
pub host: String,
Expand Down
3 changes: 2 additions & 1 deletion src/json/json_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ mod tests {
use pretty_assertions::assert_eq;
use serde_json::json;

use crate::json::{group_by_key, json_like::gather_path_matches};
use crate::json::group_by_key;
use crate::json::json_like::gather_path_matches;

#[test]
fn test_gather_path_matches() {
Expand Down
Loading

0 comments on commit 06a5924

Please sign in to comment.