Why?
GraphQL + Rust + Web Assembly Edge Runtime = world-class api substrate
What makes this so hard?
- Practically zero real-world examples.
- WebSocket connections in Wasm environments require special handling since traditional TCP/WebSocket servers cannot be directly instantiated.
- Many Rust async ecosystem dependencies (like tokio, mio) assume native platform capabilities that aren't available in wasm32-unknown-unknown target.
- GraphQL subscriptions traditionally rely on long-lived connections and event streaming, which need to be carefully adapted for edge computing environments.
- Cloned a set of examples and confirmed the subscription example was operational prior to modification.
- Added worker dependencies to the subscription example.
- Added a fetch handler to replace TCPListener
- Forked async-graphql dependency and removed platform gates on subscriptions.
- Created mio patched. All transitive usage of mio is patched with a dummy mio as a crate in the workspace.
- Update all getrandom resolutions to include the 'wasm_js' feature
- Added RUST_FLAGS to the build command.
- Validate features
- You may be better off writing an extractor for websockets. If this approach is taken, try yanking sources and refactor logic which relies on tokio features incompatible with wasm32.