Skip to content

Commit

Permalink
Rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sunli829 committed May 1, 2022
1 parent ffb8cb9 commit c98cc26
Show file tree
Hide file tree
Showing 28 changed files with 180 additions and 115 deletions.
12 changes: 12 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
edition = "2021"
newline_style = "Unix"
# comments
normalize_comments = true
wrap_comments = true
format_code_in_doc_comments = true
# imports
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
# report
#report_fixme="Unnumbered"
#report_todo="Unnumbered"
9 changes: 4 additions & 5 deletions actix-web/error-extensions/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#[macro_use]
extern crate thiserror;

use actix_web::web::Data;
use actix_web::{guard, web, App, HttpResponse, HttpServer};
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use actix_web::{guard, web, web::Data, App, HttpResponse, HttpServer};
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
EmptyMutation, EmptySubscription, ErrorExtensions, FieldError, FieldResult, Object, ResultExt,
Schema,
};
Expand Down Expand Up @@ -49,8 +48,8 @@ impl QueryRoot {
.map_err(|e: std::num::ParseIntError| e.extend_with(|_, e| e.set("code", 404)))?)
}

// THIS does unfortunately NOT work because ErrorExtensions is implemented for &E and not E.
// Which is necessary for the overwrite by the user.
// THIS does unfortunately NOT work because ErrorExtensions is implemented for
// &E and not E. Which is necessary for the overwrite by the user.

// async fn parse_with_extensions_result(&self) -> FieldResult<i32> {
// Ok("234a".parse().extend_err(|_| json!({"code": 404}))?)
Expand Down
9 changes: 5 additions & 4 deletions actix-web/starwars/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use actix_web::web::Data;
use actix_web::{guard, web, App, HttpResponse, HttpServer, Result};
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::{EmptyMutation, EmptySubscription, Schema};
use actix_web::{guard, web, web::Data, App, HttpResponse, HttpServer, Result};
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
EmptyMutation, EmptySubscription, Schema,
};
use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse};
use starwars::{QueryRoot, StarWars, StarWarsSchema};

Expand Down
9 changes: 5 additions & 4 deletions actix-web/subscription/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use actix_web::web::Data;
use actix_web::{guard, web, App, HttpRequest, HttpResponse, HttpServer, Result};
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::Schema;
use actix_web::{guard, web, web::Data, App, HttpRequest, HttpResponse, HttpServer, Result};
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
Schema,
};
use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse, GraphQLSubscription};
use books::{BooksSchema, MutationRoot, QueryRoot, Storage, SubscriptionRoot};

Expand Down
11 changes: 7 additions & 4 deletions actix-web/token-from-header/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use actix_web::http::header::HeaderMap;
use actix_web::{guard, web, App, HttpRequest, HttpResponse, HttpServer, Result};
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::{Data, EmptyMutation, Schema};
use actix_web::{
guard, http::header::HeaderMap, web, App, HttpRequest, HttpResponse, HttpServer, Result,
};
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
Data, EmptyMutation, Schema,
};
use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse, GraphQLSubscription};
use token::{on_connection_init, QueryRoot, SubscriptionRoot, Token, TokenSchema};

Expand Down
9 changes: 5 additions & 4 deletions actix-web/upload/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use actix_web::web::Data;
use actix_web::{guard, web, App, HttpResponse, HttpServer};
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig, MultipartOptions};
use async_graphql::{EmptySubscription, Schema};
use actix_web::{guard, web, web::Data, App, HttpResponse, HttpServer};
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig, MultipartOptions},
EmptySubscription, Schema,
};
use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse};
use files::{FilesSchema, MutationRoot, QueryRoot, Storage};

Expand Down
16 changes: 10 additions & 6 deletions axum/starwars/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::{EmptyMutation, EmptySubscription, Schema};
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
EmptyMutation, EmptySubscription, Schema,
};
use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
use axum::extract::Extension;
use axum::response::{self, IntoResponse};
use axum::routing::get;
use axum::{Router, Server};
use axum::{
extract::Extension,
response::{self, IntoResponse},
routing::get,
Router, Server,
};
use starwars::{QueryRoot, StarWars, StarWarsSchema};

