GuideHelp
Common scenarios
Copy-ready recipes: GraphQL operations, polling, error and latency testing, CORS, staging redirects.
Six setups that cover most day-to-day debugging. Each one is a single rule unless noted.
1. Mock one GraphQL operation
- Method
POST, match mode Contains, URL/graphql. - Add a GraphQL condition:
operationNameequalsGetCart. - Body: write only the payload —
{ "cart": { "id": "c1", "items": [] } }. Mockrew wraps it as{ "data": … }.
Without the condition every operation on that endpoint would return the cart payload. A GraphQL condition is what keeps the mock scoped to one operation.
2. Walk a polling endpoint through states
- One rule, response mode Sequence, four steps:
pending → paid → shipped → done. - After the last step choose Hold on the last step for a stable end state, or Loop to start over.
- Use Reset count before a demo so the first request starts at step 1.
3. Test error and latency handling
- Clone the existing rule and change the status to
500with an error body — that exercises the error branch without touching the happy path. - For timeouts, set Delay above the client’s timeout (e.g.
30000) on a separate rule that you enable only when needed. - For a flaky endpoint, a Sequence alternating
200and500reproduces intermittent failures deterministically.
4. Unblock a CORS error
- Action Headers, target Response.
- Click Add CORS response headers, then add
Access-Control-Allow-Credentials: trueif the call sends cookies. - Match the API host narrowly (
Containswith the full host) so you do not weaken CORS everywhere.
5. Point the front-end at a staging API
- Action Redirect, mode Replace origin, target
https://api.staging.example.com. - Path and query are kept automatically — no need to touch the code.
- If the staging API is cross-origin, add a Headers rule with the CORS preset.
6. Generate a realistic list
{
"code": 0,
"data": {
"total": 42,
"list|8-12": [
{
"id|+1": 1000,
"name": "{{person.fullName}}",
"avatar": "{{image.avatar}}",
"joined": "{{date.past}}"
}
]
}
}Pair it with a Body condition (page equals 1) to keep pagination honest, and a second rule with a shorter list for page 2.
Stuck, or need something clarified? support@mockrew.com·Terms of Service