Skip to content

Commit

Permalink
fix(grpc): invalid type names for generated configurations from proto…
Browse files Browse the repository at this point in the history
… files (#1682)

Co-authored-by: Tushar Mathur <[email protected]>
  • Loading branch information
shashitnak and tusharmath authored Apr 16, 2024
1 parent c587c4a commit b7c48a4
Show file tree
Hide file tree
Showing 12 changed files with 724 additions and 570 deletions.
488 changes: 251 additions & 237 deletions Cargo.lock

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion src/config/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{BTreeMap, BTreeSet};
use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::fmt::{self, Display};
use std::num::NonZeroU64;

Expand Down Expand Up @@ -113,6 +113,45 @@ impl Config {
pub fn contains(&self, name: &str) -> bool {
self.types.contains_key(name) || self.unions.contains_key(name)
}

/// Gets all the type names used in the schema.
pub fn get_all_used_type_names(&self) -> HashSet<String> {
let mut set = HashSet::new();
let mut stack = Vec::new();
if let Some(query) = &self.schema.query {
stack.push(query.clone());
}
if let Some(mutation) = &self.schema.mutation {
stack.push(mutation.clone());
}
while let Some(type_name) = stack.pop() {
if let Some(typ) = self.types.get(&type_name) {
set.insert(type_name);
for field in typ.fields.values() {
stack.extend(field.args.values().map(|arg| arg.type_of.clone()));
stack.push(field.type_of.clone());
}
}
}

set
}

pub fn get_all_unused_types(&self) -> HashSet<String> {
let used_types = self.get_all_used_type_names();
let all_types: HashSet<String> = self.types.keys().cloned().collect();
all_types.difference(&used_types).cloned().collect()
}

/// Removes all types that are not used in the schema.
pub fn remove_unused_types(mut self) -> Self {
let unused_types = self.get_all_unused_types();
for unused_type in unused_types {
self.types.remove(&unused_type);
}

self
}
}

impl MergeRight for Config {
Expand Down
Loading

1 comment on commit b7c48a4

@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.56ms 3.54ms 97.78ms 72.48%
Req/Sec 3.35k 263.83 4.20k 86.67%

400572 requests in 30.01s, 2.01GB read

Requests/sec: 13346.49

Transfer/sec: 68.50MB

Please sign in to comment.