Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

GraphQL · Class

GraphQLArgument

GraphQL arguments are named inputs declared by fields or directives. They can be optional or required, may have defaults, and must use input types.

How it works

A GraphQL argument is a named input supplied to a field or directive to influence its result or behavior. Its schema definition specifies an input type and may mark the value as required or provide a default.

Syntax

field(argumentName: InputType): ReturnType

Key points

  • Arguments belong to field definitions, and a field may declare none, one, or many.
  • A schema gives each argument its own name, such as unit on a length field.
  • Schema authors can choose a fallback value for an optional argument.
  • Every argument definition declares the input type accepted by that field.
  • Clients write argument names alongside their values rather than relying on positional slots.

Common mistakes

  • Arguments are not positional; changing their order does not change their meaning.
  • An operation cannot pass an argument that the target field or directive has not declared.
  • Do not assume an omitted argument is invalid; optional arguments may be absent.

Example: Named field arguments

query GetHuman($id: ID!, $size: Int) {
  human(id: $id) {
    name
    profilePic(size: $size)
  }
}

A query supplies named arguments directly and factors dynamic values into variables.

When to use it

Customize field results

A field needs client-provided criteria such as an identifier, filter, or unit.

Provide defaults

A schema offers a sensible behavior when callers omit a nonessential option.

Use variables

A query needs dynamic values supplied separately from its document.

Interview questions

QWhat is a GraphQL argument?

Arguments are named inputs attached to fields or directives. A field can define zero or more of them, and each argument can alter the field's returned result.

Follow-up: Why are named arguments useful? They let a field accept several values without depending on positional ordering, so adding or rearranging arguments remains clearer and less error-prone.

QHow do required, optional, and defaulted arguments differ?

An argument is required when its type is non-null; otherwise it is optional. An optional argument may define a default value that is used when the client omits it.

Follow-up: What happens when a non-null argument is omitted? Validation rejects the operation because the required argument has no supplied value.

QHow are argument values supplied in a query?

Arguments must use input types. GraphQL fields may receive arguments at every nesting level, and variables provide a separate dictionary for dynamic argument values.

Follow-up: Why use variables instead of embedding dynamic values? Variables separate changing data from the query document and can be supplied through the transport request.

  • Schemas and Types
  • Arguments
  • Fields
  • Input Object types
  • Queries
  • Variables
  • Execution

Source: Schemas and Types. Checked 2026-10-15.