Skip to content

Commit

Permalink
Merge pull request #29 from hasura/m-bilal/re-enable-range-op
Browse files Browse the repository at this point in the history
Re enable range operation
  • Loading branch information
gneeri authored Sep 25, 2024
2 parents 0f1e53f + a3fe04e commit 35461c2
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions connector/static_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package connector

import (
"slices"

"github.com/hasura/ndc-sdk-go/schema"
"github.com/hasura/ndc-sdk-go/utils"
)
Expand Down Expand Up @@ -330,20 +332,25 @@ var objectTypeMap = map[string]schema.ObjectType{
},
}

var unsupportedRangeQueryScalars = []string{"binary", "completion", "_id", "wildcard", "match_only_text", "search_as_you_type"}

// getComparisonOperatorDefinition generates and returns a map of comparison operators based on the provided data type.
func getComparisonOperatorDefinition(dataType string) map[string]schema.ComparisonOperatorDefinition {
var comparisonOperators = map[string]schema.ComparisonOperatorDefinition{
"match": schema.NewComparisonOperatorCustom(schema.NewNamedType(dataType)).Encode(),
"match_phrase": schema.NewComparisonOperatorCustom(schema.NewNamedType(dataType)).Encode(),
"term": schema.NewComparisonOperatorCustom(schema.NewNamedType(dataType)).Encode(),
// "range": schema.NewComparisonOperatorCustom(schema.NewNamedType("range")).Encode(), // TODO: add back once object types are supported as comparison operators
"terms": schema.NewComparisonOperatorCustom(schema.NewArrayType(schema.NewNamedType(dataType))).Encode(),
"terms": schema.NewComparisonOperatorCustom(schema.NewArrayType(schema.NewNamedType(dataType))).Encode(),
}

// if dataType == "date" { // TODO: add back once object types are supported as comparison operators
// requiredObjectTypes["date_range_query"] = objectTypeMap["date_range_query"]
// comparisonOperators["range"] = schema.NewComparisonOperatorCustom(schema.NewNamedType("date_range_query")).Encode()
// }
if !slices.Contains(unsupportedRangeQueryScalars, dataType) {
comparisonOperators["range"] = schema.NewComparisonOperatorCustom(schema.NewNamedType("range")).Encode()
}

if dataType == "date" {
requiredObjectTypes["date_range_query"] = objectTypeMap["date_range_query"]
comparisonOperators["range"] = schema.NewComparisonOperatorCustom(schema.NewNamedType("date_range_query")).Encode()
}

if dataType == "text" {
comparisonOperators["match_phrase_prefix"] = schema.NewComparisonOperatorCustom(schema.NewNamedType(dataType)).Encode()
Expand Down

0 comments on commit 35461c2

Please sign in to comment.