dgraph-io/dgraph · error

provided value is not a scalar, can't convert it to string

Error message

provided value is not a scalar, can't convert it to string

What it means

errNotScalar is returned by convertScalarToString in Dgraph's GraphQL query resolution when a value that must be converted to a string (typically for an @search/@id argument or DQL variable) is not a scalar type. The resolver only knows how to stringify scalar values; objects, lists, or enums passed where a scalar string is expected trigger this. It is a schema/type mismatch rather than a runtime data failure.

Source

Thrown at graphql/resolve/query.go:24

package resolve

import (
	"context"
	"encoding/json"
	"errors"
	"strconv"

	"github.com/golang/glog"
	"go.opentelemetry.io/otel/trace"

	dgoapi "github.com/dgraph-io/dgo/v250/protos/api"
	"github.com/dgraph-io/dgraph/v25/dql"
	"github.com/dgraph-io/dgraph/v25/graphql/dgraph"
	"github.com/dgraph-io/dgraph/v25/graphql/schema"
	"github.com/dgraph-io/dgraph/v25/x"
)

var errNotScalar = errors.New("provided value is not a scalar, can't convert it to string")

// A QueryResolver can resolve a single query.
type QueryResolver interface {
	Resolve(ctx context.Context, query schema.Query) *Resolved
}

// A QueryRewriter can build a Dgraph dql.GraphQuery from a GraphQL query,
// along with any DQL variable bindings (e.g. for parameterized password
// queries) that must be supplied to the executor.
type QueryRewriter interface {
	Rewrite(ctx context.Context, q schema.Query) ([]*dql.GraphQuery, map[string]string, error)
}

// QueryResolverFunc is an adapter that allows to build a QueryResolver from
// a function.  Based on the http.HandlerFunc pattern.
type QueryResolverFunc func(ctx context.Context, query schema.Query) *Resolved

// Resolve calls qr(ctx, query)

View on GitHub (pinned to 759e242be6)

Solutions

  1. Inspect the GraphQL query/variables being sent and ensure the value passed is a scalar (String/Int/Float/Boolean)
  2. Validate client-side variables against the schema before sending
  3. Fix the schema so the relevant field/argument is declared as a scalar type

Example fix

// before
query($id: [String!]!) { getUser(userId: $id) {...} } // list passed where scalar needed
// after
query($id: String!) { getUser(userId: $id) {...} }
Defensive patterns

Strategy: type-guard

Validate before calling

if typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean' {
  throw new Error('argument must be a scalar')
}

Type guard

func isScalarValue(v interface{}) bool {
  switch v.(type) {
  case string, int, int64, float64, bool, nil:
    return true
  }
  return false
}

Try / catch

resp, err := resolver.Resolve(ctx, req)
if err != nil && strings.Contains(err.Error(), "provided value is not a scalar") {
  // inspect variables sent with the request
  log.Printf("non-scalar value in query vars: %v", req.Variables)
}

Prevention

When it happens

Trigger: Calling a query/mutation whose argument or field resolution path invokes convertScalarToString with a non-scalar value — e.g. an object-typed or list-typed input supplied where a scalar XID or search filter value is expected.

Common situations: Mis-typed GraphQL variables in client queries; passing an object where a String was declared; custom scalars that resolve to non-scalar Go values; schema edits that changed a field type without updating client queries.

Related errors


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