Skip to content

Commit dcaf5c8

Browse files
authored
Merge pull request #133 from tomhoule/reenable-nightly-ci
Reenable the nightly channel in ci
2 parents 8d2c3f6 + d1f2b58 commit dcaf5c8

File tree

11 files changed

+155
-156
lines changed

11 files changed

+155
-156
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ language: rust
22
rust:
33
- stable
44
- beta
5-
# - nightly
5+
- nightly
66
cache: cargo
77
before_script:
8-
- if [ "$TRAVIS_RUST_VERSION" = "nightly" ]; then (rustup component add rustfmt-preview clippy-preview) fi
8+
- if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then (rustup component add rustfmt-preview clippy-preview) fi
99
script:
10-
- if [ "$TRAVIS_RUST_VERSION" = "nightly" ]; then (cargo fmt --all -- --check) fi
11-
- if [ "$TRAVIS_RUST_VERSION" = "nightly" ]; then (cargo clippy) fi
10+
- if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then (cargo fmt --all -- --check) fi
11+
- if [ "$TRAVIS_RUST_VERSION" = "stable" ]; then (cargo clippy) fi
1212
- cargo test --all
1313
- cargo build --manifest-path=./examples/github/Cargo.toml
1414
- cargo build --manifest-path=./graphql_client_cli/Cargo.toml

graphql_client_codegen/src/codegen.rs

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,25 @@ pub fn response_for_query(
4949
.find(|op| op.name == selected_operation)
5050
.map(|i| i.to_owned());
5151

52-
let opt_operation = context.selected_operation.clone().or_else(|| {
53-
operations
54-
.iter()
55-
.next()
56-
.map(|i| i.to_owned())
57-
});
52+
let opt_operation = context
53+
.selected_operation
54+
.clone()
55+
.or_else(|| operations.iter().next().map(|i| i.to_owned()));
5856
let operation = if let Some(operation) = opt_operation {
5957
operation
6058
} else {
6159
panic!("no operation '{}' in query document", selected_operation);
6260
};
6361

6462
let response_data_fields = {
65-
let opt_root_name = operation
66-
.root_name(&context.schema);
63+
let opt_root_name = operation.root_name(&context.schema);
6764
let root_name: String = if let Some(root_name) = opt_root_name {
6865
root_name
6966
} else {
70-
panic!("operation type '{:?}' not in schema", operation.operation_type);
67+
panic!(
68+
"operation type '{:?}' not in schema",
69+
operation.operation_type
70+
);
7171
};
7272
let definition = context
7373
.schema
@@ -94,17 +94,13 @@ pub fn response_for_query(
9494
.unwrap()
9595
};
9696

97-
let enum_definitions = context
98-
.schema
99-
.enums
100-
.values()
101-
.filter_map(|enm| {
102-
if enm.is_required.get() {
103-
Some(enm.to_rust(&context))
104-
} else {
105-
None
106-
}
107-
});
97+
let enum_definitions = context.schema.enums.values().filter_map(|enm| {
98+
if enm.is_required.get() {
99+
Some(enm.to_rust(&context))
100+
} else {
101+
None
102+
}
103+
});
108104
let fragment_definitions: Result<Vec<TokenStream>, _> = context
109105
.fragments
110106
.values()
@@ -114,8 +110,7 @@ pub fn response_for_query(
114110
} else {
115111
None
116112
}
117-
})
118-
.collect();
113+
}).collect();
119114
let fragment_definitions = fragment_definitions?;
120115
let variables_struct = operation.expand_variables(&context);
121116

@@ -129,8 +124,7 @@ pub fn response_for_query(
129124
} else {
130125
None
131126
}
132-
})
133-
.collect();
127+
}).collect();
134128
let input_object_definitions = input_object_definitions?;
135129

136130
let scalar_definitions: Vec<TokenStream> = context
@@ -143,8 +137,7 @@ pub fn response_for_query(
143137
} else {
144138
None
145139
}
146-
})
147-
.collect();
140+
}).collect();
148141

149142
let response_derives = context.response_derives();
150143

