{"record":{"id":"1fb1edb9d616b9be","repo":"dgraph-io/dgraph","slug":"require-a-point-for-a-within-query","errorCode":null,"errorMessage":"Require a point for a within query.","messagePattern":"Require a point for a within query\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"types/geofilter.go","lineNumber":189,"sourceCode":"\n\tswitch qt {\n\tcase QueryTypeWithin:\n\t\t// For a within query we only need to look at the objects whose parents match our cover.\n\t\t// So we take our cover and prefix with the parentPrefix to look in the index.\n\t\tif len(loops) == 0 {\n\t\t\treturn nil, nil, errors.Errorf(\"Require a polygon for within query\")\n\t\t}\n\t\ttoks := createTokens(cover, parentPrefix)\n\t\treturn toks, &GeoQueryData{loops: loops, qtype: qt}, nil\n\n\tcase QueryTypeContains:\n\t\t// For a contains query, we only need to look at the objects whose cover matches our\n\t\t// parents. So we take our parents and prefix with the coverPrefix to look in the index.\n\t\treturn createTokens(parents, coverPrefix), &GeoQueryData{pt: pt, loops: loops, qtype: qt}, nil\n\n\tcase QueryTypeNear:\n\t\tif pt == nil {\n\t\t\treturn []string{}, nil, errors.Errorf(\"Require a point for a within query.\")\n\t\t}\n\t\t// A near query is the same as the intersects query. We form a loop with the given point and\n\t\t// the radius and then see what all does it intersect with.\n\t\ttoks := parentCoverTokens(parents, cover)\n\t\treturn toks, &GeoQueryData{loops: loops, qtype: QueryTypeIntersects}, nil\n\n\tcase QueryTypeIntersects:\n\t\t// An intersects query is as the name suggests all the entities which intersect with the\n\t\t// given region. So we look at all the objects whose parents match our cover as well as\n\t\t// all the objects whose cover matches our parents.\n\t\tif len(loops) == 0 {\n\t\t\treturn nil, nil, errors.Errorf(\"Require a polygon for intersects query\")\n\t\t}\n\t\ttoks := parentCoverTokens(parents, cover)\n\t\treturn toks, &GeoQueryData{loops: loops, qtype: qt}, nil\n\n\tdefault:\n\t\treturn nil, nil, errors.Errorf(\"Unknown query type\")","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/types/geofilter.go#L171-L207","documentation":"Thrown by queryTokensGeo when a QueryTypeNear query is issued with a nil point. A near query needs a center point around which a loop of the given radius is formed; with pt == nil there is no center to search around.","triggerScenarios":"Calling GetGeoTokens/queryTokens with QueryTypeNear and the point (pt) argument set to nil, e.g. a near filter where the coordinates field was missing or not decoded.","commonSituations":"A near query built from JSON where 'coordinates' is absent, or code paths that reuse an intersects-style filter for near without populating the point.","solutions":["Populate the point (longitude, latitude) before issuing a near query","Validate pt != nil before calling queryTokensGeo with QueryTypeNear","Use QueryTypeWithin with a polygon if you actually have a region, not a point"],"exampleFix":"// before\nquery := dgraph.Query{Type: dgraph.QueryTypeNear} // pt never set\n// after\nquery := dgraph.Query{Type: dgraph.QueryTypeNear, Point: &geom.Point{X: -122.4, Y: 37.7}}","handlingStrategy":"validation","validationCode":"if qt == QueryTypeNear && pt == nil {\n    return errors.New(\"near query requires a point\")\n}","typeGuard":"func isPointSet(pt *geom.Point) bool { return pt != nil }","tryCatchPattern":"toks, data, err := types.GetGeoTokens(qt, pt, loops, cover, parents)\nif err != nil && strings.Contains(err.Error(), \"Require a point\") {\n    // prompt user for coordinates or default to a configured location\n}","preventionTips":["Require coordinates in near-query payloads before dispatch","Provide sensible default locations server-side when point is absent","Distinguish near (point) vs within/intersects (polygon) in query schema validation"],"tags":["geo","query","validation"],"backgroundTag":"missing-geo-point","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}