Skip to main content

Module example

Module example 

Source
Expand description

Draft a ready-to-paste example operation for a matched field.

Everything here is mechanical — the schema already says what the arguments are, what the field returns, and which of that type’s fields are leaves. The rules, and why each one:

  • Arguments you must supply become variables. Never inline a literal into the query body; a pasted operation should be parameterized from the start. An argument the server can fill in for itself — nullable, or with a schema default — is left out of the operation entirely and listed underneath, so the query runs as-is and the knobs are still discoverable.
  • A placeholder names its type. "<ID!>" says both what to put there and that it’s required; "" or 0 look like real values and get pasted by accident.
  • One level of selection by default, leaves only. A scalar or enum return needs no selection set at all. An object return gets its scalar/enum fields, and a # add fields you need marker for the object-valued ones — guessing how deep someone wants to go is worse than leaving a hole, and --depth asks for more when you do want it.
  • Abstract types get inline fragments. A union has no fields of its own, so it’s written as ... on Member { … } over its concrete types — the only form a server will accept.
  • Deprecated fields are flagged, not dropped. They’re still selected and marked # deprecated: reason, because silently omitting a field the schema still serves is its own surprise.
  • An errors block only when the schema has one. The payload/errors convention is widespread but not universal, so it’s expanded only when that field really exists.
  • A nested field is reached through a root. Company.employee isn’t callable on its own, so it’s wrapped in a root field that returns Company. When several roots qualify, the caller is told, rather than the pick being passed off as obvious.

Structs§

Example
A drafted operation and the variables it expects.

Functions§

build
Draft an operation that reaches target.