Skip to content

Commit

Permalink
Merge branch 'main' into garypen/better-subgraph-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
garypen committed Jun 29, 2022
2 parents 96a5d1e + 0a94e20 commit 2d58671
Show file tree
Hide file tree
Showing 120 changed files with 1,709 additions and 915 deletions.
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# .git-blame-ignore-revs

# Reformat with imports_granularity = Item and group_imports = StdExternalCrate
af3209126ffee9b825b694ee6913745873e8115b
4 changes: 3 additions & 1 deletion apollo-router-benchmarks/benches/basic_composition.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use criterion::{criterion_group, criterion_main, Criterion};
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;

include!("../src/shared.rs");

Expand Down
16 changes: 11 additions & 5 deletions apollo-router-scaffold/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
mod plugin;

use crate::plugin::PluginAction;
use anyhow::Result;
use clap::Subcommand;

use crate::plugin::PluginAction;

#[derive(Subcommand, Debug)]
pub enum RouterAction {
/// Manage plugins
Expand All @@ -23,13 +24,18 @@ impl RouterAction {

#[cfg(test)]
mod test {
use anyhow::{bail, Result};
use cargo_scaffold::{Opts, ScaffoldDescription};
use inflector::Inflector;
use std::collections::BTreeMap;
use std::env;
use std::path::{Path, PathBuf, MAIN_SEPARATOR};
use std::path::Path;
use std::path::PathBuf;
use std::path::MAIN_SEPARATOR;
use std::process::Command;

use anyhow::bail;
use anyhow::Result;
use cargo_scaffold::Opts;
use cargo_scaffold::ScaffoldDescription;
use inflector::Inflector;
use tempfile::TempDir;

#[test]
Expand Down
6 changes: 4 additions & 2 deletions apollo-router-scaffold/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::fs;
use std::path::Path;
use std::path::PathBuf;

use anyhow::Result;
use cargo_scaffold::ScaffoldDescription;
use clap::Subcommand;
use inflector::Inflector;
use regex::Regex;
use std::fs;
use std::path::{Path, PathBuf};
use toml::Value;

#[derive(Subcommand, Debug)]
Expand Down
102 changes: 66 additions & 36 deletions apollo-router/src/axum_http_server_factory.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,67 @@
//! Axum http server factory. Axum provides routing capability on top of Hyper HTTP.
use crate::configuration::{Configuration, ListenAddr};
use crate::graphql;
use crate::http_ext;
use crate::http_server_factory::{HttpServerFactory, HttpServerHandle, Listener, NetworkStream};
use crate::layers::DEFAULT_BUFFER_SIZE;
use crate::plugin::Handler;
use crate::router::ApolloRouterError;
use crate::ResponseBody;
use async_compression::tokio::write::{BrotliDecoder, GzipDecoder, ZlibDecoder};
use axum::extract::{Extension, Host, OriginalUri};
use axum::http::{header::HeaderMap, StatusCode};
use axum::middleware::{self, Next};
use std::collections::HashMap;
use std::pin::Pin;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
use std::time::Instant;

use async_compression::tokio::write::BrotliDecoder;
use async_compression::tokio::write::GzipDecoder;
use async_compression::tokio::write::ZlibDecoder;
use axum::extract::Extension;
use axum::extract::Host;
use axum::extract::OriginalUri;
use axum::http::header::HeaderMap;
use axum::http::StatusCode;
use axum::middleware::Next;
use axum::middleware::{self};
use axum::response::*;
use axum::routing::get;
use axum::Router;
use bytes::Bytes;
use futures::channel::oneshot;
use futures::prelude::*;
use futures::stream::BoxStream;
use futures::{channel::oneshot, prelude::*};
use http::header::CONTENT_ENCODING;
use http::{HeaderValue, Request, Uri};
use http::HeaderValue;
use http::Request;
use http::Uri;
use hyper::server::conn::Http;
use hyper::Body;
use opentelemetry::global;
use opentelemetry::trace::{SpanKind, TraceContextExt};
use opentelemetry::trace::SpanKind;
use opentelemetry::trace::TraceContextExt;
use serde_json::json;
use std::collections::HashMap;
use std::pin::Pin;
use std::str::FromStr;
use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::io::AsyncWriteExt;
use tokio::net::TcpListener;
#[cfg(unix)]
use tokio::net::UnixListener;
use tokio::sync::Notify;
use tower::buffer::Buffer;
use tower::util::BoxService;
use tower::BoxError;
use tower::MakeService;
use tower::{BoxError, ServiceExt};
use tower::ServiceExt;
use tower_http::compression::CompressionLayer;
use tower_http::trace::{MakeSpan, TraceLayer};
use tower_http::trace::MakeSpan;
use tower_http::trace::TraceLayer;
use tower_service::Service;
use tracing::{Level, Span};
use tracing::Level;
use tracing::Span;

use crate::configuration::Configuration;
use crate::configuration::ListenAddr;
use crate::graphql;
use crate::http_ext;
use crate::http_server_factory::HttpServerFactory;
use crate::http_server_factory::HttpServerHandle;
use crate::http_server_factory::Listener;
use crate::http_server_factory::NetworkStream;
use crate::layers::DEFAULT_BUFFER_SIZE;
use crate::plugin::Handler;
use crate::router::ApolloRouterError;
use crate::ResponseBody;

/// A basic http server using Axum.
/// Uses streaming as primary method of response.
Expand Down Expand Up @@ -658,25 +678,33 @@ impl<B> MakeSpan<B> for PropagatingMakeSpan {

#[cfg(test)]
mod tests {
use super::*;
use crate::configuration::Cors;
use crate::http_ext::Request;
use std::net::SocketAddr;
use std::str::FromStr;

use async_compression::tokio::write::GzipEncoder;
use http::header::{self, ACCEPT_ENCODING, CONTENT_TYPE};
use http::header::ACCEPT_ENCODING;
use http::header::CONTENT_TYPE;
use http::header::{self};
use mockall::mock;
use reqwest::header::{
ACCEPT, ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_METHODS,
ACCESS_CONTROL_ALLOW_ORIGIN, ACCESS_CONTROL_REQUEST_HEADERS, ACCESS_CONTROL_REQUEST_METHOD,
ORIGIN,
};
use reqwest::header::ACCEPT;
use reqwest::header::ACCESS_CONTROL_ALLOW_HEADERS;
use reqwest::header::ACCESS_CONTROL_ALLOW_METHODS;
use reqwest::header::ACCESS_CONTROL_ALLOW_ORIGIN;
use reqwest::header::ACCESS_CONTROL_REQUEST_HEADERS;
use reqwest::header::ACCESS_CONTROL_REQUEST_METHOD;
use reqwest::header::ORIGIN;
use reqwest::redirect::Policy;
use reqwest::{Client, Method, StatusCode};
use reqwest::Client;
use reqwest::Method;
use reqwest::StatusCode;
use serde_json::json;
use std::net::SocketAddr;
use std::str::FromStr;
use test_log::test;
use tower::service_fn;

use super::*;
use crate::configuration::Cors;
use crate::http_ext::Request;

macro_rules! assert_header {
($response:expr, $header:expr, $expected:expr $(, $msg:expr)?) => {
assert_eq!(
Expand Down Expand Up @@ -1605,7 +1633,9 @@ mod tests {

#[cfg(unix)]
async fn send_to_unix_socket(addr: &ListenAddr, method: Method, body: &str) -> Vec<u8> {
use tokio::io::{AsyncBufReadExt, BufReader, Interest};
use tokio::io::AsyncBufReadExt;
use tokio::io::BufReader;
use tokio::io::Interest;
use tokio::net::UnixStream;

let content = match method {
Expand Down
23 changes: 14 additions & 9 deletions apollo-router/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use crate::error::CacheResolverError;
use crate::traits::CacheResolver;
use derivative::Derivative;
use futures::lock::Mutex;
use lru::LruCache;
use std::cmp::Eq;
use std::collections::HashMap;
use std::fmt;
use std::hash::Hash;
use std::sync::Arc;
use tokio::sync::broadcast::{self, Sender};

use derivative::Derivative;
use futures::lock::Mutex;
use lru::LruCache;
use tokio::sync::broadcast::Sender;
use tokio::sync::broadcast::{self};
use tokio::sync::oneshot;

use crate::error::CacheResolverError;
use crate::traits::CacheResolver;

/// A caching map optimised for slow value resolution.
///
/// The CachingMap hold values in an LruCache. Values are loaded into the cache on a cache miss and
Expand Down Expand Up @@ -147,13 +150,15 @@ where

#[cfg(test)]
mod tests {
use super::*;
use crate::error::CacheResolverError;
use async_trait::async_trait;
use futures::stream::{FuturesUnordered, StreamExt};
use futures::stream::FuturesUnordered;
use futures::stream::StreamExt;
use mockall::mock;
use test_log::test;

use super::*;
use crate::error::CacheResolverError;

struct HasACache {
cm: CachingMap<usize, usize>,
}
Expand Down
42 changes: 27 additions & 15 deletions apollo-router/src/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@
// This entire file is license key functionality
mod yaml;

use crate::plugin::plugins;
use std::cmp::Ordering;
use std::fmt;
use std::net::SocketAddr;
use std::str::FromStr;

use derivative::Derivative;
use displaydoc::Display;
use envmnt::{ExpandOptions, ExpansionType};
use envmnt::ExpandOptions;
use envmnt::ExpansionType;
use itertools::Itertools;
use jsonschema::{Draft, JSONSchema};
use schemars::gen::{SchemaGenerator, SchemaSettings};
use schemars::schema::{ObjectValidation, RootSchema, Schema, SchemaObject};
use jsonschema::Draft;
use jsonschema::JSONSchema;
use schemars::gen::SchemaGenerator;
use schemars::gen::SchemaSettings;
use schemars::schema::ObjectValidation;
use schemars::schema::RootSchema;
use schemars::schema::Schema;
use schemars::schema::SchemaObject;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use serde::Serialize;
use serde_json::Map;
use serde_json::Value;
use std::cmp::Ordering;
use std::fmt;
use std::net::SocketAddr;
use std::str::FromStr;
use thiserror::Error;
use tower_http::cors::{self, CorsLayer};
use tower_http::cors::CorsLayer;
use tower_http::cors::{self};

use crate::plugin::plugins;

/// Configuration error.
#[derive(Debug, Error, Display)]
Expand Down Expand Up @@ -763,19 +773,21 @@ pub(crate) fn validate_configuration(raw_yaml: &str) -> Result<Configuration, Co

#[cfg(test)]
mod tests {
use super::*;
use crate::error::SchemaError;
use std::collections::HashMap;
use std::fs;

use http::Uri;
#[cfg(unix)]
use insta::assert_json_snapshot;
use regex::Regex;
#[cfg(unix)]
use schemars::gen::SchemaSettings;
use std::collections::HashMap;
use std::fs;
use walkdir::DirEntry;
use walkdir::WalkDir;

use super::*;
use crate::error::SchemaError;

#[cfg(unix)]
#[test]
fn schema_generation() {
Expand Down
15 changes: 10 additions & 5 deletions apollo-router/src/configuration/yaml.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use crate::configuration::ConfigurationError;
use std::collections::HashMap;

use derivative::Derivative;
use indexmap::IndexMap;
use jsonschema::paths::{JSONPointer, PathChunk};
use std::collections::HashMap;
use yaml_rust::parser::{MarkedEventReceiver, Parser};
use jsonschema::paths::JSONPointer;
use jsonschema::paths::PathChunk;
use yaml_rust::parser::MarkedEventReceiver;
use yaml_rust::parser::Parser;
use yaml_rust::scanner::Marker;
use yaml_rust::Event;

use crate::configuration::ConfigurationError;

#[derive(Derivative, Clone, Debug, Eq)]
#[derivative(Hash, PartialEq)]
pub(crate) struct Label {
Expand Down Expand Up @@ -190,9 +194,10 @@ impl MarkedEventReceiver for MarkedYaml {

#[cfg(test)]
mod test {
use crate::configuration::yaml::parse;
use insta::assert_snapshot;

use crate::configuration::yaml::parse;

#[test]
fn test() {
// DON'T reformat this. It'll change the test results
Expand Down
9 changes: 6 additions & 3 deletions apollo-router/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
//! Router plugins accept a mutable [`Context`] when invoked and this contains a DashMap which
//! allows additional data to be passed back and forth along the request invocation pipeline.
use crate::json_ext::Value;
use dashmap::mapref::multiple::{RefMulti, RefMutMulti};
use std::sync::Arc;

use dashmap::mapref::multiple::RefMulti;
use dashmap::mapref::multiple::RefMutMulti;
use dashmap::DashMap;
use serde::Serialize;
use std::sync::Arc;
use tower::BoxError;

use crate::json_ext::Value;

/// Holds [`Context`] entries.
pub(crate) type Entries = Arc<DashMap<String, Value>>;

Expand Down
Loading

0 comments on commit 2d58671

Please sign in to comment.