Feature by feature
Chapter 4 of 11
Rules, queries and files
Access policies live on your schema types rather than inside route handlers. Saved EdgeQL files turn your schema into named endpoints, direct file uploads and typed client SDKs.
Every object type in a freshly pushed schema starts closed over the API. Until an access policy grants permission, queries return zero rows and writes fail, even when a caller sends an unfiltered query.
Try it
Sign up as Ada in the starter app and save a note. Then sign in as Ben in a second browser window and query every Note.
select Note { title }Policies on the type#
Pillar at work: Caller-bound
An access policy lives inside an object type and declares which operations (select, insert, update, delete or all) are allowed when its using expression evaluates to true. Written in EdgeQL, policies can read properties, traverse links and check global caller.
global caller := global ext::auth::ClientTokenIdentity; type Note { required owner: ext::auth::Identity; required title: str; required body: str; access policy owner_has_full_access allow all using (.owner ?= global caller);} type Attachment extending ext::files::File { required owner: ext::auth::Identity; access policy owner_has_full_access allow all using (.owner ?= global caller);}Types without a matching policy stay closed, returning zero records on reads and refusing writes. Napalm verifies the bearer token before binding global caller, so no request can spoof another user’s identity.
Policies in every query
Matching policies compile into the SQL statement while closed types return nothing.
Statement-level enforcement#
Pillar at work: Checked and fault-tested
Napalm compiles matching policies straight into the single SQL statement PostgreSQL runs. Reads skip unpermitted rows, and insert or update statements validate the resulting row before committing, so Ben cannot insert a note naming Ada as .owner.
Service keys and agents pass through the same check. A backend service key belongs to no user, so global caller is empty and workers see zero rows unless you add a policy checking service globals. An OAuth session approved by Ada binds global caller to Ada and restricts the client to her permitted rows.
When debugging permissions, run napalm people reach to count reachable rows per type or napalm explain-access to inspect every policy clause on a specific object ID without exposing field values.
Saved queries and typed clients#
Pillar at work: Compiled
In production, you store application reads and writes as .edgeql files in dbschema/queries/. Because ownership is already enforced on Note, myNotes.edgeql needs no manual owner filter.
select Note { id, title, body }order by .titleSaved queries traverse nested links, backlinks and aggregates in one SQL statement with no N+1 round trips. Pushing deploys each file as POST /query/{name}. Callers pass typed JSON variables, including optional filter and cursor parameters, while query text remains on the server so user input cannot alter query structure.
curl https://notes.napalmdata.com/query/addNote \ -H "Authorization: Bearer $SESSION" \ -H "Content-Type: application/json" \ -d '{ "variables": { "title": "Printers", "body": "Call the vendor on Monday" } }'addNote over HTTPS with a bearer session and typed JSON variables.Running napalm generate reads those same deployed queries and generates typed client SDKs in eight languages alongside project CLI commands and MCP tools.
napalm schema push notesnpm run generateFiles as typed records#
Pillar at work: One typed graph
Subtyping ext::files::File keeps file metadata and access policies in PostgreSQL while raw bytes live in dedicated object storage. Inserting an Attachment checks the insert policy and returns a one-time upload plan while the record starts in Pending.
select (insert Attachment { owner := global caller, file_name := <str>$name, file_size := <int64>$size,}) { id, file_upload }Uploads go directly from the browser or phone to your cluster’s bucket without streaming through query engines. Once the transfer completes, Napalm inspects the leading file bytes against any file_format constraint before setting file_status to Ready.
Direct storage uploads
Uploads stream straight to object storage and pass a header check before becoming Ready.
Selecting file_download_url signs a short-lived link inside the policy-filtered query, so unauthorized callers never receive a URL. Uploaded objects are immutable, keeping point-in-time restores and data-cloned branches consistent with historical rows.
select Attachment { id, file_name, file_size, file_status, file_download_url }order by .file_nameChecks in CI and production#
Every schema push validates all files in dbschema/queries/ before running DDL. In pull-request CI, napalm schema push --review outputs the migration plan and exits non-zero if a change would break any deployed query.
napalm schema push notes --review > review.mdOnce your client apps use generated functions exclusively, disable ad-hoc EdgeQL execution for user sessions while keeping full query access for backend service keys. Under live traffic, napalm insights notes reports per-query latency, replica read share, policy cost and index recommendations.
napalm endpoint notes --passthrough keysOnce queries and access policies are deployed, keeping screens synchronized across tabs and devices requires zero extra backend code.