← All posts

What to inspect when GraphQL sits over your dataset

A new GraphQL layer over data looks simple, but the hard parts sit in schema exposure, query cost, access control, and observability. Here is what to inspect first if you run GraphQL over live datasets for apps, internal tooling, or LLM retrieval.

Simon Willison notes the datasette-graphql 3.1a0 release. The source fact is small, but the topic behind it matters to anyone who ships AI or data systems. GraphQL over a live dataset changes how data gets exposed, queried, cached, and abused. If you build internal tooling, retrieval layers for LLMs, or customer-facing APIs, those choices show up fast in performance and security work.

A GraphQL layer on top of tabular data looks clean at first. One endpoint. Flexible queries. Fast iteration. The trade-off sits in query planning, authorization boundaries, and shape control. If your backend is SQLite, Postgres, or a federated data service, the same rule applies. Flexibility at the edge creates pressure in the middle.

For practitioners, the key question is simple. When you add GraphQL over a dataset, what do you inspect first so the API stays useful under load and predictable under attack. The answer starts with schema design, then moves through cost control, row-level access, and observability.

Treat the schema as an attack surface

GraphQL schemas often start from convenience. Tables become types. Foreign keys become relations. Filtering and ordering appear across most fields. This speeds delivery. It also exposes more structure than many teams expect.

Start with three checks.

  • Count how many object types and relations the schema exposes.
  • List fields with high-cardinality fan-out, such as logs, events, comments, or transactions.
  • Identify introspection exposure in each environment.

Why this matters:

  • Deep relation chains amplify query cost.
  • Broad filter support exposes data distribution patterns.
  • Introspection reduces guesswork for anyone probing the API.

A common failure mode is auto-generated schemas with no pruning. You expose internal tables, join tables, audit fields, and historical records because the generator found them. The result is a schema with weak boundaries.

A better pattern is to publish a smaller read model. Keep naming explicit. Hide fields you do not want clients to depend on. Flatten relations where you already know the common access path. If one table has ten columns but clients need three, expose three.

For AI systems, this matters twice. LLM agents tend to over-query when given flexible tools. If your GraphQL schema exposes many similar fields and relations, the model will often issue bloated queries, retry with variations, and increase backend load.

Set query cost limits before users find the expensive paths

GraphQL performance problems rarely come from one large response alone. They come from shape. Nested lists, repeated fragments, wide selection sets, and high-limit pagination requests create expensive execution plans.

You need a cost model, even a simple one.

Inspect these controls:

  • Maximum query depth.
  • Maximum number of nodes returned.
  • Per-field cost weights for expensive resolvers.
  • Pagination caps on list fields.
  • Timeouts at the GraphQL layer and the database layer.

For data-backed GraphQL, N+1 query patterns still matter. Even with a local database, repeated resolver calls stack up. With remote services behind resolvers, the problem gets worse.

A practical baseline looks like this:

  • Depth limit of 5 to 8 for general clients.
  • Hard cap on page size, often 50 to 200 depending on row width.
  • Separate budget for aggregate fields.
  • Rate limits tied to authenticated identity, not only IP.

Where teams go wrong:

  • They rate-limit requests but not complexity.
  • They cap response size but not resolver work.
  • They allow unbounded filtering or sorting on unindexed columns.
  • They forget aliases let one request repeat expensive fields many times.

If your GraphQL layer sits over SQLite, inspect query plans for common resolver paths. Look for full table scans triggered by flexible filters. Look for sorts without supporting indexes. Look for count queries on large tables. A single elegant GraphQL query often turns into several clumsy SQL queries under the hood.

For LLM-backed applications, put a stricter policy on machine-issued queries than on hand-written developer queries. Agents do not need broad freedom. They need narrow, stable operations with predictable cost.

Enforce row-level rules close to the data

Authorization bugs in GraphQL often come from field-level checks without data-level policy. A resolver verifies the caller for one path, but another path reaches the same records through a different relation. The schema stays consistent. The access control does not.

