GraphQL depth and static complexity score

$0.005 USDC per call · Developer and security · POST /api/v1/graphql-cost · Id graphql-cost

Parses a GraphQL document (query, mutation or subscription) per the June 2018 spec and returns depth, field count, alias count, fragment list, cycle detection and a static complexity score. Complexity uses the common 'Σ field-score × list-multiplier' model: a listFields config maps parent-type + field-name to either a constant multiplier or a field argument name to read (e.g. 'first', 'limit'), with a defaultListMultiplier fallback. Returns fail when depth or complexity exceed configured limits, or the query is syntactically invalid or has a fragment cycle. No schema is required; this is a pre-schema gate for rate limiting.

What you get

A depth-50 nested query from a public token is the oldest GraphQL outage. One middleware call blocks it with the same scoring the big GraphQL proxies use.

Call it

Send the JSON body below to https://agents.writerslogic.com/api/v1/graphql-cost. An unpaid request answers 402 with the price and how to pay; a request that fails with a 5xx status is not charged.

curl -i -X POST https://agents.writerslogic.com/api/v1/graphql-cost \
  -H 'content-type: application/json' \
  -d '{"query":"query Shop { products(first: 20) { edges { node { id title reviews(first: 5) { body } } } } }","listFields":{"Query":{"products":{"multiplier":"first"}},"Product":{"reviews":{"multiplier":"first"}}},"maxDepth":15,"maxComplexity":2000}'

Input

FieldTypeRequiredDescription
querystring; length 0..200000yesThe GraphQL document text.
variablesobjectnoVariable values, used only to resolve list-argument multipliers like first: $first.
listFieldsobjectnoPer-type field multiplier config. See description for shape.
defaultListMultiplierintegernoFallback multiplier for list fields not declared in listFields. Default 10.
operationNamestring; length 0..100noPick this operation; defaults to the first.
maxDepthintegernoFail if depth exceeds this. Default 15.
maxComplexityintegernoFail if complexity exceeds this. Default 1000.

Example request body

{
  "query": "query Shop { products(first: 20) { edges { node { id title reviews(first: 5) { body } } } } }",
  "listFields": {
    "Query": {
      "products": {
        "multiplier": "first"
      }
    },
    "Product": {
      "reviews": {
        "multiplier": "first"
      }
    }
  },
  "maxDepth": 15,
  "maxComplexity": 2000
}

Result

The response is { "data": ..., "_provenance": ... }. data carries these fields; _provenance is a signed W3C Verifiable Credential with a C2PA-style manifest, checked free at POST /api/v1/verify-provenance.

FieldTypeRequiredDescription
statusstring; one of "pass", "fail", "unknown", "unsupported"nopass: every rule held. fail: a rule was violated (see witnesses). unknown: the input lacks the evidence to decide. unsupported: outside what this engine covers. Missing evidence is never a pass.
validbooleanno
operationstringno
operationTypestring; one of "query", "mutation", "subscription"no
depthintegerno
fieldCountintegerno
aliasCountintegerno
complexityintegerno
overLimitbooleanno
fragmentsarray<string>no
witnessesarray<object>no
versionsobjectnoEvery semantic dependency of this answer (engine, tables and their as-of dates, tokenizer, calendar, rounding profile).
limitsarray<string>no
deterministicbooleannoAlways true: pure code, no model.

Pay and connect

Available through: x402 (USDC on Base), MCP. MCP clients reach it through the code-preflight-kit package.

Machine-readable