Skip to content

Commit

Permalink
refactor: remove overrides from .prettierrc (#1841)
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath authored May 2, 2024
1 parent 97dc20f commit 1ac42a4
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 52 deletions.
24 changes: 0 additions & 24 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,6 @@
"tabWidth": 2,
"bracketSpacing": false,
"overrides": [
{
"files": [
"add-field-many-list.graphql",
"add-field-many-list.md",
"add-field-many.graphql",
"add-field-many.md",
"inline-many.graphql",
"inline-many.md",
"inline-many-list.graphql",
"inline-many-list.md",
"test-grpc.graphql",
"test-add-link-to-empty-config.graphql",
"test-add-link-to-empty-config.md",
"test-grpc.md",
"test-expr-success.graphql",
"test-expr-success.md",
"omit-many.graphql",
"omit-many.md",
"auth.md"
],
"options": {
"printWidth": 210
}
},
{
"files": ["devcontainer.json"],
"options": {
Expand Down
4 changes: 2 additions & 2 deletions tailcall-prettier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ lazy_static::lazy_static! {
static ref PRETTIER: Arc<Prettier> = Arc::new(Prettier::new());
}

pub async fn format<T: AsRef<str>>(source: T, parser: Parser) -> Result<String> {
pub async fn format<T: AsRef<str>>(source: T, parser: &Parser) -> Result<String> {
PRETTIER.format(source.as_ref().to_string(), parser).await
}

Expand All @@ -19,7 +19,7 @@ mod tests {

#[tokio::test]
async fn test_js() -> anyhow::Result<()> {
let prettier = format("const x={a:3};", Parser::Js).await?;
let prettier = format("const x={a:3};", &Parser::Js).await?;
assert_eq!("const x = {a: 3}\n", prettier);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion tailcall-prettier/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Result};

#[derive(strum_macros::Display)]
#[derive(strum_macros::Display, Clone)]
pub enum Parser {
Gql,
Yml,
Expand Down
8 changes: 6 additions & 2 deletions tailcall-prettier/src/prettier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ impl Prettier {
Self { runtime }
}

pub async fn format(&self, source: String, parser: Parser) -> Result<String> {
pub async fn format<'a>(&'a self, source: String, parser: &'a Parser) -> Result<String> {
let parser = parser.clone();
self.runtime
.spawn_blocking(move || {
let mut command = command();
Expand All @@ -38,7 +39,10 @@ impl Prettier {
if output.status.success() {
Ok(String::from_utf8(output.stdout)?)
} else {
Err(anyhow!("Prettier formatting failed"))
Err(anyhow!(
"Prettier formatting failed: {}",
String::from_utf8(output.stderr).unwrap()
))
}
})
.await?
Expand Down
27 changes: 12 additions & 15 deletions tests/core/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,30 +122,27 @@ async fn check_server_config(spec: ExecutionSpec) -> Vec<Config> {
// tests that were explicitly written with it in mind
if spec.check_identity {
if matches!(source, Source::GraphQL) {
let identity = config.to_sdl();
let actual = config.to_sdl();

// \r is added automatically in windows, it's safe to replace it with \n
let content = content.replace("\r\n", "\n");

let path_str = spec.path.display().to_string();
let context = format!("path: {}", path_str);

let identity = tailcall_prettier::format(
identity,
tailcall_prettier::Parser::detect(path_str.as_str()).unwrap(),
)
.await
.unwrap();
let actual = tailcall_prettier::format(actual, &tailcall_prettier::Parser::Gql)
.await
.context(context.clone())
.unwrap();

let content = tailcall_prettier::format(
content,
tailcall_prettier::Parser::detect(path_str.as_str()).unwrap(),
)
.await
.unwrap();
let expected = tailcall_prettier::format(content, &tailcall_prettier::Parser::Gql)
.await
.context(context)
.unwrap();

pretty_assertions::assert_eq!(
identity,
content,
actual,
expected,
"Identity check failed for {:#?}",
spec.path,
);
Expand Down
5 changes: 4 additions & 1 deletion tests/execution/add-field-many-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ type Query {
u: U @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/us/1")
}

type U @addField(name: "b", path: ["a", "b"]) @addField(name: "c", path: ["a", "c"]) @addField(name: "d", path: ["a", "d"]) {
type U
@addField(name: "b", path: ["a", "b"])
@addField(name: "c", path: ["a", "c"])
@addField(name: "d", path: ["a", "d"]) {
a: A
e: String
}
Expand Down
5 changes: 4 additions & 1 deletion tests/execution/add-field-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ schema @server @upstream {
query: Query
}

type Foo @addField(name: "a", path: ["x", "a"]) @addField(name: "b", path: ["x", "b"]) @addField(name: "c", path: ["x", "c"]) {
type Foo
@addField(name: "a", path: ["x", "a"])
@addField(name: "b", path: ["x", "b"])
@addField(name: "c", path: ["x", "c"]) {
name: String
x: X
}
Expand Down
6 changes: 5 additions & 1 deletion tests/execution/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ check_identity: true
# auth

```graphql @server
schema @server @upstream @link(id: "htpasswd", src: ".htpasswd", type: Htpasswd) @link(id: "jwks", src: "jwks.json", type: Jwks) {
schema
@server
@upstream
@link(id: "htpasswd", src: ".htpasswd", type: Htpasswd)
@link(id: "jwks", src: "jwks.json", type: Jwks) {
query: Query
}

Expand Down
5 changes: 4 additions & 1 deletion tests/execution/inline-many-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ type Query {
u: U @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/us/1")
}

type U @addField(name: "b", path: ["a", "b"]) @addField(name: "c", path: ["a", "c"]) @addField(name: "d", path: ["a", "d"]) {
type U
@addField(name: "b", path: ["a", "b"])
@addField(name: "c", path: ["a", "c"])
@addField(name: "d", path: ["a", "d"]) {
a: A @modify(omit: true)
e: String
}
Expand Down
5 changes: 4 additions & 1 deletion tests/execution/inline-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ type Query {
user: User @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/users/1")
}

type User @addField(name: "city", path: ["address", "city"]) @addField(name: "street", path: ["address", "street"]) @addField(name: "zipcode", path: ["address", "zipcode"]) {
type User
@addField(name: "city", path: ["address", "city"])
@addField(name: "street", path: ["address", "street"])
@addField(name: "zipcode", path: ["address", "zipcode"]) {
address: Address @modify(omit: true)
name: String
}
Expand Down
4 changes: 3 additions & 1 deletion tests/execution/omit-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ type Query {
user: User @http(baseURL: "http://jsonplaceholder.typicode.com", path: "/users/1")
}

type User @addField(name: "zipcode", path: ["address", "zipcode"]) @addField(name: "complements", path: ["address", "complements"]) {
type User
@addField(name: "zipcode", path: ["address", "zipcode"])
@addField(name: "complements", path: ["address", "complements"]) {
address: Address @omit
name: String
}
Expand Down
8 changes: 6 additions & 2 deletions tests/execution/test-grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ message NewsList {
```

```graphql @server
schema @server(port: 8000) @upstream(baseURL: "http://localhost:50051", batch: {delay: 10, headers: [], maxSize: 1000}) @link(id: "news", src: "news.proto", type: Protobuf) {
schema
@server(port: 8000)
@upstream(baseURL: "http://localhost:50051", batch: {delay: 10, headers: [], maxSize: 1000})
@link(id: "news", src: "news.proto", type: Protobuf) {
query: Query
}

Expand All @@ -66,6 +69,7 @@ type NewsData {
type Query {
news: NewsData! @grpc(method: "news.NewsService.GetAllNews")
newsById(news: NewsInput!): News! @grpc(body: "{{.args.news}}", method: "news.NewsService.GetNews")
newsByIdBatch(news: NewsInput!): News! @grpc(body: "{{.args.news}}", batchKey: ["news", "id"], method: "news.NewsService.GetMultipleNews")
newsByIdBatch(news: NewsInput!): News!
@grpc(body: "{{.args.news}}", batchKey: ["news", "id"], method: "news.NewsService.GetMultipleNews")
}
```

1 comment on commit 1ac42a4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 7.41ms 3.62ms 146.61ms 75.51%
Req/Sec 3.42k 120.44 3.74k 86.42%

408666 requests in 30.00s, 2.05GB read

Requests/sec: 13619.94

Transfer/sec: 69.91MB

Please sign in to comment.