Inspect authorization in this order:

  1. What identity reaches the GraphQL server.
  2. How tenant or user scope gets attached to a request.
  3. Where row filtering happens.
  4. Which fields carry sensitive values.
  5. Whether aggregate queries leak cross-tenant information.

The strong pattern is policy near the data. In SQL systems, this means views, row-level security, scoped query builders, or prepared access layers keyed by tenant and role. Resolver-local checks help, but they are weak as the only control.

Signals to read:

  • The same table appears in many resolvers with duplicated auth logic.
  • Admin and non-admin paths share helper functions with optional filters.
  • Aggregate fields return counts across rows the caller should never see.
  • Search fields leak existence through timing or error differences.

One common mistake is to hide sensitive columns but still expose relations which reveal the same fact indirectly. Another is to allow sorting or filtering on fields which expose private state, such as moderation flags, internal risk scores, or soft-delete markers.

In AI workflows, retrieval tools often run under a service account. That makes mistakes worse. If the service account has broad read access and the GraphQL tool is handed to an agent, your effective least-privilege story is gone. Build purpose-scoped API identities for each workflow.

Watch introspection, persisted queries, and caching together

Teams often treat these as separate features. They are linked.

Introspection helps developers and toolchains. Persisted queries constrain what production clients send. Caching reduces repeated backend work. Together, they shape how much freedom your clients have and how much certainty your infrastructure gets.

A strong production setup often includes:

  • Introspection disabled for public production clients, or gated by role.
  • Persisted queries for web and mobile applications.
  • Cache keys tied to operation name, variables, and auth scope.
  • Separate TTL policy for aggregates and entity reads.

Where this goes wrong:

  • You disable introspection but still allow arbitrary ad hoc queries.
  • You cache authenticated responses without enough variance keys.
  • You adopt persisted queries but leave a bypass route for arbitrary POST bodies.
  • You forget schema changes invalidate old assumptions in edge caches.

For GraphQL backed by mutable datasets, stale reads are often tolerated until they touch AI outputs. Then a caching bug turns into a reasoning bug. The model repeats old state with confidence because the retrieval layer served old results. If the data drives support answers, ops dashboards, or compliance review, treat cache invalidation as a correctness issue, not only a speed issue.

If you expose GraphQL through a public domain, Website Legit Check or SSL/TLS Certificate Checker help you inspect baseline web hygiene around the endpoint, but the harder work is still in API policy and resolver design.

Instrument the resolver path, not only the HTTP request

Many teams have good HTTP metrics and weak GraphQL metrics. They know request rate, p95 latency, and error count. They do not know which fields drive cost, which clients issue pathological shapes, or which resolvers trigger database scans.

Add visibility at four levels:

  • Operation name and client identity.
  • Query depth, node count, and estimated cost.
  • Resolver timing by field path.
  • Database query count and slow-query traces per request.

This gives you a usable loop:

  1. Find expensive operations.
  2. Map cost back to fields and relations.
  3. Add indexes, batching, or schema limits.
  4. Re-measure.

Common blind spots include unnamed operations, sampled logs with no variables, and metrics that flatten all GraphQL traffic into one endpoint label. If every request lands on /graphql, endpoint-level dashboards tell you little.

For Go services, keep the instrumentation simple. Wrap resolvers with timing middleware. Thread request scope through context.Context. Emit structured logs with operation name, tenant, depth, and database timings. Add cancellation support so slow upstream calls stop when the client disconnects. If you use goroutines inside resolvers, tie them to the request context and set clear budgets.

The main goal is predictability. You want to know which query shapes your system supports well, which ones degrade, and which ones need to be blocked.

What to watch next

Watch how data-serving tools balance convenience against control. Auto-generated APIs save time early. Later, the pressure shifts to cost limits, access policy, and observability. If you are adding GraphQL to a dataset for dashboards, internal search, or LLM retrieval, inspect the schema and query budget first. Those two choices shape most of the trouble you will debug later.