graphql_client_codegen/src/field_type.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,22 @@ impl FieldType {
2222
};
2323
match &self {
2424
FieldType::Named(ref name) => {
25-
let full_name = if context.schema.scalars.get(name).map(|s| s.is_required.set(true)).is_some() || DEFAULT_SCALARS
26-
.iter()
27-
.any(|elem| elem == name)
25+
let full_name = if context
26+
.schema
27+
.scalars
28+
.get(name)
29+
.map(|s| s.is_required.set(true))
30+
.is_some()
31+
|| DEFAULT_SCALARS.iter().any(|elem| elem == name)
2832
{
2933
name.clone()
30-
} else if context.schema.enums.get(name).map(|enm| enm.is_required.set(true)).is_some() {
34+
} else if context
35+
.schema
36+
.enums
37+
.get(name)
38+
.map(|enm| enm.is_required.set(true))
39+
.is_some()
40+
{
3141
format!("{}{}", ENUMS_PREFIX, name)
3242
} else {
3343
if prefix.is_empty() {
@@ -155,10 +165,7 @@ mod tests {
155165

156166
let ty = GqlParserType::NonNullType(Box::new(GqlParserType::NamedType("Cat".to_string())));
157167

158-
assert_eq!(
159-
FieldType::from(ty),
160-
FieldType::Named("Cat".to_string())
161-
);
168+
assert_eq!(FieldType::from(ty), FieldType::Named("Cat".to_string()));
162169
}
163170

164171
#[test]
@@ -186,9 +193,6 @@ mod tests {
186193
})),
187194
},
188195
};
189-
assert_eq!(
190-
FieldType::from(ty),
191-
FieldType::Named("Cat".to_string())
192-
);
196+
assert_eq!(FieldType::from(ty), FieldType::Named("Cat".to_string()));
193197
}
194198
}

graphql_client_codegen/src/fragments.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ impl GqlFragment {
1919
let object = if let Some(object) = opt_object {
2020
object
2121
} else {
22-
panic!("fragment '{}' cannot operate on unknown type '{}'", self.name, self.on);
22+
panic!(
23+
"fragment '{}' cannot operate on unknown type '{}'",
24+
self.name, self.on
25+
);
2326
};
2427
let field_impls = object.field_impls_for_selection(context, &self.selection, &self.name)?;
2528
let fields = object.response_fields_for_selection(context, &self.selection, &self.name)?;

graphql_client_codegen/src/inputs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use objects::GqlObjectField;
77
use proc_macro2::{Ident, Span, TokenStream};
88
use query::QueryContext;
99
use schema::Schema;
10-
use std::collections::HashMap;
1110
use std::cell::Cell;
11+
use std::collections::HashMap;
1212

1313
/// Represents an input object type from a GraphQL schema
1414
#[derive(Debug, Clone, PartialEq)]
@@ -25,11 +25,9 @@ impl GqlInput {
2525
return;
2626
}
2727
self.is_required.set(true);
28-
self.fields
29-
.values()
30-
.for_each(|field| {
31-
schema.require(&field.type_.inner_name_string());
32-
})
28+
self.fields.values().for_each(|field| {
29+
schema.require(&field.type_.inner_name_string());
30+
})
3331
}
3432

