File tree Expand file tree Collapse file tree
internal/request/graphql/parser
tests/integration/query/simple Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,10 +27,10 @@ func CloseNode(nodePtr C.uintptr_t) C.Result {
2727 if err != nil {
2828 return returnC (returnGoC (1 , err .Error (), "" ))
2929 }
30- err = node .Close (context .Background ())
31- if err != nil {
30+ defer cgo .Handle (nodePtr ).Delete ()
31+
32+ if err := node .Close (context .Background ()); err != nil {
3233 return returnC (GoCResult {1 , err .Error (), "" })
3334 }
34- cgo .Handle (nodePtr ).Delete ()
3535 return returnC (GoCResult {0 , "" , "" })
3636}
Original file line number Diff line number Diff line change 2828 ErrInvalidFilterConditions = errors .New ("invalid filter condition type, expected map" )
2929 ErrMultipleOrderFieldsDefined = errors .New ("each order argument can only define one field" )
3030 ErrMultipleDocIDsNotSupported = errors .New ("querying by multiple docIDs is not yet supported" )
31+ ErrSimilarityMissingTarget = errors .New ("similarity requires a target field argument" )
3132)
Original file line number Diff line number Diff line change @@ -250,6 +250,11 @@ func parseSimilarity(
250250 v := arguments [target ].(map [string ]any )
251251 vector = v [types .SimilarityArgVector ]
252252 }
253+ // The argument names the field to compare against, so without one there is nothing to
254+ // compare. The mapper looks the target up by name and would panic on the empty name.
255+ if target == "" {
256+ return nil , ErrSimilarityMissingTarget
257+ }
253258
254259 return & request.Similarity {
255260 Field : request.Field {
Original file line number Diff line number Diff line change @@ -517,3 +517,26 @@ func TestQuerySimple_WithTwoSimilarityAndFilteringOnBoth_ShouldSucceed(t *testin
517517
518518 testUtils .ExecuteTestCase (t , test )
519519}
520+
521+ func TestQuerySimple_WithSimilarityAndNoArguments_ShouldError (t * testing.T ) {
522+ test := testUtils.TestCase {
523+ Actions : []any {
524+ & action.AddCollection {
525+ SDL : `type User {
526+ name: String
527+ vector: [Int!]
528+ }` ,
529+ },
530+ & action.Request {
531+ Request : `query {
532+ User {
533+ SIMILARITY
534+ }
535+ }` ,
536+ ExpectedError : "similarity requires a target field argument" ,
537+ },
538+ },
539+ }
540+
541+ testUtils .ExecuteTestCase (t , test )
542+ }
You can’t perform that action at this time.
0 commit comments