agentleFS
getprobogetprobo/probo/.cursor/rules/graphql-resolver-errors.mdc

probo / rules

Cursor rule1.5k starsChanged 20 days agoMITView on GitHub

GraphQL resolvers return gqlx errors, never a plain error

Trending

More talk lately.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 0 mentionsSep 2026: 2 mentionsOct 2026: 0 mentionsNov 2026: 48 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the getprobo/probo repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about getprobo/probo

The biggest 5 of 56 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 56

Talked about on GitHub, Hacker News and Bluesky (56 times).

On GitHub · 50

45 more on GitHub

The file

Files
graphql-resolver-errors.mdc
---
description: GraphQL resolvers return gqlx errors, never a plain error
globs: "pkg/server/api/console/**/*resolver*.go,pkg/server/api/connect/**/*resolver*.go,pkg/server/api/complianceportal/**/*resolver*.go,pkg/server/gqlx/**/*.go"
alwaysApply: false
---

# GraphQL resolver errors

A GraphQL resolver must not return a plain `error`. gqlgen publishes
`fmt.Errorf`, `errors.New`, and `graphql.ErrorOnPath` with no
`extensions.code`. The tracing logger then records the operation as
`UNKNOWN` at error level.

Return a helper from `pkg/server/gqlx`. Do not build `&gqlerror.Error` by
hand. A hand-built error can set `extensions.code`, but it skips the
helpers that set the path and the message.

`r.authorize` already returns a coded error. Return that error unchanged.

## Which code

- The row the field was supposed to load is missing: `gqlx.NotFound`, or
  `gqlx.MapError` when the same call can also fail for another reason.
  `MapError` maps `coredata.ErrResourceNotFound` to `NOT_FOUND` and
  `validator.ValidationErrors` to `INVALID`. Anything else is logged and
  returned as `INTERNAL`.
- The load failed and not-found is already handled: log with
  `r.logger.ErrorCtx` and return `gqlx.Internal(ctx)`. Do not put
  `err.Error()` in the response.
- The client sent a value the server refuses: `gqlx.Invalid` /
  `Invalidf`, `Unauthenticated` / `Unauthenticatedf`, `Forbidden` /
  `Forbiddenf`, `Conflict`, or another named helper in
  `pkg/server/gqlx/errors.go`.
- The schema already models absence as null (no alias, no generated
  document): return `nil, nil`. That is not an error.

A new resolver-owned code needs a helper in `pkg/server/gqlx/errors.go`
and an entry in `safeGraphQLErrorCodes` in `pkg/server/gqlx/tracing.go`.
A gqlgen protocol code such as `GRAPHQL_PARSE_FAILED` or
`COMPLEXITY_LIMIT_EXCEEDED` is not returned by a resolver; it only needs
the allowlist entry. A code missing from that list is logged as `UNKNOWN`
at error level. `INTERNAL` stays at error. Every other allowlisted code
logs at info.

```go
// GOOD — missing row or store failure. MapError sends err.Error() for
// NOT_FOUND. Wrap the sentinel only with client-safe text, or return
// NotFoundf(ctx, "resource not found") when the prefix must stay private.
doc, err := r.probo.Documents.Get(ctx, scope, documentID)
if err != nil {
	return nil, gqlx.MapError(ctx, r.logger, "cannot get document", err)
}

// GOOD — not-found already returned; the rest is internal.
// NotFound shows err.Error() too; use NotFoundf when that text is not client-safe.
owner, err := loaders.Profile.Load(ctx, ownerID)
if errors.Is(err, coredata.ErrResourceNotFound) {
	return nil, gqlx.NotFound(ctx, err)
}
if err != nil {
	r.logger.ErrorCtx(ctx, "cannot get owner", log.Error(err))
	return nil, gqlx.Internal(ctx)
}

// BAD — no code; logged as UNKNOWN and the store error reaches the client
if err != nil {
	return nil, fmt.Errorf("cannot get document: %w", err)
}
```

This does not apply to MCP resolvers. See
[`contrib/claude/graphql.md`](../../contrib/claude/graphql.md) and
[`contrib/claude/api-surface.md`](../../contrib/claude/api-surface.md).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.