Skip to main content
The Mex feature wraps WhatsApp’s Meta Exchange (MEX) GraphQL API. Operations are persisted: you reference each query or mutation by a (name, id) pair pulled from a generated operation module, and pass its typed Variables. WhatsApp Web bundle updates rotate the numeric id, so the human-readable name keeps diagnostics stable across releases.

Access

Building a request

Each persisted operation lives in its own module under wacore::iq::mex_operations. Every module exposes:
  • NAME — the operation name (e.g. "WAWebJoinNewsletterMutation").
  • DOC_ID — the current persisted document ID.
  • OPERATION_KIND"query" or "mutation".
  • Variables — a typed struct matching the operation’s input shape.
  • Response — a typed struct matching the operation’s output shape.
Construct a MexRequest with MexRequest::new using those constants and a Variables value:
For operations whose Variables schema is too permissive to model exactly, pass any serde::Serialize value (for example a serde_json::json!({...})) as the variables — query and mutate are generic over V: Serialize.

Methods

query

Execute a GraphQL query.

mutate

Execute a GraphQL mutation.
Example — mutation with typed variables:
Example — loosely-typed variables with serde_json:

Types

MexDoc

A persisted-query descriptor. Re-exported from wacore::iq::mex.

MexRequest

A persisted-query descriptor plus its typed variables. V is the variables type — usually the generated Variables struct for an operation, but any Serialize value works.

new

Pair an operation’s NAME and DOC_ID with its variables.

MexResponse

Response from a GraphQL operation.
Methods:
  • has_data()true if the response contains data.
  • has_errors()true if the response contains errors.
  • fatal_error() — the first fatal error (any error with an error_code), if any.

MexGraphQLError

Methods:
  • error_code() — the numeric error code, if present.
  • is_summary()true when the error is marked as a summary.
  • has_error_code()true when an error code is set.
MexGraphQLError is re-exported from the crate root as whatsapp_rust::MexGraphQLError, alongside MexError, MexErrorExtensions, MexRequest, and MexResponse.

MexErrorExtensions

Error handling

query and mutate automatically convert any fatal GraphQL error (any error with an error_code) into MexError::ExtensionError so you can match on it without inspecting response.errors yourself.

Response handling

Check for data

Handle non-fatal errors

Errors without an error_code are non-fatal and surface in response.errors alongside any partial data.

Decode the typed response

Generated operation modules also expose a Response struct that mirrors the GraphQL schema. Decode it from response.data with serde_json:
The persisted DOC_ID for each operation is regenerated from the latest WhatsApp Web bundle. Pin to a specific crate version if you need a stable wire format.