Browse Source

Upgrade cynic to v3

I released v3 of cynic a while back, figured I might as well contribute
an upgrade in triagebot.

The main changes that'll have an impact here are:

1. I've added the ability to pre parse schems in `build.rs`, which is
   now in use here.  This makes a big difference to the compile time
   of crates using large schemas (such as the GitHub schema triagebot
   uses).
2. The `schema_for_derives` attribute macro is no longer required so
   I've got rid of that.
3. Query variables can now be references so I've made that change in the
   places where it made sense.
Graeme Coupar 1 year ago
parent
commit
4f17ff49ca
6 changed files with 285 additions and 39 deletions
  1. 256 15
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 4 1
      github-graphql/Cargo.toml
  4. 7 0
      github-graphql/build.rs
  5. 9 14
      github-graphql/src/lib.rs
  6. 8 8
      src/github.rs

+ 256 - 15
Cargo.lock

@@ -2,6 +2,12 @@
 # It is not intended for manual editing.
 version = 3
 
+[[package]]
+name = "Inflector"
+version = "0.11.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
+
 [[package]]
 name = "addr2line"
 version = "0.17.0"
@@ -17,6 +23,17 @@ version = "1.0.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
 
+[[package]]
+name = "ahash"
+version = "0.7.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd"
+dependencies = [
+ "getrandom",
+ "once_cell",
+ "version_check",
+]
+
 [[package]]
 name = "aho-corasick"
 version = "0.7.18"
@@ -26,6 +43,12 @@ dependencies = [
  "memchr",
 ]
 
+[[package]]
+name = "aliasable"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd"
+
 [[package]]
 name = "ansi_term"
 version = "0.12.1"
@@ -109,6 +132,18 @@ version = "2.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
 
+[[package]]
+name = "bitvec"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c"
+dependencies = [
+ "funty",
+ "radium",
+ "tap",
+ "wyz",
+]
+
 [[package]]
 name = "block-buffer"
 version = "0.7.3"
@@ -160,6 +195,28 @@ version = "0.3.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
 
+[[package]]
+name = "bytecheck"
+version = "0.6.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8b6372023ac861f6e6dc89c8344a8f398fb42aaba2b5dbc649ca0c0e9dbcb627"
+dependencies = [
+ "bytecheck_derive",
+ "ptr_meta",
+ "simdutf8",
+]
+
+[[package]]
+name = "bytecheck_derive"
+version = "0.6.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a7ec4c6f261935ad534c0c22dbef2201b45918860eb1c574b972bd213a76af61"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 1.0.91",
+]
+
 [[package]]
 name = "byteorder"
 version = "1.4.3"