async fn graphql_handler(
Expand Down
15 changes: 10 additions & 5 deletions axum/subscription/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::Schema;
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
Schema,
};
use async_graphql_axum::{GraphQLRequest, GraphQLResponse, GraphQLSubscription};
use axum::response::{self, IntoResponse};
use axum::routing::get;
use axum::{extract::Extension, Router, Server};
use axum::{
extract::Extension,
response::{self, IntoResponse},
routing::get,
Router, Server,
};
use books::{BooksSchema, MutationRoot, QueryRoot, Storage, SubscriptionRoot};

async fn graphql_handler(schema: Extension<BooksSchema>, req: GraphQLRequest) -> GraphQLResponse {
Expand Down
16 changes: 10 additions & 6 deletions axum/upload/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::{EmptySubscription, Schema};
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
EmptySubscription, Schema,
};
use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
use axum::extract::Extension;
use axum::response::{Html, IntoResponse};
use axum::routing::get;
use axum::Router;
use axum::{
extract::Extension,
response::{Html, IntoResponse},
routing::get,
Router,
};
use files::{FilesSchema, MutationRoot, QueryRoot, Storage};
use hyper::{Method, Server};
use tower_http::cors::{CorsLayer, Origin};
Expand Down
3 changes: 2 additions & 1 deletion federation/federation-accounts/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::convert::Infallible;

use async_graphql::{EmptyMutation, EmptySubscription, Object, Schema, SimpleObject, ID};
use async_graphql_warp::graphql;
use std::convert::Infallible;
use warp::{Filter, Reply};

#[derive(SimpleObject)]
Expand Down
3 changes: 2 additions & 1 deletion federation/federation-products/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::convert::Infallible;

use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema, SimpleObject};
use async_graphql_warp::graphql;
use std::convert::Infallible;
use warp::{Filter, Reply};

#[derive(SimpleObject)]
Expand Down
3 changes: 2 additions & 1 deletion federation/federation-reviews/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::convert::Infallible;

use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema, SimpleObject, ID};
use async_graphql_warp::graphql;
use std::convert::Infallible;
use warp::{Filter, Reply};

struct User {
Expand Down
7 changes: 3 additions & 4 deletions models/books/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
mod simple_broker;

use std::{sync::Arc, time::Duration};

use async_graphql::{Context, Enum, Object, Result, Schema, Subscription, ID};
use futures_util::lock::Mutex;
use futures_util::{Stream, StreamExt};
use futures_util::{lock::Mutex, Stream, StreamExt};
use simple_broker::SimpleBroker;
use slab::Slab;
use std::sync::Arc;
use std::time::Duration;

pub type BooksSchema = Schema<QueryRoot, MutationRoot, SubscriptionRoot>;

Expand Down
14 changes: 8 additions & 6 deletions models/books/src/simple_broker.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::any::{Any, TypeId};
use std::collections::HashMap;
use std::marker::PhantomData;
use std::pin::Pin;
use std::sync::Mutex;
use std::task::{Context, Poll};
use std::{
any::{Any, TypeId},
collections::HashMap,
marker::PhantomData,
pin::Pin,
sync::Mutex,
task::{Context, Poll},
};

use futures_channel::mpsc::{self, UnboundedReceiver, UnboundedSender};
use futures_util::{Stream, StreamExt};
Expand Down
6 changes: 3 additions & 3 deletions models/starwars/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mod model;

use async_graphql::{EmptyMutation, EmptySubscription, Schema};
use model::Episode;
use slab::Slab;
use std::collections::HashMap;

use async_graphql::{EmptyMutation, EmptySubscription, Schema};
use model::Episode;
pub use model::QueryRoot;
use slab::Slab;
pub type StarWarsSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;

pub struct StarWarsChar {
Expand Down
7 changes: 5 additions & 2 deletions models/starwars/src/model.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#![allow(clippy::needless_lifetimes)]

use async_graphql::{
connection::{query, Connection, Edge, EmptyFields},
Context, Enum, Error, Interface, Object, Result,
};

use super::StarWars;
use crate::StarWarsChar;
use async_graphql::connection::{query, Connection, Edge, EmptyFields};
use async_graphql::{Context, Enum, Error, Interface, Object, Result};

/// One of the films in the Star Wars Trilogy
#[derive(Enum, Copy, Clone, Eq, PartialEq)]
Expand Down
10 changes: 5 additions & 5 deletions poem/starwars/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::{EmptyMutation, EmptySubscription, Schema};
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
EmptyMutation, EmptySubscription, Schema,
};
use async_graphql_poem::GraphQL;
use poem::listener::TcpListener;
use poem::web::Html;
use poem::{get, handler, IntoResponse, Route, Server};
use poem::{get, handler, listener::TcpListener, web::Html, IntoResponse, Route, Server};
use starwars::{QueryRoot, StarWars};

#[handler]
Expand Down
10 changes: 5 additions & 5 deletions poem/subscription-redis/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::{Context, Object, Result, Schema, Subscription};
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
Context, Object, Result, Schema, Subscription,
};
use async_graphql_poem::{GraphQL, GraphQLSubscription};
use futures_util::{Stream, StreamExt};
use poem::listener::TcpListener;
use poem::web::Html;
use poem::{get, handler, IntoResponse, Route, Server};
use poem::{get, handler, listener::TcpListener, web::Html, IntoResponse, Route, Server};
use redis::{AsyncCommands, Client};

