Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ factory_indexing_codegen_typings:
RUSTFLAGS='-C target-cpu=native' cargo run --release --features jemalloc -- codegen --path $(CURDIR)/../examples/rindexer_factory_indexing typings
factory_indexing_codegen_indexer:
RUSTFLAGS='-C target-cpu=native' cargo run --release --features jemalloc -- codegen --path $(CURDIR)/../examples/rindexer_factory_indexing indexer
factory_indexing_codegen_graphql:
RUSTFLAGS='-C target-cpu=native' cargo run --release --features jemalloc -- codegen --path $(CURDIR)/../examples/rindexer_factory_indexing graphql

################################################################################
# LOCAL NONE CHECKED IN PROJECT COMMANDS
Expand Down Expand Up @@ -70,4 +72,4 @@ start_factory_indexing:
hyperwarp_codegen_typings:
RUSTFLAGS='-C target-cpu=native' cargo run --release --features jemalloc -- codegen --path $(CURDIR)/../examples/hyperevm typings
hyperwarp_codegen_indexer:
RUSTFLAGS='-C target-cpu=native' cargo run --release --features jemalloc -- codegen --path $(CURDIR)/../examples/hyperevm indexer
RUSTFLAGS='-C target-cpu=native' cargo run --release --features jemalloc -- codegen --path $(CURDIR)/../examples/hyperevm indexer
15 changes: 8 additions & 7 deletions cli/src/commands/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
use std::path::PathBuf;

use crate::{
cli_interface::CodegenSubcommands,
console::{print_error_message, print_success_message},
rindexer_yaml::validate_rindexer_yaml_exist,
};
use rindexer::{
format_all_files_for_project, generate_graphql_queries,
generator::build::{generate_rindexer_handlers, generate_rindexer_typings},
manifest::{
core::ProjectType,
graphql::default_graphql_port,
yaml::{read_manifest, YAML_CONFIG_NAME},
},
};

use crate::{
cli_interface::CodegenSubcommands,
console::{print_error_message, print_success_message},
rindexer_yaml::validate_rindexer_yaml_exist,
};

pub async fn handle_codegen_command(
project_path: PathBuf,
subcommand: &CodegenSubcommands,
) -> Result<(), Box<dyn std::error::Error>> {
if let CodegenSubcommands::GraphQL { endpoint } = subcommand {
let url = endpoint.as_deref().unwrap_or("http://localhost:3001");
let default_url = format!("http://localhost:{}/graphql", default_graphql_port());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

/graphql was missing

let url = endpoint.as_deref().unwrap_or(&default_url);
generate_graphql_queries(url, &project_path).await.map_err(|e| {
print_error_message(&format!("Failed to generate graphql queries: {e}"));
e
Expand Down
15 changes: 6 additions & 9 deletions core/src/api/generate_schema.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
use std::path::Path;

use crate::api::generate_operations::{generate_operations, GenerateOperationsError};
use reqwest::Client;
use serde_json::Value;

use crate::api::generate_operations::{generate_operations, GenerateOperationsError};

#[derive(thiserror::Error, Debug)]
pub enum GenerateGraphqlQueriesError {
#[error("Network request failed: {0}")]
Network(#[from] reqwest::Error),

#[error("Failed to parse JSON: {0}")]
JsonParse(#[from] serde_json::Error),

#[error("File system error: {0}")]
Io(#[from] std::io::Error),

#[error("No data in response")]
NoData,

#[error("Invalid response. Make sure that {0} can receive GraphQL introspection query.")]
InvalidData(String),

#[error("Failed to generate operations: {0}")]
GenerateOperationsError(#[from] GenerateOperationsError),
}
Expand Down Expand Up @@ -89,7 +85,8 @@ pub async fn generate_graphql_queries(
.send()
.await?
.json::<Value>()
.await?;
.await
.map_err(|_| GenerateGraphqlQueriesError::InvalidData(endpoint.to_string()))?;

let schema = res["data"]["__schema"].clone();
if schema.is_null() {
Expand Down
2 changes: 1 addition & 1 deletion core/src/generator/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ serde = {{ version = "1.0", features = ["derive"] }}
let mut port: Option<u16> = None;

let args = args.iter();
if args.len() == 0 {
if args.len() == 1 {
enable_graphql = true;
enable_indexer = true;
}
Expand Down
10 changes: 7 additions & 3 deletions core/src/manifest/graphql.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use serde::{Deserialize, Serialize};

fn default_port() -> u16 {
pub fn default_graphql_port() -> u16 {
3001
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GraphQLSettings {
#[serde(default = "default_port")]
#[serde(default = "default_graphql_port")]
pub port: u16,

#[serde(default)]
Expand All @@ -18,7 +18,11 @@ pub struct GraphQLSettings {

impl Default for GraphQLSettings {
fn default() -> Self {
Self { port: 3001, disable_advanced_filters: false, filter_only_on_indexed_columns: false }
Self {
port: default_graphql_port(),
disable_advanced_filters: false,
filter_only_on_indexed_columns: false,
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions documentation/docs/pages/docs/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

### Bug fixes
-------------------------------------------------
- fix: start indexer and graphql when a rust project is started without any commands
- fix: take the correct default graphql endpoint when generating graphql files

### Breaking changes
-------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/rindexer_factory_indexing/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/rindexer_factory_indexing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ async fn main() {
let mut port: Option<u16> = None;

let args = args.iter();
if args.len() == 0 {

if args.len() == 1 {
enable_graphql = true;
enable_indexer = true;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/rindexer_rust_playground/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn main() {
let mut port: Option<u16> = None;

let args = args.iter();
if args.len() == 0 {
if args.len() == 1 {
enable_graphql = true;
enable_indexer = true;
}
Expand Down
Loading