Skip to content

Commit

Permalink
need to integrate with rocket for gql queries
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Jan 28, 2024
1 parent e3f927f commit 44bcfa0
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 19 deletions.
60 changes: 48 additions & 12 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ edition = "2018"

[dependencies]
anyhow = "1.0.79"
bytes = "1.5.0"
cfonts = "1.1.0"
chrono = "0.4.31"
clap = { version = "4.4.16", features = ["derive"] }
crossterm = "0.27.0"
ethers = "2.0.11"
futures = "0.3.30"
hyper = "1.1.0"
juniper = "0.15.12"
rand = { version = "0.7.3", default-features = false, features = ["std"] }
rand = { version = "0.8.5", default-features = false, features = ["std"] }
ratatui = "0.25.0"
serde = "1.0.194"
simplelog = "0.12.1"
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::error::Error;
use std::io::{self};
use std::sync::{mpsc, Arc};
use std::thread;
Expand Down
4 changes: 2 additions & 2 deletions src/models/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ impl<S> GraphQLScalar for I128
where
S: ScalarValue,
{
// Convert I128 to juniper::Value
// Convert I128 to Value
fn resolve(&self) -> Value {
Value::scalar(self.0.to_string())
}

// Convert juniper::InputValue to MyI128
// Convert juniper::InputValue to I128
fn from_input_value(v: &InputValue) -> Option<I128> {
v.as_string_value()
.and_then(|s| s.parse::<i128>().ok())
Expand Down
42 changes: 39 additions & 3 deletions src/models/states.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
use std::collections::HashMap;

use ethers::types::Address;
use juniper::{graphql_object, Context};

use crate::network::ethers::types::AddressInfo;

use super::position::Position;

pub enum InputMode {
Normal,
Editing,
}

pub struct Query {
pub query: String,
pub error_message: Option<String>,
#[derive(Clone, Default)]
pub struct Database {
pub positions: HashMap<String, Position>,
}

impl Context for Database {}

impl Database {
pub fn default() -> Database {
let mut positions = HashMap::<String, Position>::new();

Database { positions }
}

pub fn get_position(&self, address: &str) -> Option<&Position> {
self.positions.get(address)
}
}

#[derive(Clone, Copy, Debug)]
pub struct Query;

#[graphql_object(context = Database)]
impl Query {
fn position(
#[graphql(context)] database: &Database,
#[graphql(description = "Address of a position")] address: String,
) -> Option<&Position> {
database.get_position(&address)
}
}

pub struct AppSearchState {
Expand Down
1 change: 1 addition & 0 deletions src/network/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod ethers;
pub mod network;
pub mod server;
3 changes: 3 additions & 0 deletions src/network/server.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub async fn queryGQL(url: String, query_type: String) -> Result<(), Box<dyn Error + Send + Sync>> {
unimplemented!()
}

0 comments on commit 44bcfa0

Please sign in to comment.