struct QueryRoot;
Expand Down
10 changes: 5 additions & 5 deletions poem/subscription/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::Schema;
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
Schema,
};
use async_graphql_poem::{GraphQL, GraphQLSubscription};
use books::{MutationRoot, QueryRoot, Storage, SubscriptionRoot};
use poem::listener::TcpListener;
use poem::web::Html;
use poem::{get, handler, IntoResponse, Route, Server};
use poem::{get, handler, listener::TcpListener, web::Html, IntoResponse, Route, Server};

#[handler]
async fn graphql_playground() -> impl IntoResponse {
Expand Down
17 changes: 11 additions & 6 deletions poem/token-from-header/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig, ALL_WEBSOCKET_PROTOCOLS};
use async_graphql::{EmptyMutation, Schema};
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig, ALL_WEBSOCKET_PROTOCOLS},
EmptyMutation, Schema,
};
use async_graphql_poem::{GraphQLProtocol, GraphQLRequest, GraphQLResponse, GraphQLWebSocket};
use poem::http::HeaderMap;
use poem::listener::TcpListener;
use poem::web::{websocket::WebSocket, Data, Html};
use poem::{get, handler, EndpointExt, IntoResponse, Route, Server};
use poem::{
get, handler,
http::HeaderMap,
listener::TcpListener,
web::{websocket::WebSocket, Data, Html},
EndpointExt, IntoResponse, Route, Server,
};
use token::{on_connection_init, QueryRoot, SubscriptionRoot, Token, TokenSchema};

fn get_token_from_headers(headers: &HeaderMap) -> Option<Token> {
Expand Down
17 changes: 11 additions & 6 deletions poem/upload/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::{EmptySubscription, Schema};
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
EmptySubscription, Schema,
};
use async_graphql_poem::{GraphQLRequest, GraphQLResponse};
use files::{FilesSchema, MutationRoot, QueryRoot, Storage};
use poem::listener::TcpListener;
use poem::middleware::Cors;
use poem::web::{Data, Html};
use poem::{get, handler, EndpointExt, IntoResponse, Route, Server};
use poem::{
get, handler,
listener::TcpListener,
middleware::Cors,
web::{Data, Html},
EndpointExt, IntoResponse, Route, Server,
};

#[handler]
async fn index(schema: Data<&FilesSchema>, req: GraphQLRequest) -> GraphQLResponse {
Expand Down
16 changes: 9 additions & 7 deletions tide/dataloader-postgres/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use async_graphql::dataloader::{DataLoader, Loader};
use async_graphql::futures_util::TryStreamExt;
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use std::{collections::HashMap, env};

use async_graphql::{
dataloader::{DataLoader, Loader},
futures_util::TryStreamExt,
http::{playground_source, GraphQLPlaygroundConfig},
Context, EmptyMutation, EmptySubscription, FieldError, Object, Result, Schema, SimpleObject,
};
use async_std::task;
use async_trait::async_trait;
use itertools::Itertools;
use sqlx::{Pool, Postgres};
use std::collections::HashMap;
use std::env;
use tide::{http::mime, Body, Response, StatusCode};

#[derive(sqlx::FromRow, Clone, SimpleObject)]
Expand Down Expand Up @@ -121,10 +121,12 @@ async fn run() -> Result<()> {

#[cfg(test)]
mod tests {
use super::*;
use std::time::Duration;

use async_std::prelude::*;
use serde_json::{json, Value};
use std::time::Duration;

use super::*;

#[test]
fn sample() -> Result<()> {
Expand Down
Loading

0 comments on commit c98cc26

Please sign in to comment.