Skip to content

Commit

Permalink
fix: use contract name + event name as comment
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstevens19 committed Aug 15, 2024
1 parent 582b4b7 commit 276d896
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 47 deletions.
2 changes: 1 addition & 1 deletion core/src/api/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub async fn start_graphql_server(
)
})
.collect();

let connection_string = connection_string()?;
let port = settings.port;
let graphql_endpoint = format!("http://localhost:{}/graphql", &port);
Expand Down
8 changes: 4 additions & 4 deletions core/src/database/postgres/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tracing::{error, info};

use crate::{
abi::{ABIInput, ABIItem, EventInfo, GenerateAbiPropertiesType, ParamTypeError, ReadAbiError},
helpers::{camel_to_snake, to_pascal_case},
helpers::camel_to_snake,
indexer::Indexer,
manifest::contract::Contract,
types::code::Code,
Expand Down Expand Up @@ -41,6 +41,7 @@ pub fn generate_column_names_only_with_base_properties(inputs: &[ABIInput]) -> V

fn generate_event_table_sql_with_comments(
abi_inputs: &[EventInfo],
contract_name: &str,
schema_name: &str,
apply_full_name_comment_for_events: Vec<String>,
) -> String {
Expand Down Expand Up @@ -77,9 +78,7 @@ fn generate_event_table_sql_with_comments(
// smart comments needed to avoid clashing of order by graphql names
let table_comment = format!(
"COMMENT ON TABLE {} IS E'@name {}{}';",
table_name,
to_pascal_case(schema_name).as_str(),
event_info.name
table_name, contract_name, event_info.name
);

format!("{}\n{}", create_table_sql, table_comment)
Expand Down Expand Up @@ -178,6 +177,7 @@ pub fn generate_tables_for_indexer_sql(

sql.push_str(&generate_event_table_sql_with_comments(
&event_names,
&contract.name,
&schema_name,
event_matching_name_on_other,
));
Expand Down
38 changes: 0 additions & 38 deletions core/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,6 @@ pub fn replace_env_variable_to_raw_name(rpc: &str) -> String {
}
}

pub fn to_pascal_case(s: &str) -> String {
let mut result = String::new();
let mut capitalize_next = true;

for c in s.chars() {
if c == '_' {
capitalize_next = true;
} else if capitalize_next {
result.push(c.to_ascii_uppercase());
capitalize_next = false;
} else {
result.push(c.to_ascii_lowercase());
}
}

result
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -149,24 +131,4 @@ mod tests {
assert_eq!(camel_to_snake_advanced("ERC20", false), "erc_20");
assert_eq!(camel_to_snake_advanced("ERC20", true), "erc20");
}

#[test]
fn test_pascal_case() {
let test_cases = vec![
("hello_world", "HelloWorld"),
("hello", "Hello"),
("hello__world__test", "HelloWorldTest"),
("_hello_world", "HelloWorld"),
("hello_world_", "HelloWorld"),
("", ""),
("HELLO_WORLD", "HelloWorld"),
("hElLo_WoRlD", "HelloWorld"),
("hello_world_123", "HelloWorld123"),
("indexer_cdh", "IndexerCdh"),
];

for (input, expected) in test_cases {
assert_eq!(to_pascal_case(input), expected, "Failed for input: {}", input);
}
}
}
8 changes: 4 additions & 4 deletions documentation/docs/pages/docs/accessing-data/graphql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ in the list results alongside the singular item query.
Important to read if you have 2 events with matching names across contracts.
:::

If you have 2 events which have exactly the same name as another contract this is a conflict of naming for graphql and it will render
full naming, for example `Transfer` would turn into `{indexer_name}{contract_name}Transfer`
If you have 2 events which have exactly the same name as another contract this is a conflict of naming for graphql so rindexer will render
it as `{contract_name}{event_name}` in pascal case, for example `Transfer` would turn into `{contract_name}Transfer`

So its is super clear lets say i had a yaml like this:

Expand Down Expand Up @@ -222,8 +222,8 @@ contracts:
My query names for `allTransfers` would be:

- `AllRocketPoolETHIndexerRocketPoolETHTransfers`
- `AllRocketPoolETHIndexerRocketPoolETHForkTransfers`
- `AllRocketPoolETHTransfers`
- `AllRocketPoolETHForkTransfers`

### Ordering

Expand Down

0 comments on commit 276d896

Please sign in to comment.