3533
pub(crate) fn to_rust(&self, context: &QueryContext) -> Result<TokenStream, failure::Error> {
@@ -144,7 +142,9 @@ mod tests {
144142
GqlObjectField {
145143
description: None,
146144
name: "requirements".to_string(),
147-
type_: FieldType::Optional(Box::new(FieldType::Named("CatRequirements".to_string()))),
145+
type_: FieldType::Optional(Box::new(FieldType::Named(
146+
"CatRequirements".to_string(),
147+
))),
148148
deprecation: DeprecationStatus::Current,
149149
},
150150
),

graphql_client_codegen/src/interfaces.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,37 @@ impl GqlInterface {
4343
.ok_or_else(|| format_err!("Missing __typename in selection for {}", prefix))?;
4444

4545
let object_selection = Selection(
46-
selection.0.iter()
47-
// Only keep what we can handle
48-
.filter(|f| match f {
49-
SelectionItem::Field(f) => f.name != "__typename",
50-
SelectionItem::FragmentSpread(_) => true,
51-
SelectionItem::InlineFragment(_) => false,
52-
}).map(|a| (*a).clone()).collect(),
46+
selection
47+
.0
48+
.iter()
49+
// Only keep what we can handle
50+
.filter(|f| match f {
51+
SelectionItem::Field(f) => f.name != "__typename",
52+
SelectionItem::FragmentSpread(_) => true,
53+
SelectionItem::InlineFragment(_) => false,
54+
}).map(|a| (*a).clone())
55+
.collect(),
5356
);
5457

5558
let union_selection = Selection(
56-
selection.0.iter()
57-
// Only keep what we can handle
58-
.filter(|f| match f {
59-
SelectionItem::InlineFragment(_) => true,
60-
SelectionItem::Field(_) | SelectionItem::FragmentSpread(_) => false,
61-
}).map(|a| (*a).clone()).collect(),
59+
selection
60+
.0
61+
.iter()
62+
// Only keep what we can handle
63+
.filter(|f| match f {
64+
SelectionItem::InlineFragment(_) => true,
65+
SelectionItem::Field(_) | SelectionItem::FragmentSpread(_) => false,
66+
}).map(|a| (*a).clone())
67+
.collect(),
6268
);
6369

64-
let object_fields =
65-
response_fields_for_selection(&self.name, &self.fields, query_context, &object_selection, prefix)?;
70+
let object_fields = response_fields_for_selection(
71+
&self.name,
72+
&self.fields,
73+
query_context,
74+
&object_selection,
75+
prefix,
76+
)?;
6677

6778
let object_children =
6879
field_impls_for_selection(&self.fields, query_context, &object_selection, prefix)?;

graphql_client_codegen/src/objects.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,9 @@ impl GqlObject {
114114
return;
115115
}
116116
self.is_required.set(true);
117-
self.fields
118-
.iter()
119-
.for_each(|field| {
120-
schema.require(&field.type_.inner_name_string());
121-
})
117+
self.fields.iter().for_each(|field| {
118+
schema.require(&field.type_.inner_name_string());
119+
})
122120
}
123121

124122
pub(crate) fn response_for_selection(

graphql_client_codegen/src/schema.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,22 @@ impl Schema {
5757
}
5858

5959
pub(crate) fn require(&self, typename_: &str) {
60-
DEFAULT_SCALARS.iter()
60+
DEFAULT_SCALARS
61+
.iter()
6162
.find(|&&s| s == typename_)
6263
.map(|_| ())
6364
.or_else(|| {
64-
self.enums.get(typename_)
65+
self.enums
66+
.get(typename_)
6567
.map(|enm| enm.is_required.set(true))
66-
})
67-
.or_else(|| {
68-
self.inputs.get(typename_)
69-
.map(|input| input.require(self))
70-
})
68+
}).or_else(|| self.inputs.get(typename_).map(|input| input.require(self)))
7169
.or_else(|| {
72-
self.objects.get(typename_)
70+
self.objects
71+
.get(typename_)
7372
.map(|object| object.require(self))
74-
})
75-
.or_else(|| {
76-
self.scalars.get(typename_)
73+
}).or_else(|| {
74+
self.scalars
75+
.get(typename_)
7776
.map(|scalar| scalar.is_required.set(true))
7877
});
7978
}
@@ -350,7 +349,9 @@ mod tests {
350349
description: None,
351350
name: "friends".to_string(),
352351
type_: FieldType::Optional(Box::new(FieldType::Vector(Box::new(
353-
FieldType::Optional(Box::new(FieldType::Named("Character".to_string()))),
352+
FieldType::Optional(Box::new(FieldType::Named(
353+
"Character".to_string()
354+
))),
354355
)))),
355356
deprecation: DeprecationStatus::Current,
356357
},
@@ -371,7 +372,9 @@ mod tests {
371372
GqlObjectField {
372373
description: None,
373374
name: "primaryFunction".to_string(),
374-
type_: FieldType::Optional(Box::new(FieldType::Named("String".to_string()))),
375+
type_: FieldType::Optional(Box::new(FieldType::Named(
376+
"String".to_string()
377+
))),
375378
deprecation: DeprecationStatus::Current,
376379
},
377380
],

graphql_client_codegen/src/shared.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,12 @@ pub(crate) fn field_impls_for_selection(
8282
.ok_or_else(|| format_err!("could not find field `{}`", name))?
8383
.type_
8484
.inner_name_string();
85-
let prefix = format!(
86-
"{}{}",
87-
prefix.to_camel_case(),
88-
alias.to_camel_case()
89-
);
85+
let prefix = format!("{}{}", prefix.to_camel_case(), alias.to_camel_case());
9086
context.maybe_expand_field(&ty, &selected.fields, &prefix)
9187
} else {
9288
Ok(quote!())
9389
}
94-
})
95-
.collect()
90+
}).collect()
9691
}
9792

9893
pub(crate) fn response_fields_for_selection(
@@ -118,7 +113,10 @@ pub(crate) fn response_fields_for_selection(
118113
"Could not find field `{}` on `{}`. Available fields: `{}`.",
119114
name.as_str(),
120115
type_name,
121-
schema_fields.iter().map(|ref field| &field.name).format("`, `"),
116+
schema_fields
117+
.iter()
118+
.map(|ref field| &field.name)
119+
.format("`, `"),
122120
)
123121
})?;
124122
let ty = schema_field.type_.to_rust(
@@ -144,17 +142,15 @@ pub(crate) fn response_fields_for_selection(
144142
pub #field_name: #type_name
145143
})
146144
}
147-
SelectionItem::InlineFragment(_) => {
148-
Err(format_err!("unimplemented: inline fragment on object field"))?
149-
}
150-
})
151-
.filter(|x| match x {
145+
SelectionItem::InlineFragment(_) => Err(format_err!(
146+
"unimplemented: inline fragment on object field"
147+
))?,
148+
}).filter(|x| match x {
152149
// Remove empty fields so callers always know a field has some
153150
// tokens.
154151
Ok(f) => !f.is_empty(),
155152
Err(_) => true,
156-
})
157-
.collect()
153+
}).collect()
158154
}
159155

160156
/// Given the GraphQL schema name for an object/interface/input object field and

0 commit comments

Comments
 (0)