From 688714fe2f844fddee5fbebacf4632ea158419b5 Mon Sep 17 00:00:00 2001 From: Tom Gasson Date: Thu, 19 May 2022 14:36:19 +1000 Subject: [PATCH] Allow including query text when persisting queries For safe migration from non-persisted use to persisted use --- compiler/Cargo.lock | 249 ++++++++++++------ compiler/crates/relay-codegen/src/ast.rs | 15 +- .../crates/relay-codegen/src/build_ast.rs | 106 ++++---- compiler/crates/relay-codegen/src/lib.rs | 1 + compiler/crates/relay-codegen/src/printer.rs | 13 +- .../src/artifact_content/content.rs | 29 +- .../crates/relay-config/src/project_config.rs | 8 +- .../relay-runtime/util/RelayConcreteNode.js | 36 +-- 8 files changed, 281 insertions(+), 176 deletions(-) diff --git a/compiler/Cargo.lock b/compiler/Cargo.lock index 40707328fbc50..21b9d767b975f 100644 --- a/compiler/Cargo.lock +++ b/compiler/Cargo.lock @@ -46,9 +46,9 @@ checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" [[package]] name = "async-trait" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716" +checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" dependencies = [ "proc-macro2", "quote", @@ -95,9 +95,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "block-buffer" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ "generic-array", ] @@ -157,9 +157,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.10" +version = "3.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69c5a7f9997be616e47f0577ee38c91decb33392c5be4866494f34cdf329a9aa" +checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" dependencies = [ "atty", "bitflags", @@ -177,9 +177,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.2.7" +version = "3.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902" +checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" dependencies = [ "heck 0.4.0", "proc-macro-error", @@ -190,9 +190,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.2" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5538cd660450ebeb4234cfecf8f2284b844ffc4c50531e66d584ad5b91293613" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" dependencies = [ "os_str_bytes", ] @@ -247,9 +247,9 @@ checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" dependencies = [ "libc", ] @@ -314,9 +314,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.8" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" dependencies = [ "cfg-if", "lazy_static", @@ -376,9 +376,9 @@ checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" [[package]] name = "digest" -version = "0.10.3" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" dependencies = [ "block-buffer", "crypto-common", @@ -402,6 +402,27 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "errors" version = "0.0.0" @@ -490,9 +511,9 @@ checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" [[package]] name = "futures" -version = "0.3.13" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f55667319111d593ba876406af7c409c0ebb44dc4be6132a783ccf163ea14c1" +checksum = "7f21eda599937fba36daeb58a22e8f5cee2d14c4a17b5b7739c7c8e5e3b8230c" dependencies = [ "futures-channel", "futures-core", @@ -505,9 +526,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.13" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" dependencies = [ "futures-core", "futures-sink", @@ -515,15 +536,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.13" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" [[package]] name = "futures-executor" -version = "0.3.13" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891a4b7b96d84d5940084b2a37632dd65deeae662c114ceaa2c879629c9c0ad1" +checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab" dependencies = [ "futures-core", "futures-task", @@ -532,17 +553,16 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.13" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59" +checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" [[package]] name = "futures-macro" -version = "0.3.13" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea405816a5139fb39af82c2beb921d52143f556038378d6db21183a5c37fbfb7" +checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17" dependencies = [ - "proc-macro-hack", "proc-macro2", "quote", "syn", @@ -550,21 +570,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.13" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85754d98985841b7d4f5e8e6fbfa4a4ac847916893ec511a2917ccd8525b8bb3" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" [[package]] name = "futures-task" -version = "0.3.13" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" [[package]] name = "futures-util" -version = "0.3.13" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures 0.1.31", "futures-channel", @@ -576,8 +596,6 @@ dependencies = [ "memchr", "pin-project-lite", "pin-utils", - "proc-macro-hack", - "proc-macro-nested", "slab", ] @@ -726,9 +744,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.11.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ "ahash", "serde", @@ -787,9 +805,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.7.1" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" +checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" [[package]] name = "httpdate" @@ -799,9 +817,9 @@ checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" [[package]] name = "hyper" -version = "0.14.12" +version = "0.14.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13f67199e765030fa08fe0bd581af683f0d5bc04ea09c2b1102012c5fb90e7fd" +checksum = "07d6baa1b441335f3ce5098ac421fb6547c46dda735ca1bc6d0153c838f9dd83" dependencies = [ "bytes 1.0.1", "futures-channel", @@ -847,9 +865,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.8.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", "hashbrown", @@ -895,6 +913,12 @@ dependencies = [ "serde", ] +[[package]] +name = "io-lifetimes" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ea37f355c05dde75b84bba2d767906ad522e97cd9e2eef2be7a4ab7fb442c06" + [[package]] name = "iovec" version = "0.1.4" @@ -952,9 +976,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.112" +version = "0.2.132" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" + +[[package]] +name = "linux-raw-sys" +version = "0.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" +checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" [[package]] name = "lock_api" @@ -1013,9 +1043,9 @@ dependencies = [ [[package]] name = "lsp-types" -version = "0.93.0" +version = "0.93.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70c74e2173b2b31f8655d33724b4b45ac13f439386f66290f539c22b144c2212" +checksum = "a3bcfee315dde785ba887edb540b08765fd7df75a7d948844be6bf5712246734" dependencies = [ "bitflags", "serde", @@ -1038,9 +1068,9 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "md-5" -version = "0.10.1" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658646b21e0b72f7866c7038ab086d3d5e1cd6271f060fd37defb241949d0582" +checksum = "66b48670c893079d3c2ed79114e3644b7004df1c361a4e0ad52e2e6940d07c3d" dependencies = [ "digest", ] @@ -1131,9 +1161,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.13.1" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" dependencies = [ "hermit-abi", "libc", @@ -1141,9 +1171,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" [[package]] name = "openssl" @@ -1314,23 +1344,11 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - -[[package]] -name = "proc-macro-nested" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" - [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" dependencies = [ "unicode-ident", ] @@ -1386,9 +1404,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.5.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" +checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" dependencies = [ "autocfg", "crossbeam-deque", @@ -1398,9 +1416,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.9.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" +checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" dependencies = [ "crossbeam-channel", "crossbeam-deque", @@ -1488,7 +1506,7 @@ dependencies = [ "extract-graphql", "fixture-tests", "fnv", - "futures 0.3.13", + "futures 0.3.24", "glob", "graphql-cli", "graphql-ir", @@ -1689,6 +1707,20 @@ dependencies = [ "schema", ] +[[package]] +name = "rustix" +version = "0.35.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c825b8aa8010eb9ee99b75f05e10180b9278d161583034d7574c9d617aeada" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.5" @@ -1895,9 +1927,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.2" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if", "cpufeatures", @@ -2008,9 +2040,9 @@ checksum = "45f6ee7c7b87caf59549e9fe45d6a69c75c8019e79e212a835c5da0e92f0ba08" [[package]] name = "syn" -version = "1.0.96" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" +checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e" dependencies = [ "proc-macro2", "quote", @@ -2042,19 +2074,19 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.1.17" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" +checksum = "8440c860cf79def6164e4a0a983bcc2305d82419177a0e0c71930d049e3ac5a1" dependencies = [ - "libc", - "winapi", + "rustix", + "windows-sys", ] [[package]] name = "textwrap" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" dependencies = [ "terminal_size", "unicode-width", @@ -2220,9 +2252,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.0" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "unicode-normalization" @@ -2321,7 +2353,7 @@ checksum = "839fea2d85719bb69089290d7970bba2131f544448db8f990ea75813c30775ca" dependencies = [ "anyhow", "bytes 1.0.1", - "futures 0.3.13", + "futures 0.3.24", "maplit", "serde", "serde_bser", @@ -2362,6 +2394,49 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + [[package]] name = "zstd" version = "0.11.1+zstd.1.5.2" diff --git a/compiler/crates/relay-codegen/src/ast.rs b/compiler/crates/relay-codegen/src/ast.rs index f18c65acdf503..e8e38ac9ef121 100644 --- a/compiler/crates/relay-codegen/src/ast.rs +++ b/compiler/crates/relay-codegen/src/ast.rs @@ -138,15 +138,20 @@ pub enum QueryID { External(StringKey), } -pub struct RequestParameters<'a> { - pub id: &'a Option, +pub enum RequestFormat { + ID(QueryID), + Text(Option), + Migration(QueryID, Option), +} + +pub struct RequestParameters { pub name: StringKey, pub operation_kind: OperationKind, - pub text: Option, + pub request_format: Option, } -impl<'a> RequestParameters<'a> { +impl RequestParameters { pub fn is_client_request(&self) -> bool { - self.id.is_none() && self.text.is_none() + return self.request_format.is_none(); } } diff --git a/compiler/crates/relay-codegen/src/build_ast.rs b/compiler/crates/relay-codegen/src/build_ast.rs index b21568ddecb8b..ba606979353b4 100644 --- a/compiler/crates/relay-codegen/src/build_ast.rs +++ b/compiler/crates/relay-codegen/src/build_ast.rs @@ -68,6 +68,7 @@ use crate::ast::AstKey; use crate::ast::ObjectEntry; use crate::ast::Primitive; use crate::ast::QueryID; +use crate::ast::RequestFormat; use crate::ast::RequestParameters; use crate::constants::CODEGEN_CONSTANTS; use crate::object; @@ -75,7 +76,7 @@ use crate::top_level_statements::TopLevelStatements; pub fn build_request_params_ast_key( schema: &SDLSchema, - request_parameters: RequestParameters<'_>, + request_parameters: RequestParameters, ast_builder: &mut AstBuilder, operation: &OperationDefinition, top_level_statements: &TopLevelStatements, @@ -144,12 +145,11 @@ pub fn build_request( })) } -pub fn build_request_params(operation: &OperationDefinition) -> RequestParameters<'_> { +pub fn build_request_params(operation: &OperationDefinition) -> RequestParameters { RequestParameters { name: operation.name.item.0, operation_kind: operation.kind, - id: &None, - text: None, + request_format: None, } } @@ -1649,7 +1649,7 @@ impl<'schema, 'builder, 'config> CodegenBuilder<'schema, 'builder, 'config> { fn build_request_parameters( &mut self, operation: &OperationDefinition, - request_parameters: RequestParameters<'_>, + request_parameters: RequestParameters, top_level_statements: &TopLevelStatements, ) -> AstKey { let mut metadata_items: Vec = operation @@ -1704,58 +1704,60 @@ impl<'schema, 'builder, 'config> CodegenBuilder<'schema, 'builder, 'config> { }), }; - let id_prop = ObjectEntry { - key: CODEGEN_CONSTANTS.id, - value: match request_parameters.id { - Some(QueryID::Persisted { id, .. }) => Primitive::RawString(id.clone()), - Some(QueryID::External(name)) => Primitive::JSModuleDependency(*name), - None => Primitive::Null, - }, - }; - - let mut params_object = if let Some(text) = request_parameters.text { - vec![ - ObjectEntry { - key: CODEGEN_CONSTANTS.cache_id, - value: Primitive::RawString(md5(&text)), - }, - id_prop, - metadata_prop, - name_prop, - operation_kind_prop, - ObjectEntry { - key: CODEGEN_CONSTANTS.text, - value: Primitive::RawString(text), + let id_prop = if let Some(RequestFormat::ID(ref id) | RequestFormat::Migration(ref id, _)) = + request_parameters.request_format + { + match id { + QueryID::Persisted { id, .. } => ObjectEntry { + key: CODEGEN_CONSTANTS.id, + value: Primitive::RawString(id.clone()), }, - ] - } else if request_parameters.id.is_some() { - vec![ - id_prop, - metadata_prop, - name_prop, - operation_kind_prop, - ObjectEntry { - key: CODEGEN_CONSTANTS.text, - value: Primitive::Null, + QueryID::External(name) => ObjectEntry { + key: CODEGEN_CONSTANTS.id, + value: Primitive::JSModuleDependency(*name), }, - ] + } } else { - vec![ - ObjectEntry { - key: CODEGEN_CONSTANTS.cache_id, - value: Primitive::RawString(md5(operation.name.item.0.lookup())), - }, - id_prop, - metadata_prop, - name_prop, - operation_kind_prop, - ObjectEntry { - key: CODEGEN_CONSTANTS.text, - value: Primitive::Null, - }, - ] + ObjectEntry { + key: CODEGEN_CONSTANTS.id, + value: Primitive::Null, + } }; + let mut params_object = vec![]; + + match request_parameters.request_format { + Some( + RequestFormat::Text(Some(ref text)) | RequestFormat::Migration(_, Some(ref text)), + ) => params_object.push(ObjectEntry { + key: CODEGEN_CONSTANTS.cache_id, + value: Primitive::RawString(md5(&text.clone())), + }), + None => params_object.push(ObjectEntry { + key: CODEGEN_CONSTANTS.cache_id, + value: Primitive::RawString(md5(operation.name.item.0.lookup())), + }), + _ => (), + } + + params_object.push(id_prop); + params_object.push(metadata_prop); + params_object.push(name_prop); + params_object.push(operation_kind_prop); + + match request_parameters.request_format { + Some( + RequestFormat::Text(Some(ref text)) | RequestFormat::Migration(_, Some(ref text)), + ) => params_object.push(ObjectEntry { + key: CODEGEN_CONSTANTS.text, + value: Primitive::RawString(text.to_string()), + }), + _ => params_object.push(ObjectEntry { + key: CODEGEN_CONSTANTS.text, + value: Primitive::Null, + }), + } + let provided_variables = if top_level_statements .contains(CODEGEN_CONSTANTS.provided_variables_definition.lookup()) { diff --git a/compiler/crates/relay-codegen/src/lib.rs b/compiler/crates/relay-codegen/src/lib.rs index ebf9c4ebfc487..7b6effee333f9 100644 --- a/compiler/crates/relay-codegen/src/lib.rs +++ b/compiler/crates/relay-codegen/src/lib.rs @@ -20,6 +20,7 @@ mod utils; pub use ast::AstBuilder; pub use ast::Primitive; pub use ast::QueryID; +pub use ast::RequestFormat; pub use ast::RequestParameters; pub use build_ast::build_request_params; pub use build_ast::is_static_storage_key_available; diff --git a/compiler/crates/relay-codegen/src/printer.rs b/compiler/crates/relay-codegen/src/printer.rs index e767290c20424..5e83e62421203 100644 --- a/compiler/crates/relay-codegen/src/printer.rs +++ b/compiler/crates/relay-codegen/src/printer.rs @@ -28,6 +28,7 @@ use crate::ast::AstKey; use crate::ast::ObjectEntry; use crate::ast::Primitive; use crate::ast::QueryID; +use crate::ast::RequestFormat; use crate::ast::RequestParameters; use crate::build_ast::build_fragment; use crate::build_ast::build_operation; @@ -67,7 +68,7 @@ pub fn print_request( schema: &SDLSchema, operation: &OperationDefinition, fragment: &FragmentDefinition, - request_parameters: RequestParameters<'_>, + request_parameters: RequestParameters, project_config: &ProjectConfig, top_level_statements: &mut TopLevelStatements, ) -> String { @@ -88,7 +89,11 @@ pub fn print_request_params( top_level_statements: &mut TopLevelStatements, ) -> String { let mut request_parameters = build_request_params(operation); - request_parameters.id = query_id; + request_parameters.request_format = if let Some(query_id) = &query_id { + Some(RequestFormat::ID(query_id.clone())) + } else { + None + }; let mut builder = AstBuilder::default(); let request_parameters_ast_key = build_request_params_ast_key( @@ -176,7 +181,7 @@ impl<'p> Printer<'p> { schema: &SDLSchema, operation: &OperationDefinition, fragment: &FragmentDefinition, - request_parameters: RequestParameters<'_>, + request_parameters: RequestParameters, top_level_statements: &mut TopLevelStatements, ) -> String { let request_parameters = build_request_params_ast_key( @@ -239,7 +244,7 @@ impl<'p> Printer<'p> { pub fn print_request_params( &mut self, schema: &SDLSchema, - request_parameters: RequestParameters<'_>, + request_parameters: RequestParameters, operation: &OperationDefinition, top_level_statements: &mut TopLevelStatements, ) -> String { diff --git a/compiler/crates/relay-compiler/src/artifact_content/content.rs b/compiler/crates/relay-compiler/src/artifact_content/content.rs index b3557ce29f92f..c38ee8034fe0e 100644 --- a/compiler/crates/relay-compiler/src/artifact_content/content.rs +++ b/compiler/crates/relay-compiler/src/artifact_content/content.rs @@ -17,8 +17,10 @@ use graphql_ir::OperationDefinition; use relay_codegen::build_request_params; use relay_codegen::Printer; use relay_codegen::QueryID; +use relay_codegen::RequestFormat; use relay_codegen::TopLevelStatement; use relay_codegen::CODEGEN_CONSTANTS; +use relay_config::PersistConfig; use relay_transforms::is_operation_preloadable; use relay_transforms::ReactFlightLocalComponentsMetadata; use relay_transforms::RelayClientComponentMetadata; @@ -177,11 +179,25 @@ pub fn generate_operation( fragment_locations: &FragmentLocations, ) -> Result, FmtError> { let mut request_parameters = build_request_params(normalization_operation); - if id_and_text_hash.is_some() { - request_parameters.id = id_and_text_hash; + + request_parameters.request_format = if let Some(id_and_text_hash) = id_and_text_hash { + let safe_migration = match &project_config.persist { + Some(PersistConfig::Remote(config)) => config.safe_migration, + Some(PersistConfig::Local(config)) => config.safe_migration, + None => false, + }; + if safe_migration { + Some(RequestFormat::Migration( + id_and_text_hash.clone(), + text.to_owned(), + )) + } else { + Some(RequestFormat::ID(id_and_text_hash.clone())) + } } else { - request_parameters.text = text.clone(); + Some(RequestFormat::Text(text.to_owned())) }; + let operation_fragment = FragmentDefinition { name: reader_operation.name.map(|x| FragmentDefinitionName(x.0)), variable_definitions: reader_operation.variable_definitions.clone(), @@ -219,9 +235,14 @@ pub fn generate_operation( // -- Begin Metadata Annotations Section -- let mut section = CommentAnnotationsSection::default(); - if let Some(QueryID::Persisted { id, .. }) = &request_parameters.id { + if let Some( + RequestFormat::ID(QueryID::Persisted { id, .. }) + | RequestFormat::Migration(QueryID::Persisted { id, .. }, _), + ) = &request_parameters.request_format + { writeln!(section, "@relayRequestID {}", id)?; } + if project_config.variable_names_comment { write!(section, "@relayVariables")?; for variable_definition in &normalization_operation.variable_definitions { diff --git a/compiler/crates/relay-config/src/project_config.rs b/compiler/crates/relay-config/src/project_config.rs index 42427b62b5338..a3969d05a6ceb 100644 --- a/compiler/crates/relay-config/src/project_config.rs +++ b/compiler/crates/relay-config/src/project_config.rs @@ -41,7 +41,7 @@ type FnvIndexMap = IndexMap; pub type ProjectName = StringKey; #[derive(Clone, Debug, Serialize, Deserialize)] -#[serde(deny_unknown_fields)] +#[serde(deny_unknown_fields, rename_all = "camelCase")] pub struct RemotePersistConfig { /// URL to send a POST request to to persist. pub url: String, @@ -56,6 +56,9 @@ pub struct RemotePersistConfig { deserialize_with = "deserialize_semaphore_permits" )] pub semaphore_permits: Option, + + #[serde(default)] + pub safe_migration: bool, } fn deserialize_semaphore_permits<'de, D>(d: D) -> Result, D::Error> @@ -92,6 +95,9 @@ pub struct LocalPersistConfig { #[serde(default)] pub algorithm: LocalPersistAlgorithm, + + #[serde(default)] + pub safe_migration: bool, } #[derive(Debug, Serialize, Clone)] diff --git a/packages/relay-runtime/util/RelayConcreteNode.js b/packages/relay-runtime/util/RelayConcreteNode.js index 97e25f8edb1d7..d71d761aaf0c1 100644 --- a/packages/relay-runtime/util/RelayConcreteNode.js +++ b/packages/relay-runtime/util/RelayConcreteNode.js @@ -43,30 +43,20 @@ export type ProvidedVariablesType = {+[key: string]: {get(): mixed}}; /** * Contains the parameters required for executing a GraphQL request. - * The operation can either be provided as a persisted `id` or `text`. If given - * in `text` format, a `cacheID` as a hash of the text should be set to be used - * for local caching. + * The operation can either be provided as a persisted `id` or `text` or both. + * If `text` format is provided, a `cacheID` as a hash of the text should be set + * to be used for local caching. */ -export type RequestParameters = - | { - +id: string, - +text: null, - // common fields - +name: string, - +operationKind: 'mutation' | 'query' | 'subscription', - +providedVariables?: ProvidedVariablesType, - +metadata: {[key: string]: mixed, ...}, - } - | { - +cacheID: string, - +id: null, - +text: string | null, - // common fields - +name: string, - +operationKind: 'mutation' | 'query' | 'subscription', - +providedVariables?: ProvidedVariablesType, - +metadata: {[key: string]: mixed, ...}, - }; +export type RequestParameters = { + +cacheID?: string, + +id: string | null, + +text: string | null, + // common fields + +name: string, + +operationKind: 'mutation' | 'query' | 'subscription', + +providedVariables?: ProvidedVariablesType, + +metadata: {[key: string]: mixed, ...}, +}; export type ClientRequestParameters = { +cacheID: string,