Skip to content

Fail One GraphQL Operation

GraphQL clients often send every operation to /graphql. Use graphqlOperation to fail one operation without breaking unrelated queries on the same URL.

await injectChaos(page, {
seed: 42,
network: {
failures: [{
urlPattern: '/graphql',
graphqlOperation: 'GetUser',
statusCode: 503,
probability: 1,
}],
},
});
await page.goto('/profile');
await expect(page.locator('[data-testid="profile-error"]')).toBeVisible();
await page.getByRole('button', { name: 'Search products' }).click();
await expect(page.locator('[data-testid="products"]')).toBeVisible();

graphqlOperation is an additional matcher. urlPattern and methods still apply, so a rule can target only POST GetUser or only persisted-query GET GetUser when needed.

If a rule with graphqlOperation seems inactive, check the chaos log for a reason: 'graphql-body-unparseable' diagnostic. Multipart, streaming, and XHR Blob bodies cannot be inspected for an operation name and emit this event with applied: false instead of matching.