Skip to content

Commit 8e10420

Browse files
committed
Drop i64 support, add i32 support
This is a breaking change, but having i64 support is both against the specification and a bad idea when interfacing with e.g. JavaScript or transmitting it via JSON
1 parent cecf507 commit 8e10420

23 files changed

+140
-140
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ using the macros and not deriving `GraphQLType` directly.
203203

204204
// Each entity has its own context
205205
struct TopContext {
206-
entities: HashMap<i64, EntityContext>,
206+
entities: HashMap<i32, EntityContext>,
207207
db: DatabaseConnection,
208208
}
209209

@@ -219,7 +219,7 @@ using the macros and not deriving `GraphQLType` directly.
219219
// to switch out the context for the returned value. You can wrap the
220220
// tuple in Option<>, FieldResult<>, FieldResult<Option<>>, or just return
221221
// the tuple without wrapping it.
222-
field entity(&executor, key: i64) -> Option<(&EntityContext, Entity)> {
222+
field entity(&executor, key: i32) -> Option<(&EntityContext, Entity)> {
223223
executor.context().entities.get(&key)
224224
.map(|ctx| (ctx, executor.context().db.get_entity(key)))
225225
}
@@ -247,7 +247,7 @@ using the macros and not deriving `GraphQLType` directly.
247247

248248
```rust
249249
graphql_object(MyType: Database |&self| {
250-
field count(&executor) -> FieldResult<i64> {
250+
field count(&executor) -> FieldResult<i32> {
251251
let txn = jtry!(executor.context().transaction());
252252

253253
let count = jtry!(txn.execute("SELECT COUNT(*) FROM user"));

src/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub enum Type<'a> {
3737
#[allow(missing_docs)]
3838
pub enum InputValue {
3939
Null,
40-
Int(i64),
40+
Int(i32),
4141
Float(f64),
4242
String(String),
4343
Boolean(bool),
@@ -208,7 +208,7 @@ impl InputValue {
208208
pub fn null() -> InputValue { InputValue::Null }
209209

210210
/// Construct an integer value.
211-
pub fn int(i: i64) -> InputValue { InputValue::Int(i) }
211+
pub fn int(i: i32) -> InputValue { InputValue::Int(i) }
212212

213213
/// Construct a floating point value.
214214
pub fn float(f: f64) -> InputValue { InputValue::Float(f) }
@@ -310,7 +310,7 @@ impl InputValue {
310310
}
311311

312312
/// View the underlying int value, if present.
313-
pub fn as_int_value(&self) -> Option<i64> {
313+
pub fn as_int_value(&self) -> Option<i32> {
314314
match *self {
315315
InputValue::Int(i) => Some(i),
316316
_ => None,

src/executor_tests/executor.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod field_execution {
1515
field e() -> &str { "Egg" }
1616
field f() -> &str { "Fish" }
1717

18-
field pic(size: Option<i64>) -> String {
18+
field pic(size: Option<i32>) -> String {
1919
format!("Pic of size: {}", size.unwrap_or(50))
2020
}
2121

@@ -219,7 +219,7 @@ mod dynamic_context_switching {
219219
}
220220

221221
struct OuterContext {
222-
items: HashMap<i64, InnerContext>,
222+
items: HashMap<i32, InnerContext>,
223223
}
224224

225225
impl Context for OuterContext {}
@@ -228,17 +228,17 @@ mod dynamic_context_switching {
228228
struct ItemRef;
229229

230230
graphql_object!(Schema: OuterContext |&self| {
231-
field item_opt(&executor, key: i64) -> Option<(&InnerContext, ItemRef)> {
231+
field item_opt(&executor, key: i32) -> Option<(&InnerContext, ItemRef)> {
232232
executor.context().items.get(&key).map(|c| (c, ItemRef))
233233
}
234234

235-
field item_res(&executor, key: i64) -> FieldResult<(&InnerContext, ItemRef)> {
235+
field item_res(&executor, key: i32) -> FieldResult<(&InnerContext, ItemRef)> {
236236
executor.context().items.get(&key)
237237
.ok_or(format!("Could not find key {}", key))
238238
.map(|c| (c, ItemRef))
239239
}
240240

241-
field item_res_opt(&executor, key: i64) -> FieldResult<Option<(&InnerContext, ItemRef)>> {
241+
field item_res_opt(&executor, key: i32) -> FieldResult<Option<(&InnerContext, ItemRef)>> {
242242
if key > 100 {
243243
Err(format!("Key too large: {}", key))
244244
} else {
@@ -247,7 +247,7 @@ mod dynamic_context_switching {
247247
}
248248
}
249249

250-
field item_always(&executor, key: i64) -> (&InnerContext, ItemRef) {
250+
field item_always(&executor, key: i32) -> (&InnerContext, ItemRef) {
251251
executor.context().items.get(&key)
252252
.map(|c| (c, ItemRef))
253253
.unwrap()

src/executor_tests/introspection.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ enum Sample {
88
Two,
99
}
1010

11-
struct Scalar(i64);
11+
struct Scalar(i32);
1212

1313
struct Interface {}
1414

@@ -51,8 +51,8 @@ graphql_object!(Root: () |&self| {
5151
}
5252

5353
field sample_scalar(
54-
first: i64 as "The first number",
55-
second = 123: i64 as "The second number"
54+
first: i32 as "The first number",
55+
second = 123: i32 as "The second number"
5656
) -> Scalar as "A sample scalar field on the object" {
5757
Scalar(first + second)
5858
}

src/executor_tests/variables.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ graphql_input_object!(
5353
#[derive(Debug)]
5454
struct ExampleInputObject {
5555
a: Option<String>,
56-
b: i64,
56+
b: i32,
5757
}
5858
);
5959

6060
graphql_input_object!(
6161
#[derive(Debug)]
6262
struct InputWithDefaults {
63-
a = 123: i64,
63+
a = 123: i32,
6464
}
6565
);
6666

@@ -109,7 +109,7 @@ graphql_object!(TestType: () |&self| {
109109
format!("a: {:?}", arg.a)
110110
}
111111

112-
field integer_input(value: i64) -> String {
112+
field integer_input(value: i32) -> String {
113113
format!("value: {}", value)
114114
}
115115

src/integrations/serde.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'de> de::Deserialize<'de> for InputValue {
7171
where E: de::Error,
7272
{
7373
if value >= i32::min_value() as i64 && value <= i32::max_value() as i64 {
74-
Ok(InputValue::int(value))
74+
Ok(InputValue::int(value as i32))
7575
}
7676
else {
7777
Err(E::custom(format!("integer out of range")))
@@ -146,7 +146,7 @@ impl ser::Serialize for InputValue {
146146
{
147147
match *self {
148148
InputValue::Null | InputValue::Variable(_) => serializer.serialize_unit(),
149-
InputValue::Int(v) => serializer.serialize_i64(v),
149+
InputValue::Int(v) => serializer.serialize_i64(v as i64),
150150
InputValue::Float(v) => serializer.serialize_f64(v),
151151
InputValue::String(ref v) | InputValue::Enum(ref v) => serializer.serialize_str(v),
152152
InputValue::Boolean(v) => serializer.serialize_bool(v),
@@ -226,7 +226,7 @@ impl ser::Serialize for Value {
226226
{
227227
match *self {
228228
Value::Null => serializer.serialize_unit(),
229-
Value::Int(v) => serializer.serialize_i64(v),
229+
Value::Int(v) => serializer.serialize_i64(v as i64),
230230
Value::Float(v) => serializer.serialize_f64(v),
231231
Value::String(ref v) => serializer.serialize_str(v),
232232
Value::Boolean(v) => serializer.serialize_bool(v),

src/macros/input_object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ is similar to argument default values:
3737
#
3838
graphql_input_object!(
3939
struct SampleObject {
40-
foo = 123: i64 as "A sample field, defaults to 123 if omitted"
40+
foo = 123: i32 as "A sample field, defaults to 123 if omitted"
4141
}
4242
);
4343

src/macros/object.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ graphql_object!(<'a> &'a SomeTrait: () as "SomeTrait" |&self| {
7979
struct GenericType<T> { items: Vec<T> }
8080
8181
graphql_object!(<T> GenericType<T>: () as "GenericType" |&self| {
82-
field count() -> i64 { self.items.len() as i64 }
82+
field count() -> i32 { self.items.len() as i32 }
8383
});
8484
8585
# fn main() { }
@@ -215,9 +215,9 @@ default value, _or_ make the type into an `Option<>`, the argument becomes
215215
optional. For example:
216216
217217
```text
218-
arg_name: i64 -- required
219-
arg_name: Option<i64> -- optional, None if unspecified
220-
arg_name = 123: i64 -- optional, "123" if unspecified
218+
arg_name: i32 -- required
219+
arg_name: Option<i32> -- optional, None if unspecified
220+
arg_name = 123: i32 -- optional, "123" if unspecified
221221
```
222222
223223
Due to some syntactical limitations in the macros, you must parentesize more

src/macros/tests/args.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,59 +22,59 @@ Syntax to validate:
2222
graphql_input_object!(
2323
#[derive(Debug)]
2424
struct Point {
25-
x: i64,
25+
x: i32,
2626
}
2727
);
2828

2929
graphql_object!(Root: () |&self| {
30-
field simple() -> i64 { 0 }
31-
field exec_arg(&executor) -> i64 { 0 }
32-
field exec_arg_and_more(&executor, arg: i64) -> i64 { 0 }
30+
field simple() -> i32 { 0 }
31+
field exec_arg(&executor) -> i32 { 0 }
32+
field exec_arg_and_more(&executor, arg: i32) -> i32 { 0 }
3333

34-
field single_arg(arg: i64) -> i64 { 0 }
34+
field single_arg(arg: i32) -> i32 { 0 }
3535
field multi_args(
36-
arg1: i64,
37-
arg2: i64
38-
) -> i64 { 0 }
36+
arg1: i32,
37+
arg2: i32
38+
) -> i32 { 0 }
3939
field multi_args_trailing_comma(
40-
arg1: i64,
41-
arg2: i64,
42-
) -> i64 { 0 }
40+
arg1: i32,
41+
arg2: i32,
42+
) -> i32 { 0 }
4343

44-
field single_arg_descr(arg: i64 as "The arg") -> i64 { 0 }
44+
field single_arg_descr(arg: i32 as "The arg") -> i32 { 0 }
4545
field multi_args_descr(
46-
arg1: i64 as "The first arg",
47-
arg2: i64 as "The second arg"
48-
) -> i64 { 0 }
46+
arg1: i32 as "The first arg",
47+
arg2: i32 as "The second arg"
48+
) -> i32 { 0 }
4949
field multi_args_descr_trailing_comma(
50-
arg1: i64 as "The first arg",
51-
arg2: i64 as "The second arg",
52-
) -> i64 { 0 }
50+
arg1: i32 as "The first arg",
51+
arg2: i32 as "The second arg",
52+
) -> i32 { 0 }
5353

54-
field arg_with_default(arg = 123: i64) -> i64 { 0 }
54+
field arg_with_default(arg = 123: i32) -> i32 { 0 }
5555
field multi_args_with_default(
56-
arg1 = 123: i64,
57-
arg2 = 456: i64
58-
) -> i64 { 0 }
56+
arg1 = 123: i32,
57+
arg2 = 456: i32
58+
) -> i32 { 0 }
5959
field multi_args_with_default_trailing_comma(
60-
arg1 = 123: i64,
61-
arg2 = 456: i64,
62-
) -> i64 { 0 }
60+
arg1 = 123: i32,
61+
arg2 = 456: i32,
62+
) -> i32 { 0 }
6363

64-
field arg_with_default_descr(arg = 123: i64 as "The arg") -> i64 { 0 }
64+
field arg_with_default_descr(arg = 123: i32 as "The arg") -> i32 { 0 }
6565
field multi_args_with_default_descr(
66-
arg1 = 123: i64 as "The first arg",
67-
arg2 = 456: i64 as "The second arg"
68-
) -> i64 { 0 }
66+
arg1 = 123: i32 as "The first arg",
67+
arg2 = 456: i32 as "The second arg"
68+
) -> i32 { 0 }
6969
field multi_args_with_default_trailing_comma_descr(
70-
arg1 = 123: i64 as "The first arg",
71-
arg2 = 456: i64 as "The second arg",
72-
) -> i64 { 0 }
70+
arg1 = 123: i32 as "The first arg",
71+
arg2 = 456: i32 as "The second arg",
72+
) -> i32 { 0 }
7373

7474
field args_with_complex_default(
7575
arg1 = ("test".to_owned()): String as "A string default argument",
7676
arg2 = (Point { x: 1 }): Point as "An input object default argument",
77-
) -> i64 { 0 }
77+
) -> i32 { 0 }
7878
});
7979

8080
fn run_args_info_query<F>(field_name: &str, f: F)

src/macros/tests/field.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,35 @@ Syntax to validate:
2222
*/
2323

2424
graphql_object!(Root: () |&self| {
25-
field simple() -> i64 { 0 }
25+
field simple() -> i32 { 0 }
2626

27-
field description() -> i64 as "Field description" { 0 }
27+
field description() -> i32 as "Field description" { 0 }
2828

2929
field deprecated "Deprecation reason"
30-
deprecated() -> i64 { 0 }
30+
deprecated() -> i32 { 0 }
3131

3232
field deprecated "Deprecation reason"
33-
deprecated_descr() -> i64 as "Field description" { 0 }
33+
deprecated_descr() -> i32 as "Field description" { 0 }
3434

35-
field with_field_result() -> FieldResult<i64> { Ok(0) }
35+
field with_field_result() -> FieldResult<i32> { Ok(0) }
3636

37-
field with_return() -> i64 { return 0; }
37+
field with_return() -> i32 { return 0; }
3838

39-
field with_return_field_result() -> FieldResult<i64> { return Ok(0); }
39+
field with_return_field_result() -> FieldResult<i32> { return Ok(0); }
4040

4141
interfaces: [Interface]
4242
});
4343

4444
graphql_interface!(Interface: () |&self| {
45-
field simple() -> i64 { 0 }
45+
field simple() -> i32 { 0 }
4646

47-
field description() -> i64 as "Field description" { 0 }
47+
field description() -> i32 as "Field description" { 0 }
4848

4949
field deprecated "Deprecation reason"
50-
deprecated() -> i64 { 0 }
50+
deprecated() -> i32 { 0 }
5151

5252
field deprecated "Deprecation reason"
53-
deprecated_descr() -> i64 as "Field description" { 0 }
53+
deprecated_descr() -> i32 as "Field description" { 0 }
5454

5555
instance_resolvers: |&_| {
5656
Root => Some(Root {}),

0 commit comments

Comments
 (0)