dgraph-io/dgraph · error

can't convert input to map

Error message

can't convert input to map

What it means

getMoveTabletInput extracts the 'input' argument of the moveTablet admin mutation and requires it to arrive as a map[string]interface{} (the shape the GraphQL layer normally produces from a JSON object). If the argument value cannot be type-asserted to a map, this error is returned wrapped by inputArgError. It indicates the mutation was invoked without a properly structured input object.

Source

Thrown at graphql/admin/moveTablet.go:51

	status, err := worker.MoveTabletOverNetwork(ctx, &pb.MoveTabletRequest{
		Namespace: input.Namespace,
		Tablet:    input.Tablet,
		DstGroup:  input.GroupId,
	})
	if err != nil {
		return resolve.EmptyResult(m, err), false
	}

	return resolve.DataResult(m,
		map[string]interface{}{m.Name(): response("Success", status.GetMsg())},
		nil,
	), true
}

func getMoveTabletInput(m schema.Mutation) (*moveTabletInput, error) {
	inputArg, ok := m.ArgValue(schema.InputArgName).(map[string]interface{})
	if !ok {
		return nil, inputArgError(errors.Errorf("can't convert input to map"))
	}

	inputRef := &moveTabletInput{}
	// namespace is an optional parameter
	if _, ok = inputArg["namespace"]; !ok {
		inputRef.Namespace = x.RootNamespace
	} else {
		ns, err := parseAsUint64(inputArg["namespace"])
		if err != nil {
			return nil, inputArgError(schema.GQLWrapf(err,
				"can't convert input.namespace to uint64"))
		}
		inputRef.Namespace = ns
	}

	inputRef.Tablet, ok = inputArg["tablet"].(string)
	if !ok {
		return nil, inputArgError(errors.Errorf("can't convert input.tablet to string"))

View on GitHub (pinned to 759e242be6)

Solutions

  1. Send a properly structured input object: { moveTablet(input: { tablet: "...", groupId: 1, namespace: 0 }) }.
  2. If using GraphQL variables, declare $input: MoveTabletInput! and pass a JSON object (not a string) as the variable value.
  3. Check the argument is literally named 'input' (schema.InputArgName) and the type name matches the schema.
  4. Inspect the raw request body to confirm the input field is a JSON object, not a quoted string of JSON.
  5. Regenerate/update the client from the current admin schema in case the mutation signature changed.

Example fix

// before: input as JSON string variable
{"query":"mutation Move($input: String!){ moveTablet(input: $input){...} }
// after: typed input object
mutation Move($input: MoveTabletInput!) { moveTablet(input: $input) { ... } }
// variables: {"input": {"tablet":"5","groupId":1,"namespace":0}}
Defensive patterns

Strategy: validation

Validate before calling

function assertMoveTabletInput(v) {
  if (v === null || typeof v !== 'object' || Array.isArray(v)) {
    throw new Error('moveTablet input must be an object: {tablet, groupId, namespace?}');
  }
  return v;
}

Type guard

function isPlainObject(v) {
  return v !== null && typeof v === 'object' && !Array.isArray(v);
}

Try / catch

try {
  await gql(`mutation Move($input: MoveTabletInput!){ moveTablet(input: $input){...} }`, { input });
} catch (e) {
  if (String(e.message).includes("can't convert input to map")) {
    // input arrived as non-object; rebuild as an object and retry
  }
}

Prevention

When it happens

Trigger: Calling the moveTablet admin GraphQL mutation with the input argument missing entirely, passed as a scalar/string/JSON blob instead of the declared input object, or via a raw HTTP/client path that bypasses GraphQL variable coercion and hands the resolver a non-map value.

Common situations: Hand-crafted admin mutations with a typo like 'inputs:' or 'in:' instead of 'input:', clients sending GraphQL variables with the wrong type (string instead of object), or tooling that posts raw JSON to the admin endpoint without the input wrapper object.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/cc58b3938cc6018f. Report an issue: GitHub.