Skip to content

Commit ae83c65

Browse files
committed
feat: use ArcStr for storing strings in Schema
BREAKING CHANGE: Schema types are not lifetime-generic anymore
1 parent 9c4ea32 commit ae83c65

File tree

100 files changed

+1112
-1091
lines changed

Some content is hidden

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

100 files changed

+1112
-1091
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/quickstart.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl Mutation {
140140

141141
// Root schema consists of a query, a mutation, and a subscription.
142142
// Request queries can be executed against a `RootNode`.
143-
type Schema = juniper::RootNode<'static, Query, Mutation, EmptySubscription<Context>>;
143+
type Schema = juniper::RootNode<Query, Mutation, EmptySubscription<Context>>;
144144
#
145145
# fn main() {
146146
# _ = Schema::new(Query, Mutation, EmptySubscription::new());
@@ -190,7 +190,7 @@ impl Query {
190190
}
191191
}
192192

193-
type Schema = juniper::RootNode<'static, Query, EmptyMutation<Ctx>, EmptySubscription<Ctx>>;
193+
type Schema = juniper::RootNode<Query, EmptyMutation<Ctx>, EmptySubscription<Ctx>>;
194194

195195
fn main() {
196196
// Create a context.

book/src/schema/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Mutation {
5252
}
5353
}
5454

55-
type Schema = RootNode<'static, Query, Mutation, EmptySubscription>;
55+
type Schema = RootNode<Query, Mutation, EmptySubscription>;
5656
#
5757
# fn main() {}
5858
```
@@ -138,7 +138,7 @@ impl Query {
138138
}
139139
}
140140

141-
type Schema = RootNode<'static, Query, EmptyMutation, EmptySubscription>;
141+
type Schema = RootNode<Query, EmptyMutation, EmptySubscription>;
142142

143143
fn main() {
144144
// Run the built-in introspection query.

book/src/schema/introspection.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Query {
4545
}
4646
}
4747

48-
type Schema = RootNode<'static, Query, EmptyMutation, EmptySubscription>;
48+
type Schema = RootNode<Query, EmptyMutation, EmptySubscription>;
4949

5050
fn main() {
5151
let schema = Schema::new(Query, EmptyMutation::new(), EmptySubscription::new())

book/src/schema/subscriptions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ While we can implement [`SubscriptionCoordinator`] ourselves, [Juniper] contains
113113
# }
114114
# }
115115
#
116-
type Schema = RootNode<'static, Query, EmptyMutation<Database>, Subscription>;
116+
type Schema = RootNode<Query, EmptyMutation<Database>, Subscription>;
117117

118118
fn schema() -> Schema {
119119
Schema::new(Query, EmptyMutation::new(), Subscription)

juniper/Cargo.toml

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

4343
[dependencies]
4444
anyhow = { version = "1.0.47", optional = true }
45+
arcstr = "1"
4546
async-trait = "0.1.39"
4647
auto_enums = "0.8"
4748
bigdecimal = { version = "0.4", optional = true }
@@ -57,7 +58,6 @@ rust_decimal = { version = "1.20", default-features = false, optional = true }
5758
ryu = { version = "1.0", optional = true }
5859
serde = { version = "1.0.122", features = ["derive"] }
5960
serde_json = { version = "1.0.18", features = ["std"], default-features = false, optional = true }
60-
smartstring = "1.0"
6161
static_assertions = "1.1"
6262
time = { version = "0.3", features = ["formatting", "macros", "parsing"], optional = true }
6363
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)