hasura-tests
БесплатноБез исполняемых скриптовНе проверенUse when a Hasura GraphQL Engine needs tests, especially role-based row permissions: a docker-compose test instance, metadata API setup, x-hasura-role and…
от testland★ 18 звёзд на GitHubОб этом скилле
hasura-tests
Overview
Per hasura.io/docs/2.0/auth/authorization/quickstart/, Hasura permissions are configured per table, role, and operation (select / insert / update / delete), with row- filter expressions and column-level scopes.
The testable concerns are different from Apollo / Yoga:
- Permission rules are declarative; tests verify the rule produces the expected filter SQL.
- Roles + session variables drive everything; tests inject
x-hasura-role+ custom claims and assert the response shape. - Metadata is the source of truth; tests apply a fixture metadata then run queries.
When to use
- Testing a Hasura-backed API where row-level isolation is the
primary concern (composes with
cross-tenant-data-leak-testsin the qa-multi-tenancy plugin). - Verifying a new role's permission rules.
- PR review of
hasura/metadata/changes. - Regression-testing role transitions (user becomes admin, etc.).
How to use
- Bring up the ephemeral test stack (
docker compose -f docker-compose.test.yml up -d) with introspection disabled and the console off. - Apply the fixture metadata that declares the permission rules under test, via the
/v1/metadataAPI orhasura metadata apply. - Seed per-test rows so no test depends on another test's data.
- Send queries to
/v1/graphqlwith the admin secret plus anx-hasura-roleoverride (andx-hasura-user-id/ custom claims) to act as any role. - Assert the response shape: rows are row-filtered to the role, or the failure
carries
extensions.code = "permission-error"(oraffected_rows: 0). - Cover the full role x table x operation matrix from a checked-in fixture, and add one smoke test through the real JWT path.
- Tear the stack down with
-vand reset metadata between suites.
Authoring
Test instance setup
# docker-compose.test.yml
services:
postgres:
image: postgres:16
environment:
POSTGRES_PASSWORD: ${PG_PASSWORD:?set PG_PASSWORD}
hasura:
image: hasura/graphql-engine:v2.42.0
ports: ["8080:8080"]
depends_on: [postgres]
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:${PG_PASSWORD}@postgres:5432/postgres
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET:?set HASURA_GRAPHQL_ADMIN_SECRET}
HASURA_GRAPHQL_DISABLE_INTROSPECTION_PUBLIC_API: "true" # per graphql-complexity-limit-tester references/introspection.md
HASURA_GRAPHQL_ENABLE_CONSOLE: "false"
docker compose -f docker-compose.test.yml up -d
Never write the admin secret or DB password into the compose file or a
test. Per Compose interpolation, ${VAR} is read from the
shell or a git-ignored .env, and ${VAR:?error} stops Compose when it is
unset. Every command and test below reads HASURA_GRAPHQL_ADMIN_SECRET from
the environment.
Apply metadata for test
Per Hasura docs, the metadata API at /v1/metadata:
curl -X POST http://localhost:8080/v1/metadata \
-H "x-hasura-admin-secret: $HASURA_GRAPHQL_ADMIN_SECRET" \
-H "Content-Type: application/json" \
-d @hasura/metadata-fixture.json
metadata-fixture.json contains the declarative permission
rules being tested.
Or via hasura CLI:
hasura migrate apply --endpoint http://localhost:8080 --admin-secret "$HASURA_GRAPHQL_ADMIN_SECRET"
hasura metadata apply --endpoint http://localhost:8080 --admin-secret "$HASURA_GRAPHQL_ADMIN_SECRET"
Role-based permission tests
Tests act as any role via admin secret + x-hasura-role override, and a full
per-role x per-table x per-operation audit is generated from a checked-in fixture.
Both patterns - the httpx by-role queries and the parametrized matrix - are in
references/permission-matrix-tests.md.
Worked example
Scenario: a new user role must see only its own rows in the user table.
- In the fixture metadata, give
usera select permission onuserfiltered byid = X-Hasura-User-Id; apply it withhasura metadata apply. - POST
{ user { id name } }to/v1/graphqlwith headersx-hasura-admin-secret,x-hasura-role: user,x-hasura-user-id: 3. - Assert
status_code == 200and every returned row hasid == 3- the row filter held. - POST the same query with
x-hasura-role: admin(no user-id) and assertlen(rows) > 1- admin is not restricted.
Result: one pair of requests proves the row-filter rule for the restricted role and confirms it does not leak into the admin role.
Running
docker compose -f docker-compose.test.yml up -d
hasura metadata apply --endpoint http://localhost:8080 --admin-secret "$HASURA_GRAPHQL_ADMIN_SECRET"
pytest tests/hasura/
docker compose -f docker-compose.test.yml down -v
Parsing results
H
Установить hasura-tests в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл hasura-tests?
Use when a Hasura GraphQL Engine needs tests, especially role-based row permissions: a docker-compose test instance, metadata API setup, x-hasura-role and x-hasura-user-id headers, and a role by table by operation permission matrix against the v1/graphql endpoint.
Как установить скилл hasura-tests?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл hasura-tests запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic