Skip to content

Commit 62054bc

Browse files
committed
Always sort scalar types by name when returning them
Previously these were returned in an essentially random order. This would lead to flapping in the generated code when running the client CLI against the same schema multiple times. In the application I'm writing, I check in the generated schema, so this sort of flapping in the generated code creates unwanted noise in the commit history.
1 parent e79e30c commit 62054bc

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
`rustls` rather than `native-tls`.
1313
- Code generated by the `graphql-client` CLI program now suppresses all
1414
warnings from rustc and clippy.
15+
- The generated code now sorts scalar types by name. This fixes "flapping" in
16+
the generated code that used to happen as the scalar types would be randomly
17+
ordered each time the generator ran.
1518

1619
## 0.10.0 - 2021-07-04
1720

graphql_client_codegen/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ repository = "https://github.com/graphql-rust/graphql-client"
88
edition = "2018"
99

1010
[dependencies]
11+
itertools = "0.10.3"
1112
graphql-introspection-query = { version = "0.2.0", path = "../graphql-introspection-query" }
1213
graphql-parser = "^0.2"
1314
heck = "0.4.0"

graphql_client_codegen/src/query.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::{
1818
StoredInputType, StoredScalar, TypeId, UnionId,
1919
},
2020
};
21+
use itertools::Itertools;
2122
use std::{
2223
collections::{HashMap, HashSet},
2324
fmt::Display,
@@ -605,6 +606,7 @@ impl UsedTypes {
605606
.filter_map(TypeId::as_scalar_id)
606607
.map(move |scalar_id| (scalar_id, schema.get_scalar(scalar_id)))
607608
.filter(|(_id, scalar)| !crate::schema::DEFAULT_SCALARS.contains(&scalar.name.as_str()))
609+
.sorted_by_key(|(_id, scalar)| scalar.name.as_str())
608610
}
609611

610612
pub(crate) fn enums<'a, 'schema: 'a>(

0 commit comments

Comments
 (0)