gatsbyjs/gatsby · error · Error

Invalid field arg

Error message

Invalid field arg

What it means

getProjectedField inspects the 'field' argument on an aggregate/pipe resolver (group, distinct, max, min, sum) to project which field to aggregate. When the enum/input-object argument node cannot be resolved to a field path, this sentinel is thrown — the 'field' argument is missing or malformed in the query.

Source

Thrown at packages/gatsby/src/schema/resolvers.ts:608

            (acc: Array<string>, fieldNode: FieldNode) => {
              const fieldArg = fieldNode.arguments?.find(
                arg => arg.name.value === `field`
              )
              if (isEnumType(fieldTC)) {
                if (fieldArg?.value.kind === Kind.ENUM) {
                  const enumKey = fieldArg.value.value
                  const enumValue = fieldTC.getValue(enumKey)
                  if (enumValue) {
                    acc.push(enumValue.value)
                  }
                }
              } else if (isInputObjectType(fieldTC)) {
                const path: Array<string> = []
                let currentValue = fieldArg?.value
                while (currentValue) {
                  if (currentValue.kind === Kind.OBJECT) {
                    if (currentValue.fields.length !== 1) {
                      throw new Error(`Invalid field arg`)
                    }

                    const fieldArg = currentValue.fields[0]
                    path.push(fieldArg.name.value)
                    currentValue = fieldArg.value
                  } else {
                    currentValue = undefined
                  }
                }

                if (path.length > 0) {
                  const sortPath = path.join(`.`)
                  acc.push(sortPath)
                }
              }
              return acc
            },
            []

View on GitHub (pinned to e85d62f177)

Solutions

  1. Provide a valid 'field' argument to the group/distinct/max/min/sum field
  2. Use dotted path syntax matching the node's fields
  3. Check for typos in the field path string
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/gatsby/src/schema/resolvers.ts:608 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of gatsbyjs/gatsby@e85d62f177 (2026-08-26). Data as JSON: /api/errors/976c99b8fa5af3e2. Report an issue: GitHub.