Skip to content

Commit

Permalink
Use graphql utils from toolshed (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus authored Jan 27, 2023
1 parent f890c63 commit 8378f17
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 278 deletions.
6 changes: 3 additions & 3 deletions agora/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ fraction = { version="0.6.3", features=["with-bigint"] }
serde = { version="1.0.115", features = ["derive"] }
serde_json = "1.0"
tree-buf = "0.10.0"
shellexpand = "2.0.0"
shellexpand = "3.0.0"
rayon = "1.4.0"
rand = "0.7.3"
rand = "0.8.5"
structopt = "0.3.14"
num-format = { version = "0.4.0", features = ["with-num-bigint"] }
graphql-parser = "0.3.0"
graphql-parser = "0.4.0"
anyhow = "1.0.33"
libflate = "1.1.0"
8 changes: 3 additions & 5 deletions lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# Include the consume_definition API and nameless operations fix
graphql-parser = { git = "https://github.com/graphql-rust/graphql-parser", rev = "8a759df" }
# graphql-parser = "0.3.0"
lazy_static = "1.4.0"
nom = "5.1.2"
num-bigint = "0.2.6"
num-traits = "0.2.12"
firestorm = "0.5"
fraction = { version = "0.6.3", features = ["with-bigint"] }
serde = { version = "1.0.116", features = ["derive"] }
serde_json = "1.0"
lazy_static = "1.4.0"
single = "1.0.0"
firestorm = "0.4"
toolshed = { git = "https://github.com/edgeandnode/toolshed", tag = "v0.1.1" }
3 changes: 1 addition & 2 deletions lang/src/coercion.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use graphql_parser::query as q;

use fraction::BigFraction;
use q::Value::*;
use toolshed::graphql::graphql_parser::query as q;

/// This is like TryInto, but more liberal
pub trait Coerce<T> {
Expand Down
3 changes: 1 addition & 2 deletions lang/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::graphql_utils::QueryVariables;
use crate::prelude::*;
use crate::{Captures, CostError};
use graphql_parser::query as q;
use toolshed::graphql::{graphql_parser::query as q, QueryVariables};

pub struct Context<'a, T: q::Text<'a>> {
pub operations: Vec<q::OperationDefinition<'a, T>>,
Expand Down
2 changes: 1 addition & 1 deletion lang/src/expressions/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use crate::coercion::Coerce;
use crate::graphql_utils::StaticValue;
use std::marker::PhantomData;
use toolshed::graphql::StaticValue;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
struct Unowned<T>(PhantomData<*const T>);
Expand Down
222 changes: 0 additions & 222 deletions lang/src/graphql_utils.rs

This file was deleted.

5 changes: 2 additions & 3 deletions lang/src/language.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::coercion::Coerce;
use crate::expressions::expr_stack::*;
use crate::expressions::*;
use crate::graphql_utils::{IntoStaticValue, QueryVariables, StaticValue};
use crate::matching::{get_capture_names_field, match_query};
use crate::prelude::*;
use fraction::BigFraction;
use graphql_parser::query as q;
use std::collections::HashMap;
use toolshed::graphql::{graphql_parser::query as q, IntoStaticValue, QueryVariables, StaticValue};

#[derive(Debug, PartialEq)]
pub struct Document<'a> {
Expand Down Expand Up @@ -324,7 +323,7 @@ impl Captures {
#[cfg(test)]
pub(crate) mod test_helpers {
use super::*;
use crate::graphql_utils::IntoStaticValue;
use toolshed::graphql::IntoStaticValue;

impl From<()> for Captures {
fn from(_: ()) -> Captures {
Expand Down
9 changes: 3 additions & 6 deletions lang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,23 @@ extern crate lazy_static;
mod coercion;
mod context;
mod expressions;
mod graphql_utils;
mod language;
mod matching;
#[macro_use]
mod parse_errors;
mod parser;
mod repeat;

pub(crate) mod prelude;
use prelude::*;

use fraction::{BigFraction, GenericFraction, Sign};
use graphql_parser::query as q;
use language::*;
use num_bigint::BigUint;
use std::{error, fmt};
use toolshed::graphql::graphql_parser::query as q;
use toolshed::graphql::QueryVariables;

pub use context::Context;
// Hack for indexer selection
pub use graphql_utils::QueryVariables;

pub struct CostModel {
// Rust does not have a memory model, nor does it have a proper `uintptr_t` equivalent. So a
Expand Down Expand Up @@ -93,7 +90,7 @@ pub(crate) fn parse_vars(vars: &str) -> Result<QueryVariables, serde_json::Error

let vars = vars.trim();
if ["{}", "null", ""].contains(&vars) {
Ok(graphql_utils::QueryVariables::new())
Ok(QueryVariables::default())
} else {
serde_json::from_str(vars)
}
Expand Down
3 changes: 1 addition & 2 deletions lang/src/matching.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::graphql_utils::{IntoStaticValue, QueryVariables};
use crate::language::Captures;
use crate::prelude::*;
use graphql_parser::query as q;
use single::Single as _;
use std::borrow::Borrow;
use std::collections::BTreeMap;
use toolshed::graphql::{graphql_parser::query as q, IntoStaticValue, QueryVariables};

struct MatchingContext<'var, 'cap, 'frag, 'fragt: 'frag, TF: q::Text<'fragt>> {
fragments: &'frag [q::FragmentDefinition<'fragt, TF>],
Expand Down
5 changes: 2 additions & 3 deletions lang/src/parse_errors.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::prelude::*;
use crate::repeat::repeat;
use graphql_parser::query::ParseError as GraphQLParseError;
use nom::error::{ErrorKind, ParseError};
use nom::{Err as NomErr, IResult, InputLength};
use std::cmp::Ordering;
use std::fmt;
use std::ops::Deref;
use toolshed::graphql::graphql_parser::query::ParseError as GraphQLParseError;

/// If something failed, this notes what we were
/// trying to do when it failed.
Expand Down Expand Up @@ -385,7 +384,7 @@ impl<'a> AgoraParseError<&'a str> {
)?;
writeln!(f, "{}", pos.line)?;
// Write a caret indicating the position.
writeln!(f, "{}^", repeat(pos.column_number, " "))?;
writeln!(f, "{}^", " ".repeat(pos.column_number))?;
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion lang/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::parse_errors::{
use crate::prelude::*;
use crate::{expressions::*, language::*, parse_errors::*};
use fraction::BigFraction;
use graphql_parser::query as q;
use nom::{
branch::alt,
bytes::complete::{is_not, take_while1},
Expand All @@ -19,6 +18,7 @@ use nom::{
use num_bigint::BigUint;
use num_traits::Pow as _;
use single::Single as _;
use toolshed::graphql::graphql_parser::query as q;

// Change Nom default error type from (I, ErrorKind) to ErrorAggregator<I>
type IResult<I, O, E = ErrorAggregator<I>> = NomIResult<I, O, E>;
Expand Down
Loading

0 comments on commit 8378f17

Please sign in to comment.