@@ -296,11 +353,12 @@ dependencies = [
 
 [[package]]
 name = "cynic"
-version = "2.2.2"
+version = "3.2.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a4a3b1c069f38d62c0795fd74df7a55bde42d3ff44e58a00576d1e5c65222fa8"
+checksum = "bf035d785657f3621eee03fdfeefab48127d8b1643b6f9edf8b3cd66cbd86e9b"
 dependencies = [
  "cynic-proc-macros",
+ "ref-cast",
  "serde",
  "static_assertions",
  "thiserror",
@@ -308,35 +366,39 @@ dependencies = [
 
 [[package]]
 name = "cynic-codegen"
-version = "2.2.2"
+version = "3.2.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "aefc758a26044bd02a2a0ecb871b158abcb98c92d93d7bc40750285064de602c"
+checksum = "4e8e65b71a8bd2751712ab38326b73a5f98405b6b5f8fd4dae658e58c1576d09"
 dependencies = [
  "counter",
  "darling",
  "graphql-parser",
  "once_cell",
+ "ouroboros",
  "proc-macro2",
  "quote",
+ "rkyv",
  "strsim",
  "syn 1.0.91",
+ "thiserror",
 ]
 
 [[package]]
 name = "cynic-proc-macros"
-version = "2.2.2"
+version = "3.2.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c948605f5b7ae37c2e70b42c71679172c4a147351ee1b475578ea8f7d70680db"
+checksum = "4a933ea1f357cbd48f2068c59457631696ae58d554f89290e4da272b1f69ebf1"
 dependencies = [
  "cynic-codegen",
+ "quote",
  "syn 1.0.91",
 ]
 
 [[package]]
 name = "darling"
-version = "0.13.4"
+version = "0.14.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
+checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850"
 dependencies = [
  "darling_core",
  "darling_macro",
@@ -344,9 +406,9 @@ dependencies = [
 
 [[package]]
 name = "darling_core"
-version = "0.13.4"
+version = "0.14.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
+checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0"
 dependencies = [
  "fnv",
  "ident_case",
@@ -358,9 +420,9 @@ dependencies = [
 
 [[package]]
 name = "darling_macro"
-version = "0.13.4"
+version = "0.14.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
+checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
 dependencies = [
  "darling_core",
  "quote",
@@ -497,6 +559,12 @@ dependencies = [
  "percent-encoding",
 ]
 
+[[package]]
+name = "funty"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
+
 [[package]]
 name = "futures"
 version = "0.3.21"
@@ -637,6 +705,7 @@ version = "0.1.0"
 dependencies = [
  "chrono",
  "cynic",
+ "cynic-codegen",
 ]
 
 [[package]]
@@ -704,6 +773,15 @@ version = "0.11.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
 
+[[package]]
+name = "hashbrown"
+version = "0.12.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
+dependencies = [
+ "ahash",
+]
+
 [[package]]
 name = "heck"
 version = "0.4.1"
@@ -880,7 +958,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee"
 dependencies = [
  "autocfg",
- "hashbrown",
+ "hashbrown 0.11.2",
  "serde",
 ]
 
@@ -1208,6 +1286,29 @@ dependencies = [
  "vcpkg",
 ]
 
+[[package]]
+name = "ouroboros"
+version = "0.15.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e1358bd1558bd2a083fed428ffeda486fbfb323e698cdda7794259d592ca72db"
+dependencies = [
+ "aliasable",
+ "ouroboros_macro",
+]
+
+[[package]]
+name = "ouroboros_macro"
+version = "0.15.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5f7d21ccd03305a674437ee1248f3ab5d4b1db095cf1caf49f1713ddf61956b7"
+dependencies = [
+ "Inflector",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn 1.0.91",
+]
+
 [[package]]
 name = "parking_lot"
 version = "0.11.2"
@@ -1411,7 +1512,7 @@ dependencies = [
  "postgres-protocol",
  "serde",
  "serde_json",
- "uuid",
+ "uuid 0.8.2",
 ]
 
 [[package]]
@@ -1420,6 +1521,30 @@ version = "0.2.16"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
 
+[[package]]
+name = "proc-macro-error"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
+dependencies = [
+ "proc-macro-error-attr",
+ "proc-macro2",
+ "quote",
+ "syn 1.0.91",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro-error-attr"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "version_check",
+]
+
 [[package]]
 name = "proc-macro2"
 version = "1.0.67"
@@ -1429,6 +1554,26 @@ dependencies = [
  "unicode-ident",
 ]
 
+[[package]]
+name = "ptr_meta"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1"
+dependencies = [
+ "ptr_meta_derive",
+]
+
+[[package]]
+name = "ptr_meta_derive"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 1.0.91",
+]
+
 [[package]]
 name = "pulldown-cmark"
 version = "0.7.2"
@@ -1450,6 +1595,12 @@ dependencies = [
  "proc-macro2",
 ]
 
+[[package]]
+name = "radium"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
+
 [[package]]
 name = "rand"
 version = "0.8.5"
@@ -1500,6 +1651,26 @@ dependencies = [
  "thiserror",
 ]
 
+[[package]]
+name = "ref-cast"
+version = "1.0.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "acde58d073e9c79da00f2b5b84eed919c8326832648a5b109b3fce1bb1175280"
+dependencies = [
+ "ref-cast-impl",
+]
+
+[[package]]
+name = "ref-cast-impl"
+version = "1.0.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f7473c2cfcf90008193dd0e3e16599455cb601a9fce322b5bb55de799664925"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.37",
+]
+
 [[package]]
 name = "regex"
 version = "1.6.0"
@@ -1535,6 +1706,15 @@ dependencies = [
  "winapi",
 ]
 
+[[package]]
+name = "rend"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2571463863a6bd50c32f94402933f03457a3fbaf697a707c5be741e459f08fd"
+dependencies = [
+ "bytecheck",
+]
+
 [[package]]
 name = "reqwest"
 version = "0.11.20"
@@ -1587,6 +1767,34 @@ dependencies = [
  "winapi",
 ]
 
+[[package]]
+name = "rkyv"
+version = "0.7.42"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0200c8230b013893c0b2d6213d6ec64ed2b9be2e0e016682b7224ff82cff5c58"
+dependencies = [
+ "bitvec",
+ "bytecheck",
+ "hashbrown 0.12.3",
+ "ptr_meta",
+ "rend",
+ "rkyv_derive",
+ "seahash",
+ "tinyvec",
+ "uuid 1.5.0",
+]
+
+[[package]]
+name = "rkyv_derive"
+version = "0.7.42"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b2e06b915b5c230a17d7a736d1e2e63ee753c256a8614ef3f5147b13a4f5541d"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 1.0.91",
+]
+
 [[package]]
 name = "route-recognizer"
 version = "0.3.1"
@@ -1692,6 +1900,12 @@ dependencies = [
  "untrusted",
 ]
 
+[[package]]
+name = "seahash"
+version = "4.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
+
 [[package]]
 name = "secrecy"
 version = "0.8.0"
@@ -1814,6 +2028,12 @@ version = "1.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
 
+[[package]]
+name = "simdutf8"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a"
+
 [[package]]
 name = "simple_asn1"
 version = "0.6.2"
@@ -1933,6 +2153,12 @@ dependencies = [
  "unicode-ident",
 ]
 
+[[package]]
+name = "tap"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
+
 [[package]]
 name = "tempfile"
 version = "3.3.0"
@@ -2318,7 +2544,7 @@ dependencies = [
  "tracing",
  "tracing-subscriber",
  "url",
- "uuid",
+ "uuid 0.8.2",
 ]
 
 [[package]]
@@ -2496,6 +2722,12 @@ dependencies = [
  "serde",
 ]
 
+[[package]]
+name = "uuid"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc"
+
 [[package]]
 name = "valuable"
 version = "0.1.0"
@@ -2736,6 +2968,15 @@ dependencies = [
  "windows-sys",
 ]
 
+[[package]]
+name = "wyz"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed"
+dependencies = [
+ "tap",
+]
+
 [[package]]
 name = "xdg"
 version = "2.4.1"

+ 1 - 1
Cargo.toml

@@ -36,7 +36,7 @@ serde_path_to_error = "0.1.2"
 octocrab = "0.30.1"
 comrak = { version = "0.8.2", default-features = false }
 route-recognizer = "0.3.0"
-cynic = { version = "2.0.0" }
+cynic = "3"
 itertools = "0.10.2"
 tower = { version = "0.4.13", features = ["util", "limit", "buffer", "load-shed"] }
 github-graphql = { path = "github-graphql" }

+ 4 - 1
github-graphql/Cargo.toml

@@ -5,4 +5,7 @@ edition = "2021"
 
 [dependencies]
 chrono = { version = "0.4", features = ["serde"] }
-cynic = { version = "2.2.2" }
+cynic = { version = "3", features = ["rkyv"] }
+
+[build-dependencies]
+cynic-codegen = { version = "3", features = ["rkyv"] }

+ 7 - 0
github-graphql/build.rs

@@ -0,0 +1,7 @@
+pub fn main() {
+    cynic_codegen::register_schema("github")
+        .from_sdl_file("src/github.graphql")
+        .unwrap()
+        .as_default()
+        .unwrap();
+}

+ 9 - 14
github-graphql/src/lib.rs

@@ -3,7 +3,6 @@
 //! See <https://docs.github.com/en/graphql> for more GitHub's GraphQL API.
 
 // This schema can be downloaded from https://docs.github.com/public/schema.docs.graphql
-#[cynic::schema_for_derives(file = "src/github.graphql", module = "schema")]
 pub mod queries {
     use super::schema;
 
@@ -14,9 +13,9 @@ pub mod queries {
     cynic::impl_scalar!(DateTime, schema::DateTime);
 
     #[derive(cynic::QueryVariables, Debug, Clone)]
-    pub struct LeastRecentlyReviewedPullRequestsArguments {
-        pub repository_owner: String,
-        pub repository_name: String,
+    pub struct LeastRecentlyReviewedPullRequestsArguments<'a> {
+        pub repository_owner: &'a str,
+        pub repository_name: &'a str,
         pub after: Option<String>,
     }
 
@@ -132,16 +131,15 @@ pub mod queries {
     pub struct Uri(pub String);
 }
 
-#[cynic::schema_for_derives(file = "src/github.graphql", module = "schema")]
 pub mod docs_update_queries {
     use super::queries::{DateTime, PageInfo};
     use super::schema;
 
     #[derive(cynic::QueryVariables, Clone, Debug)]
-    pub struct RecentCommitsArguments {
-        pub branch: String,
-        pub name: String,
-        pub owner: String,
+    pub struct RecentCommitsArguments<'a> {
+        pub branch: &'a str,
+        pub name: &'a str,
+        pub owner: &'a str,
         pub after: Option<String>,
     }
 
@@ -268,12 +266,9 @@ pub mod docs_update_queries {
     pub struct GitObjectID(pub String);
 }
 
-#[allow(non_snake_case, non_camel_case_types)]
-mod schema {
-    cynic::use_schema!("src/github.graphql");
-}
+#[cynic::schema("github")]
+mod schema {}
 
-#[cynic::schema_for_derives(file = "src/github.graphql", module = "schema")]
 pub mod project_items {
     use super::queries::{Date, PageInfo, Uri};
     use super::schema;

+ 8 - 8
src/github.rs

@@ -1287,9 +1287,9 @@ impl Repository {
         };
 
         let mut args = RecentCommitsArguments {
-            branch: branch.to_string(),
-            name: self.name().to_string(),
-            owner: self.owner().to_string(),
+            branch,
+            name: self.name(),
+            owner: self.owner(),
             after: None,
         };
         let mut found_newest = false;
@@ -2167,14 +2167,14 @@ impl IssuesQuery for LeastRecentlyReviewedPullRequests {
         use cynic::QueryBuilder;
         use github_graphql::queries;
 
-        let repository_owner = repo.owner().to_owned();
-        let repository_name = repo.name().to_owned();
+        let repository_owner = repo.owner();
+        let repository_name = repo.name();
 
         let mut prs: Vec<queries::PullRequest> = vec![];
 
         let mut args = queries::LeastRecentlyReviewedPullRequestsArguments {
             repository_owner,
-            repository_name: repository_name.clone(),
+            repository_name,
             after: None,
         };
         loop {
@@ -2264,7 +2264,7 @@ impl IssuesQuery for LeastRecentlyReviewedPullRequests {
                     pr.number as u64,
                     pr.title,
                     pr.url.0,
-                    repository_name.clone(),
+                    repository_name,
                     labels,
                     assignees,
                 ))
@@ -2283,7 +2283,7 @@ impl IssuesQuery for LeastRecentlyReviewedPullRequests {
                         number,
                         title,
                         html_url,
-                        repo_name,
+                        repo_name: repo_name.to_string(),
                         labels,
                         assignees,
                         updated_at_hts,