Skip to content

Commit 7e5c881

Browse files
authored
Support non-browser WASM (#1147, #1118)
- gate `js-sys` and `wasm-bindgen` behind `js` Cargo feature
1 parent b84621c commit 7e5c881

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ jobs:
125125
- { feature: graphql-parser, crate: juniper }
126126
- { feature: rust_decimal, crate: juniper }
127127
- { feature: schema-language, crate: juniper }
128-
- { feature: serde_json, crate: juniper }
129128
- { feature: time, crate: juniper }
130129
- { feature: url, crate: juniper }
131130
- { feature: uuid, crate: juniper }
@@ -280,8 +279,10 @@ jobs:
280279
fail-fast: false
281280
matrix:
282281
crate:
283-
- juniper_codegen
284282
- juniper
283+
target:
284+
- wasm32-unknown-unknown
285+
- wasm32-wasi
285286
toolchain:
286287
- stable
287288
- beta
@@ -292,9 +293,12 @@ jobs:
292293
- uses: dtolnay/rust-toolchain@v1
293294
with:
294295
toolchain: ${{ matrix.toolchain }}
295-
target: wasm32-unknown-unknown
296+
target: ${{ matrix.target }}
296297

297-
- run: cargo check --target wasm32-unknown-unknown -p ${{ matrix.crate }}
298+
- run: cargo check --target ${{ matrix.target }} -p ${{ matrix.crate }}
299+
${{ matrix.target == 'wasm32-unknown-unknown'
300+
&& '--features js'
301+
|| '' }}
298302

299303

300304

juniper/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
6161
- `#[derive(GraphQLInterface)]` macro allowing using structs as GraphQL interfaces. ([#1026])
6262
- [`bigdecimal` crate] integration behind `bigdecimal` [Cargo feature]. ([#1060])
6363
- [`rust_decimal` crate] integration behind `rust_decimal` [Cargo feature]. ([#1060])
64+
- `js` [Cargo feature] enabling `js-sys` and `wasm-bindgen` support for `wasm32-unknown-unknown` target. ([#1118], [#1147])
6465

6566
### Changed
6667

@@ -112,7 +113,9 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
112113
[#1081]: /../../pull/1081
113114
[#1085]: /../../issues/1085
114115
[#1086]: /../../pull/1086
115-
[#1114]: /../../pull/1119
116+
[#1118]: /../../issues/1118
117+
[#1119]: /../../pull/1119
118+
[#1147]: /../../pull/1147
116119
[ba1ed85b]: /../../commit/ba1ed85b3c3dd77fbae7baf6bc4e693321a94083
117120
[CVE-2022-31173]: /../../security/advisories/GHSA-4rx6-g5vg-5f3j
118121

juniper/Cargo.toml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,19 @@ default = [
3131
"url",
3232
"uuid",
3333
]
34+
bigdecimal = ["dep:bigdecimal"]
35+
bson = ["dep:bson"]
36+
chrono = ["dep:chrono"]
3437
chrono-clock = ["chrono", "chrono/clock"]
3538
chrono-tz = ["dep:chrono-tz", "dep:regex"]
36-
expose-test-schema = ["anyhow", "serde_json"]
39+
expose-test-schema = ["dep:anyhow", "dep:serde_json"]
3740
graphql-parser = ["dep:graphql-parser", "dep:void"]
41+
js = ["chrono?/wasmbind", "time?/wasm-bindgen", "uuid?/js"]
42+
rust_decimal = ["dep:rust_decimal"]
3843
schema-language = ["graphql-parser"]
44+
time = ["dep:time"]
45+
url = ["dep:url"]
46+
uuid = ["dep:uuid"]
3947

4048
[dependencies]
4149
anyhow = { version = "1.0.47", default-features = false, optional = true }
@@ -57,17 +65,14 @@ smartstring = "1.0"
5765
static_assertions = "1.1"
5866
time = { version = "0.3", features = ["formatting", "macros", "parsing"], optional = true }
5967
url = { version = "2.0", optional = true }
60-
uuid = { version = "1.0", default-features = false, optional = true }
68+
uuid = { version = "1.3", default-features = false, optional = true }
6169

6270
# Fixes for MSRV check.
6371
# TODO: Try remove on upgrade of `chrono-tz` crate.
6472
regex = { version = "1.6", default-features = false, optional = true }
65-
# TODO: Remove on upgrade to 4.0.1 version of `graphql-parser`.
73+
# TODO: Remove on upgrade to 0.4.1 version of `graphql-parser`.
6674
void = { version = "1.0.2", optional = true }
6775

68-
[target.'cfg(target_arch = "wasm32")'.dependencies]
69-
getrandom = { version = "0.2", features = ["js"] }
70-
7176
[dev-dependencies]
7277
bencher = "0.1.2"
7378
chrono = { version = "0.4.20", features = ["alloc"], default-features = false }

0 commit comments

Comments
 (0)