dgraph-io/dgraph · error

Unknown query type

Error message

Unknown query type

What it means

A default-case error in queryTokensGeo meaning the supplied query type is not one of Within, Contains, Near, or Intersects. It indicates an unrecognized or unsupported geo query type value reached the token builder.

Source

Thrown at types/geofilter.go:207

			return []string{}, nil, errors.Errorf("Require a point for a within query.")
		}
		// A near query is the same as the intersects query. We form a loop with the given point and
		// the radius and then see what all does it intersect with.
		toks := parentCoverTokens(parents, cover)
		return toks, &GeoQueryData{loops: loops, qtype: QueryTypeIntersects}, nil

	case QueryTypeIntersects:
		// An intersects query is as the name suggests all the entities which intersect with the
		// given region. So we look at all the objects whose parents match our cover as well as
		// all the objects whose cover matches our parents.
		if len(loops) == 0 {
			return nil, nil, errors.Errorf("Require a polygon for intersects query")
		}
		toks := parentCoverTokens(parents, cover)
		return toks, &GeoQueryData{loops: loops, qtype: qt}, nil

	default:
		return nil, nil, errors.Errorf("Unknown query type")
	}
}

// MatchesFilter applies the query filter to a geo value
func (q GeoQueryData) MatchesFilter(g geom.T) bool {
	switch q.qtype {
	case QueryTypeWithin:
		return q.isWithin(g)
	case QueryTypeContains:
		return q.contains(g)
	case QueryTypeIntersects:
		return q.intersects(g)
	case QueryTypeNear:
		return q.intersects(g)
	}
	return false
}

View on GitHub (pinned to 759e242be6)

Solutions

  1. Use only the exported QueryType constants (QueryTypeWithin, QueryTypeContains, QueryTypeNear, QueryTypeIntersects)
  2. Validate/whitelist the query type string before mapping it to a constant
  3. Check for zero-value query structs where Type was never set

Example fix

// before
qt := dgraph.QueryType(userInput) // arbitrary value
// after
var qt dgraph.QueryType
switch userInput {
case "within": qt = dgraph.QueryTypeWithin
case "intersects": qt = dgraph.QueryTypeIntersects
case "contains": qt = dgraph.QueryTypeContains
case "near": qt = dgraph.QueryTypeNear
default: return errors.New("unsupported geo query type")
}
Defensive patterns

Strategy: validation

Validate before calling

switch qt {
case QueryTypeWithin, QueryTypeContains, QueryTypeNear, QueryTypeIntersects:
    // ok
default:
    return errors.Errorf("unsupported geo query type: %v", qt)
}

Type guard

func isKnownQueryType(qt QueryType) bool {
    switch qt {
    case QueryTypeWithin, QueryTypeContains, QueryTypeNear, QueryTypeIntersects:
        return true
    }
    return false
}

Try / catch

toks, data, err := types.GetGeoTokens(qt, pt, loops, cover, parents)
if err != nil && strings.Contains(err.Error(), "Unknown query type") {
    // fix constant mapping; surface unsupported-type error
}

Prevention

When it happens

Trigger: Calling GetGeoTokens/queryTokens with a query type value outside the known QueryType constants, e.g. a typo, an uninitialized/zero-value query type, or a type added by a newer/older version mismatch.

Common situations: Constructing queries from user/JSON input where the 'type' string maps incorrectly to a QueryType constant; version skew between clients and this library.

Related errors


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