Skip to content

Commit 1ce2171

Browse files
committed
refactor: use ArcStr for storing strings in Schema
1 parent 86b5319 commit 1ce2171

File tree

99 files changed

+1095
-1077
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1095
-1077
lines changed

benches/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ impl Query {
8989
}
9090
}
9191

92-
pub fn new_schema() -> RootNode<'static, Query, EmptyMutation<Context>, EmptySubscription<Context>>
93-
{
92+
pub fn new_schema() -> RootNode<Query, EmptyMutation<Context>, EmptySubscription<Context>> {
9493
RootNode::new(Query, EmptyMutation::new(), EmptySubscription::new())
9594
}
9695

book/src/advanced/introspection.md

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ impl Query {
5858
}
5959

6060
type Schema = juniper::RootNode<
61-
'static,
6261
Query,
6362
EmptyMutation<Context>,
6463
EmptySubscription<Context>

book/src/advanced/subscriptions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ where [`Connection`][Connection] is a `Stream` of values returned by the operati
124124
# Box::pin(stream)
125125
# }
126126
# }
127-
type Schema = RootNode<'static, Query, EmptyMutation<Database>, Subscription>;
127+
type Schema = RootNode<Query, EmptyMutation<Database>, Subscription>;
128128

129129
fn schema() -> Schema {
130130
Schema::new(Query, EmptyMutation::new(), Subscription)

book/src/quickstart.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl Mutation {
127127

128128
// A root schema consists of a query, a mutation, and a subscription.
129129
// Request queries can be executed against a RootNode.
130-
type Schema = juniper::RootNode<'static, Query, Mutation, EmptySubscription<Context>>;
130+
type Schema = juniper::RootNode<Query, Mutation, EmptySubscription<Context>>;
131131
#
132132
# fn main() {
133133
# let _ = Schema::new(Query, Mutation, EmptySubscription::new());
@@ -175,7 +175,7 @@ impl Query {
175175

176176
// A root schema consists of a query, a mutation, and a subscription.
177177
// Request queries can be executed against a RootNode.
178-
type Schema = juniper::RootNode<'static, Query, EmptyMutation<Ctx>, EmptySubscription<Ctx>>;
178+
type Schema = juniper::RootNode<Query, EmptyMutation<Ctx>, EmptySubscription<Ctx>>;
179179

180180
fn main() {
181181
// Create a context object.

juniper/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ uuid = ["dep:uuid"]
4848

4949
[dependencies]
5050
anyhow = { version = "1.0.47", optional = true }
51+
arcstr = "1"
5152
async-trait = "0.1.39"
5253
auto_enums = "0.8"
5354
bigdecimal = { version = "0.4", optional = true }
@@ -63,7 +64,6 @@ rust_decimal = { version = "1.20", default-features = false, optional = true }
6364
ryu = { version = "1.0", optional = true }
6465
serde = { version = "1.0.122", features = ["derive"] }
6566
serde_json = { version = "1.0.18", features = ["std"], default-features = false, optional = true }
66-
smartstring = "1.0"
6767
static_assertions = "1.1"
6868
time = { version = "0.3", features = ["formatting", "macros", "parsing"], optional = true }
6969
url = { version = "2.0", optional = true }

juniper/src/ast.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@ use crate::{
66
executor::Variables,
77
parser::Spanning,
88
value::{DefaultScalarValue, ScalarValue},
9+
ArcStr,
910
};
1011

1112
/// A type literal in the syntax tree
1213
///
1314
/// This enum carries no semantic information and might refer to types that do
1415
/// not exist.
1516
#[derive(Clone, Eq, PartialEq, Debug)]
16-
pub enum Type<'a> {
17+
pub enum Type<N = ArcStr> {
1718
/// A nullable named type, e.g. `String`
18-
Named(Cow<'a, str>),
19+
Named(N),
1920
/// A nullable list type, e.g. `[String]`
2021
///
2122
/// The list itself is what's nullable, the containing type might be non-null.
22-
List(Box<Type<'a>>, Option<usize>),
23+
List(Box<Type<N>>, Option<usize>),
2324
/// A non-null named type, e.g. `String!`
24-
NonNullNamed(Cow<'a, str>),
25+
NonNullNamed(N),
2526
/// A non-null list type, e.g. `[String]!`.
2627
///
2728
/// The list itself is what's non-null, the containing type might be null.
28-
NonNullList(Box<Type<'a>>, Option<usize>),
29+
NonNullList(Box<Type<N>>, Option<usize>),
2930
}
3031

3132
/// A JSON-like value that can be passed into the query execution, either
@@ -47,7 +48,7 @@ pub enum InputValue<S = DefaultScalarValue> {
4748

4849
#[derive(Clone, PartialEq, Debug)]
4950
pub struct VariableDefinition<'a, S> {
50-
pub var_type: Spanning<Type<'a>>,
51+
pub var_type: Spanning<Type<&'a str>>,
5152
pub default_value: Option<Spanning<InputValue<S>>>,
5253
pub directives: Option<Vec<Spanning<Directive<'a, S>>>>,
5354
}
@@ -194,13 +195,13 @@ pub trait ToInputValue<S = DefaultScalarValue>: Sized {
194195
fn to_input_value(&self) -> InputValue<S>;
195196
}
196197

197-
impl<'a> Type<'a> {
198+
impl<N: AsRef<str>> Type<N> {
198199
/// Get the name of a named type.
199200
///
200201
/// Only applies to named types; lists will return `None`.
201202
pub fn name(&self) -> Option<&str> {
202203
match *self {
203-
Type::Named(ref n) | Type::NonNullNamed(ref n) => Some(n),
204+
Type::Named(ref n) | Type::NonNullNamed(ref n) => Some(n.as_ref()),
204205
_ => None,
205206
}
206207
}
@@ -210,7 +211,7 @@ impl<'a> Type<'a> {
210211
/// All type literals contain exactly one named type.
211212
pub fn innermost_name(&self) -> &str {
212213
match *self {
213-
Type::Named(ref n) | Type::NonNullNamed(ref n) => n,
214+
Type::Named(ref n) | Type::NonNullNamed(ref n) => n.as_ref(),
214215
Type::List(ref l, _) | Type::NonNullList(ref l, _) => l.innermost_name(),
215216
}
216217
}
@@ -221,7 +222,7 @@ impl<'a> Type<'a> {
221222
}
222223
}
223224

224-
impl<'a> fmt::Display for Type<'a> {
225+
impl<N: fmt::Display> fmt::Display for Type<N> {
225226
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
226227
match self {
227228
Self::Named(n) => write!(f, "{n}"),

0 commit comments

Comments
 (0)